Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting up connection to non-IP sockets #178

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Build
runs-on: ubuntu-latest
env:
SCYLLA_IMAGE: scylladb/scylla:5.4.6
SCYLLA_IMAGE: scylladb/scylla:6.0.0
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
Expand Down
6 changes: 5 additions & 1 deletion control.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ type connHost struct {
func (c *controlConn) setupConn(conn *Conn) error {
// we need up-to-date host info for the filterHost call below
iter := conn.querySystemLocal(context.TODO())
host, err := c.session.hostInfoFromIter(iter, conn.host.connectAddress, conn.conn.RemoteAddr().(*net.TCPAddr).Port)
defaultPort := 9042
if tcpAddr, ok := conn.conn.RemoteAddr().(*net.TCPAddr); ok {
defaultPort = tcpAddr.Port
}
host, err := c.session.hostInfoFromIter(iter, conn.host.connectAddress, defaultPort)
if err != nil {
return err
}
Expand Down
71 changes: 71 additions & 0 deletions control_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//go:build integration && scylla
// +build integration,scylla

package gocql

import (
"context"
"fmt"
"net"
"testing"
)

// unixSocketDialer is a special dialer which connects only to the maintenance_socket.
type unixSocketDialer struct {
dialer net.Dialer
socketPath string
}

func (d unixSocketDialer) DialContext(_ context.Context, _, _ string) (net.Conn, error) {
return d.dialer.Dial("unix", d.socketPath)
}

func TestUnixSockets(t *testing.T) {
socketPath := "/tmp/scylla/cql.m"

wprzytula marked this conversation as resolved.
Show resolved Hide resolved
c := createCluster()
c.NumConns = 1
c.DisableInitialHostLookup = true
c.ProtoVersion = 3
c.ReconnectInterval = 0
c.WriteCoalesceWaitTime = 0

c.Events.DisableNodeStatusEvents = true
c.Events.DisableTopologyEvents = true
c.Events.DisableSchemaEvents = true

d := net.Dialer{
Timeout: c.Timeout,
}
if c.SocketKeepalive > 0 {
d.KeepAlive = c.SocketKeepalive
}

c.Dialer = unixSocketDialer{
dialer: d,
socketPath: socketPath,
}

sess, err := c.CreateSession()
if err != nil {
panic(fmt.Sprintf("unable to create session: %v", err))
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you ran a query to make sure session is operational ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add it, but I thought it was not necessary cause the issue was discovered without it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but you know, lot's of things happening between session creation and query being executed, aren't we need to make sure that whole thing is working ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the queries

defer sess.Close()

keyspace := "test1"

err = createTable(sess, `DROP KEYSPACE IF EXISTS `+keyspace)
if err != nil {
t.Fatal("unable to drop keyspace if exists:", err)
}

err = createTable(sess, fmt.Sprintf(`CREATE KEYSPACE %s
WITH replication = {
'class' : 'SimpleStrategy',
'replication_factor' : 1
}`, keyspace))
if err != nil {
t.Fatal("unable to create keyspace:", err)
}
}
13 changes: 4 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
public:
ipv4_address: 192.168.100.11
volumes:
- /tmp/scylla:/var/lib/scylla/
- type: bind
source: ./testdata/config/scylla.yaml
target: /etc/scylla/scylla.yaml
Expand All @@ -33,10 +34,8 @@ services:
timeout: 5s
retries: 18
node_2:
image: scylladb/scylla-nightly:6.0.0-rc2-0.20240602.cbf47319c1f7
image: ${SCYLLA_IMAGE}
command: |
--experimental-features consistent-topology-changes
--experimental-features tablets
--smp 2
--memory 1G
--seeds 192.168.100.12
Expand All @@ -49,10 +48,8 @@ services:
timeout: 5s
retries: 18
node_3:
image: scylladb/scylla-nightly:6.0.0-rc2-0.20240602.cbf47319c1f7
image: ${SCYLLA_IMAGE}
command: |
--experimental-features consistent-topology-changes
--experimental-features tablets
--smp 2
--memory 1G
--seeds 192.168.100.12
Expand All @@ -68,10 +65,8 @@ services:
node_2:
condition: service_healthy
node_4:
image: scylladb/scylla-nightly:6.0.0-rc2-0.20240602.cbf47319c1f7
image: ${SCYLLA_IMAGE}
command: |
--experimental-features consistent-topology-changes
--experimental-features tablets
--smp 2
--memory 1G
--seeds 192.168.100.12
Expand Down
2 changes: 2 additions & 0 deletions integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function scylla_restart() {

scylla_restart

sudo chmod 0777 /tmp/scylla/cql.m

readonly clusterSize=1
readonly multiNodeClusterSize=3
readonly scylla_liveset="192.168.100.11"
Expand Down
2 changes: 0 additions & 2 deletions metadata_cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,6 @@ func getMaterializedViewsMetadata(session *Session, keyspaceName string) ([]Mate
compaction,
compression,
crc_check_chance,
dclocal_read_repair_chance,
default_time_to_live,
extensions,
gc_grace_seconds,
Expand All @@ -1003,7 +1002,6 @@ func getMaterializedViewsMetadata(session *Session, keyspaceName string) ([]Mate
max_index_interval,
memtable_flush_period_in_ms,
min_index_interval,
read_repair_chance,
speculative_retry
FROM %s
WHERE keyspace_name = ?`, tableName)
Expand Down
4 changes: 0 additions & 4 deletions metadata_scylla.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,11 @@ func getTableMetadata(session *Session, keyspaceName string) ([]TableMetadata, e
"compaction": &table.Options.Compaction,
"compression": &table.Options.Compression,
"crc_check_chance": &table.Options.CrcCheckChance,
"dclocal_read_repair_chance": &table.Options.DcLocalReadRepairChance,
"default_time_to_live": &table.Options.DefaultTimeToLive,
"gc_grace_seconds": &table.Options.GcGraceSeconds,
"max_index_interval": &table.Options.MaxIndexInterval,
"memtable_flush_period_in_ms": &table.Options.MemtableFlushPeriodInMs,
"min_index_interval": &table.Options.MinIndexInterval,
"read_repair_chance": &table.Options.ReadRepairChance,
"speculative_retry": &table.Options.SpeculativeRetry,
"flags": &table.Flags,
"extensions": &table.Extensions,
Expand Down Expand Up @@ -772,13 +770,11 @@ func getViewMetadata(session *Session, keyspaceName string) ([]ViewMetadata, err
"compaction": &view.Options.Compaction,
"compression": &view.Options.Compression,
"crc_check_chance": &view.Options.CrcCheckChance,
"dclocal_read_repair_chance": &view.Options.DcLocalReadRepairChance,
"default_time_to_live": &view.Options.DefaultTimeToLive,
"gc_grace_seconds": &view.Options.GcGraceSeconds,
"max_index_interval": &view.Options.MaxIndexInterval,
"memtable_flush_period_in_ms": &view.Options.MemtableFlushPeriodInMs,
"min_index_interval": &view.Options.MinIndexInterval,
"read_repair_chance": &view.Options.ReadRepairChance,
"speculative_retry": &view.Options.SpeculativeRetry,
"extensions": &view.Extensions,
}) {
Expand Down
2 changes: 0 additions & 2 deletions recreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,11 @@ func (h toCQLHelpers) tableOptionsToCQL(ops TableMetadataOptions) ([]string, err
"bloom_filter_fp_chance": ops.BloomFilterFpChance,
"comment": ops.Comment,
"crc_check_chance": ops.CrcCheckChance,
"dclocal_read_repair_chance": ops.DcLocalReadRepairChance,
"default_time_to_live": ops.DefaultTimeToLive,
"gc_grace_seconds": ops.GcGraceSeconds,
"max_index_interval": ops.MaxIndexInterval,
"memtable_flush_period_in_ms": ops.MemtableFlushPeriodInMs,
"min_index_interval": ops.MinIndexInterval,
"read_repair_chance": ops.ReadRepairChance,
"speculative_retry": ops.SpeculativeRetry,
}

Expand Down
3 changes: 1 addition & 2 deletions testdata/config/scylla.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ client_encryption_options:
keyfile: /etc/scylla/db.key
truststore: /etc/scylla/ca.crt
require_client_auth: true
# when using 5.4.x we have to specify force_schema_commit_log option
force_schema_commit_log: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you deleted it intentionaly, since it is used by dirver-matrix I do not recommend deleting it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was only necessary to specify it in 5.4.x. In the 6.0 it should be enabled be default

maintenance_socket: workdir
Comment on lines 8 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of maintenance_socket here is not related to the commit description. Why is it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right it should be in the second commit

2 changes: 0 additions & 2 deletions testdata/recreate/index_golden.cql
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ CREATE TABLE gocqlx_idx.menus (
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND dclocal_read_repair_chance = 0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0
AND speculative_retry = '99.0PERCENTILE';

CREATE INDEX menus_name_idx ON gocqlx_idx.menus (name);
6 changes: 0 additions & 6 deletions testdata/recreate/materialized_views_golden.cql
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ CREATE TABLE gocqlx_mv.mv_buildings (
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND dclocal_read_repair_chance = 0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0
AND speculative_retry = '99.0PERCENTILE';

CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city AS
Expand All @@ -35,13 +33,11 @@ CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city AS
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND dclocal_read_repair_chance = 0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0
AND speculative_retry = '99.0PERCENTILE';

CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city2 AS
Expand All @@ -59,11 +55,9 @@ CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city2 AS
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND dclocal_read_repair_chance = 0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0
AND speculative_retry = '99.0PERCENTILE';
2 changes: 0 additions & 2 deletions testdata/recreate/secondary_index_golden.cql
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ CREATE TABLE gocqlx_sec_idx.menus (
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND dclocal_read_repair_chance = 0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0
AND speculative_retry = '99.0PERCENTILE';

CREATE INDEX menus_name_idx ON gocqlx_sec_idx.menus ((location), name);
3 changes: 1 addition & 2 deletions testdata/recreate/table.cql
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ CREATE TABLE gocqlx_table.monkeySpecies (
common_name text,
population varint,
average_size int
) WITH comment='Important biological records'
AND read_repair_chance = 1.0;
) WITH comment='Important biological records';

CREATE TABLE gocqlx_table.timeline (
userid uuid,
Expand Down
8 changes: 0 additions & 8 deletions testdata/recreate/table_golden.cql
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ CREATE TABLE gocqlx_table.loads (
AND compaction = {'class':'TimeWindowCompactionStrategy','compaction_window_size':'14','compaction_window_unit':'DAYS'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND dclocal_read_repair_chance = 0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0
AND speculative_retry = '99.0PERCENTILE';

CREATE TABLE gocqlx_table.monkeyspecies (
Expand All @@ -36,13 +34,11 @@ CREATE TABLE gocqlx_table.monkeyspecies (
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND dclocal_read_repair_chance = 0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 1
AND speculative_retry = '99.0PERCENTILE';

CREATE TABLE gocqlx_table.timeline (
Expand All @@ -59,13 +55,11 @@ CREATE TABLE gocqlx_table.timeline (
AND compaction = {'class':'LeveledCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND dclocal_read_repair_chance = 0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0
AND speculative_retry = '99.0PERCENTILE';

CREATE TABLE gocqlx_table.users_picture (
Expand All @@ -81,11 +75,9 @@ CREATE TABLE gocqlx_table.users_picture (
AND compaction = {'class':'SizeTieredCompactionStrategy'}
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1
AND dclocal_read_repair_chance = 0
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0
AND speculative_retry = '99.0PERCENTILE';
Loading