Skip to content

Commit 790b1a8

Browse files
Merge pull request #178 from sylwiaszunejko/unix_socket
Fix setting up connection to non-IP sockets
2 parents 2c5fba3 + 76878db commit 790b1a8

14 files changed

+85
-41
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: Build
1313
runs-on: ubuntu-latest
1414
env:
15-
SCYLLA_IMAGE: scylladb/scylla:5.4.6
15+
SCYLLA_IMAGE: scylladb/scylla:6.0.0
1616
steps:
1717
- uses: actions/checkout@v2
1818
- uses: actions/setup-go@v2

control.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ type connHost struct {
270270
func (c *controlConn) setupConn(conn *Conn) error {
271271
// we need up-to-date host info for the filterHost call below
272272
iter := conn.querySystemLocal(context.TODO())
273-
host, err := c.session.hostInfoFromIter(iter, conn.host.connectAddress, conn.conn.RemoteAddr().(*net.TCPAddr).Port)
273+
defaultPort := 9042
274+
if tcpAddr, ok := conn.conn.RemoteAddr().(*net.TCPAddr); ok {
275+
defaultPort = tcpAddr.Port
276+
}
277+
host, err := c.session.hostInfoFromIter(iter, conn.host.connectAddress, defaultPort)
274278
if err != nil {
275279
return err
276280
}

control_integration_test.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//go:build integration && scylla
2+
// +build integration,scylla
3+
4+
package gocql
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"net"
10+
"testing"
11+
)
12+
13+
// unixSocketDialer is a special dialer which connects only to the maintenance_socket.
14+
type unixSocketDialer struct {
15+
dialer net.Dialer
16+
socketPath string
17+
}
18+
19+
func (d unixSocketDialer) DialContext(_ context.Context, _, _ string) (net.Conn, error) {
20+
return d.dialer.Dial("unix", d.socketPath)
21+
}
22+
23+
func TestUnixSockets(t *testing.T) {
24+
socketPath := "/tmp/scylla/cql.m"
25+
26+
c := createCluster()
27+
c.NumConns = 1
28+
c.DisableInitialHostLookup = true
29+
c.ProtoVersion = 3
30+
c.ReconnectInterval = 0
31+
c.WriteCoalesceWaitTime = 0
32+
33+
c.Events.DisableNodeStatusEvents = true
34+
c.Events.DisableTopologyEvents = true
35+
c.Events.DisableSchemaEvents = true
36+
37+
d := net.Dialer{
38+
Timeout: c.Timeout,
39+
}
40+
if c.SocketKeepalive > 0 {
41+
d.KeepAlive = c.SocketKeepalive
42+
}
43+
44+
c.Dialer = unixSocketDialer{
45+
dialer: d,
46+
socketPath: socketPath,
47+
}
48+
49+
sess, err := c.CreateSession()
50+
if err != nil {
51+
panic(fmt.Sprintf("unable to create session: %v", err))
52+
}
53+
54+
defer sess.Close()
55+
56+
keyspace := "test1"
57+
58+
err = createTable(sess, `DROP KEYSPACE IF EXISTS `+keyspace)
59+
if err != nil {
60+
t.Fatal("unable to drop keyspace if exists:", err)
61+
}
62+
63+
err = createTable(sess, fmt.Sprintf(`CREATE KEYSPACE %s
64+
WITH replication = {
65+
'class' : 'SimpleStrategy',
66+
'replication_factor' : 1
67+
}`, keyspace))
68+
if err != nil {
69+
t.Fatal("unable to create keyspace:", err)
70+
}
71+
}

docker-compose.yml

+4-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
public:
1616
ipv4_address: 192.168.100.11
1717
volumes:
18+
- /tmp/scylla:/var/lib/scylla/
1819
- type: bind
1920
source: ./testdata/config/scylla.yaml
2021
target: /etc/scylla/scylla.yaml
@@ -33,10 +34,8 @@ services:
3334
timeout: 5s
3435
retries: 18
3536
node_2:
36-
image: scylladb/scylla-nightly:6.0.0-rc2-0.20240602.cbf47319c1f7
37+
image: ${SCYLLA_IMAGE}
3738
command: |
38-
--experimental-features consistent-topology-changes
39-
--experimental-features tablets
4039
--smp 2
4140
--memory 1G
4241
--seeds 192.168.100.12
@@ -49,10 +48,8 @@ services:
4948
timeout: 5s
5049
retries: 18
5150
node_3:
52-
image: scylladb/scylla-nightly:6.0.0-rc2-0.20240602.cbf47319c1f7
51+
image: ${SCYLLA_IMAGE}
5352
command: |
54-
--experimental-features consistent-topology-changes
55-
--experimental-features tablets
5653
--smp 2
5754
--memory 1G
5855
--seeds 192.168.100.12
@@ -68,10 +65,8 @@ services:
6865
node_2:
6966
condition: service_healthy
7067
node_4:
71-
image: scylladb/scylla-nightly:6.0.0-rc2-0.20240602.cbf47319c1f7
68+
image: ${SCYLLA_IMAGE}
7269
command: |
73-
--experimental-features consistent-topology-changes
74-
--experimental-features tablets
7570
--smp 2
7671
--memory 1G
7772
--seeds 192.168.100.12

integration.sh

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function scylla_restart() {
2727

2828
scylla_restart
2929

30+
sudo chmod 0777 /tmp/scylla/cql.m
31+
3032
readonly clusterSize=1
3133
readonly multiNodeClusterSize=3
3234
readonly scylla_liveset="192.168.100.11"

metadata_cassandra.go

-2
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,6 @@ func getMaterializedViewsMetadata(session *Session, keyspaceName string) ([]Mate
994994
compaction,
995995
compression,
996996
crc_check_chance,
997-
dclocal_read_repair_chance,
998997
default_time_to_live,
999998
extensions,
1000999
gc_grace_seconds,
@@ -1003,7 +1002,6 @@ func getMaterializedViewsMetadata(session *Session, keyspaceName string) ([]Mate
10031002
max_index_interval,
10041003
memtable_flush_period_in_ms,
10051004
min_index_interval,
1006-
read_repair_chance,
10071005
speculative_retry
10081006
FROM %s
10091007
WHERE keyspace_name = ?`, tableName)

metadata_scylla.go

-4
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,11 @@ func getTableMetadata(session *Session, keyspaceName string) ([]TableMetadata, e
553553
"compaction": &table.Options.Compaction,
554554
"compression": &table.Options.Compression,
555555
"crc_check_chance": &table.Options.CrcCheckChance,
556-
"dclocal_read_repair_chance": &table.Options.DcLocalReadRepairChance,
557556
"default_time_to_live": &table.Options.DefaultTimeToLive,
558557
"gc_grace_seconds": &table.Options.GcGraceSeconds,
559558
"max_index_interval": &table.Options.MaxIndexInterval,
560559
"memtable_flush_period_in_ms": &table.Options.MemtableFlushPeriodInMs,
561560
"min_index_interval": &table.Options.MinIndexInterval,
562-
"read_repair_chance": &table.Options.ReadRepairChance,
563561
"speculative_retry": &table.Options.SpeculativeRetry,
564562
"flags": &table.Flags,
565563
"extensions": &table.Extensions,
@@ -772,13 +770,11 @@ func getViewMetadata(session *Session, keyspaceName string) ([]ViewMetadata, err
772770
"compaction": &view.Options.Compaction,
773771
"compression": &view.Options.Compression,
774772
"crc_check_chance": &view.Options.CrcCheckChance,
775-
"dclocal_read_repair_chance": &view.Options.DcLocalReadRepairChance,
776773
"default_time_to_live": &view.Options.DefaultTimeToLive,
777774
"gc_grace_seconds": &view.Options.GcGraceSeconds,
778775
"max_index_interval": &view.Options.MaxIndexInterval,
779776
"memtable_flush_period_in_ms": &view.Options.MemtableFlushPeriodInMs,
780777
"min_index_interval": &view.Options.MinIndexInterval,
781-
"read_repair_chance": &view.Options.ReadRepairChance,
782778
"speculative_retry": &view.Options.SpeculativeRetry,
783779
"extensions": &view.Extensions,
784780
}) {

recreate.go

-2
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,11 @@ func (h toCQLHelpers) tableOptionsToCQL(ops TableMetadataOptions) ([]string, err
319319
"bloom_filter_fp_chance": ops.BloomFilterFpChance,
320320
"comment": ops.Comment,
321321
"crc_check_chance": ops.CrcCheckChance,
322-
"dclocal_read_repair_chance": ops.DcLocalReadRepairChance,
323322
"default_time_to_live": ops.DefaultTimeToLive,
324323
"gc_grace_seconds": ops.GcGraceSeconds,
325324
"max_index_interval": ops.MaxIndexInterval,
326325
"memtable_flush_period_in_ms": ops.MemtableFlushPeriodInMs,
327326
"min_index_interval": ops.MinIndexInterval,
328-
"read_repair_chance": ops.ReadRepairChance,
329327
"speculative_retry": ops.SpeculativeRetry,
330328
}
331329

testdata/config/scylla.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ client_encryption_options:
88
keyfile: /etc/scylla/db.key
99
truststore: /etc/scylla/ca.crt
1010
require_client_auth: true
11-
# when using 5.4.x we have to specify force_schema_commit_log option
12-
force_schema_commit_log: true
11+
maintenance_socket: workdir

testdata/recreate/index_golden.cql

-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ CREATE TABLE gocqlx_idx.menus (
1616
AND compaction = {'class':'SizeTieredCompactionStrategy'}
1717
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
1818
AND crc_check_chance = 1
19-
AND dclocal_read_repair_chance = 0
2019
AND default_time_to_live = 0
2120
AND gc_grace_seconds = 864000
2221
AND max_index_interval = 2048
2322
AND memtable_flush_period_in_ms = 0
2423
AND min_index_interval = 128
25-
AND read_repair_chance = 0
2624
AND speculative_retry = '99.0PERCENTILE';
2725

2826
CREATE INDEX menus_name_idx ON gocqlx_idx.menus (name);

testdata/recreate/materialized_views_golden.cql

-6
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ CREATE TABLE gocqlx_mv.mv_buildings (
1414
AND compaction = {'class':'SizeTieredCompactionStrategy'}
1515
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
1616
AND crc_check_chance = 1
17-
AND dclocal_read_repair_chance = 0
1817
AND default_time_to_live = 0
1918
AND gc_grace_seconds = 864000
2019
AND max_index_interval = 2048
2120
AND memtable_flush_period_in_ms = 0
2221
AND min_index_interval = 128
23-
AND read_repair_chance = 0
2422
AND speculative_retry = '99.0PERCENTILE';
2523

2624
CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city AS
@@ -35,13 +33,11 @@ CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city AS
3533
AND compaction = {'class':'SizeTieredCompactionStrategy'}
3634
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
3735
AND crc_check_chance = 1
38-
AND dclocal_read_repair_chance = 0
3936
AND default_time_to_live = 0
4037
AND gc_grace_seconds = 864000
4138
AND max_index_interval = 2048
4239
AND memtable_flush_period_in_ms = 0
4340
AND min_index_interval = 128
44-
AND read_repair_chance = 0
4541
AND speculative_retry = '99.0PERCENTILE';
4642

4743
CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city2 AS
@@ -59,11 +55,9 @@ CREATE MATERIALIZED VIEW gocqlx_mv.mv_building_by_city2 AS
5955
AND compaction = {'class':'SizeTieredCompactionStrategy'}
6056
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
6157
AND crc_check_chance = 1
62-
AND dclocal_read_repair_chance = 0
6358
AND default_time_to_live = 0
6459
AND gc_grace_seconds = 864000
6560
AND max_index_interval = 2048
6661
AND memtable_flush_period_in_ms = 0
6762
AND min_index_interval = 128
68-
AND read_repair_chance = 0
6963
AND speculative_retry = '99.0PERCENTILE';

testdata/recreate/secondary_index_golden.cql

-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ CREATE TABLE gocqlx_sec_idx.menus (
1616
AND compaction = {'class':'SizeTieredCompactionStrategy'}
1717
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
1818
AND crc_check_chance = 1
19-
AND dclocal_read_repair_chance = 0
2019
AND default_time_to_live = 0
2120
AND gc_grace_seconds = 864000
2221
AND max_index_interval = 2048
2322
AND memtable_flush_period_in_ms = 0
2423
AND min_index_interval = 128
25-
AND read_repair_chance = 0
2624
AND speculative_retry = '99.0PERCENTILE';
2725

2826
CREATE INDEX menus_name_idx ON gocqlx_sec_idx.menus ((location), name);

testdata/recreate/table.cql

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ CREATE TABLE gocqlx_table.monkeySpecies (
88
common_name text,
99
population varint,
1010
average_size int
11-
) WITH comment='Important biological records'
12-
AND read_repair_chance = 1.0;
11+
) WITH comment='Important biological records';
1312

1413
CREATE TABLE gocqlx_table.timeline (
1514
userid uuid,

testdata/recreate/table_golden.cql

-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ CREATE TABLE gocqlx_table.loads (
1616
AND compaction = {'class':'TimeWindowCompactionStrategy','compaction_window_size':'14','compaction_window_unit':'DAYS'}
1717
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
1818
AND crc_check_chance = 1
19-
AND dclocal_read_repair_chance = 0
2019
AND default_time_to_live = 0
2120
AND gc_grace_seconds = 864000
2221
AND max_index_interval = 2048
2322
AND memtable_flush_period_in_ms = 0
2423
AND min_index_interval = 128
25-
AND read_repair_chance = 0
2624
AND speculative_retry = '99.0PERCENTILE';
2725

2826
CREATE TABLE gocqlx_table.monkeyspecies (
@@ -36,13 +34,11 @@ CREATE TABLE gocqlx_table.monkeyspecies (
3634
AND compaction = {'class':'SizeTieredCompactionStrategy'}
3735
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
3836
AND crc_check_chance = 1
39-
AND dclocal_read_repair_chance = 0
4037
AND default_time_to_live = 0
4138
AND gc_grace_seconds = 864000
4239
AND max_index_interval = 2048
4340
AND memtable_flush_period_in_ms = 0
4441
AND min_index_interval = 128
45-
AND read_repair_chance = 1
4642
AND speculative_retry = '99.0PERCENTILE';
4743

4844
CREATE TABLE gocqlx_table.timeline (
@@ -59,13 +55,11 @@ CREATE TABLE gocqlx_table.timeline (
5955
AND compaction = {'class':'LeveledCompactionStrategy'}
6056
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
6157
AND crc_check_chance = 1
62-
AND dclocal_read_repair_chance = 0
6358
AND default_time_to_live = 0
6459
AND gc_grace_seconds = 864000
6560
AND max_index_interval = 2048
6661
AND memtable_flush_period_in_ms = 0
6762
AND min_index_interval = 128
68-
AND read_repair_chance = 0
6963
AND speculative_retry = '99.0PERCENTILE';
7064

7165
CREATE TABLE gocqlx_table.users_picture (
@@ -81,11 +75,9 @@ CREATE TABLE gocqlx_table.users_picture (
8175
AND compaction = {'class':'SizeTieredCompactionStrategy'}
8276
AND compression = {'sstable_compression':'org.apache.cassandra.io.compress.LZ4Compressor'}
8377
AND crc_check_chance = 1
84-
AND dclocal_read_repair_chance = 0
8578
AND default_time_to_live = 0
8679
AND gc_grace_seconds = 864000
8780
AND max_index_interval = 2048
8881
AND memtable_flush_period_in_ms = 0
8982
AND min_index_interval = 128
90-
AND read_repair_chance = 0
9183
AND speculative_retry = '99.0PERCENTILE';

0 commit comments

Comments
 (0)