From 1f42f78d82eb404fefe8320e66f1c7c9a1d0f208 Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Fri, 31 May 2024 08:37:04 -0400 Subject: [PATCH] Make ExecutableQuery interfaces implementable `ExecutableQuery` uses `partitioner` which makes it unimplementable --- host_source.go | 8 ++++---- metadata_scylla.go | 2 +- query_executor.go | 2 +- scylla.go | 14 +++++++------- scylla_cdc.go | 2 +- session.go | 18 +++++++++--------- token.go | 4 ++-- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/host_source.go b/host_source.go index 0d5a86f6d..551833735 100644 --- a/host_source.go +++ b/host_source.go @@ -435,10 +435,10 @@ func (h *HostInfo) Hostname() string { } func (h *HostInfo) ConnectAddressAndPort() string { - h.mu.Lock() - defer h.mu.Unlock() - addr, _ := h.connectAddressLocked() - return net.JoinHostPort(addr.String(), strconv.Itoa(h.port)) + h.mu.Lock() + defer h.mu.Unlock() + addr, _ := h.connectAddressLocked() + return net.JoinHostPort(addr.String(), strconv.Itoa(h.port)) } func (h *HostInfo) String() string { diff --git a/metadata_scylla.go b/metadata_scylla.go index b675b6c8c..c413d97c0 100644 --- a/metadata_scylla.go +++ b/metadata_scylla.go @@ -244,7 +244,7 @@ type schemaDescriber struct { session *Session mu sync.Mutex - cache map[string]*KeyspaceMetadata + cache map[string]*KeyspaceMetadata // Experimental, this interface and use may change tabletsCache *TabletsMetadata diff --git a/query_executor.go b/query_executor.go index f0d4e761f..02b0ac84a 100644 --- a/query_executor.go +++ b/query_executor.go @@ -18,7 +18,7 @@ type ExecutableQuery interface { Table() string IsIdempotent() bool IsLWT() bool - GetCustomPartitioner() partitioner + GetCustomPartitioner() Partitioner withContext(context.Context) ExecutableQuery diff --git a/scylla.go b/scylla.go index 548debf51..66075c600 100644 --- a/scylla.go +++ b/scylla.go @@ -378,13 +378,13 @@ func (p *scyllaConnPicker) Pick(t Token, keyspace string, table string) *Conn { conn.mu.Lock() if conn.tabletsRoutingV1 { tablets := conn.session.getTablets() - + // Search for tablets with Keyspace and Table from the Query l, r := findTablets(tablets, keyspace, table) - + if l != -1 { tablet := findTabletForToken(tablets, mmt, l, r) - + for _, replica := range tablet.replicas { if replica.hostId.String() == p.hostId { idx = replica.shardId @@ -396,7 +396,7 @@ func (p *scyllaConnPicker) Pick(t Token, keyspace string, table string) *Conn { break } - + if idx == -1 { idx = p.shardOf(mmt) } @@ -415,7 +415,7 @@ func (p *scyllaConnPicker) maybeReplaceWithLessBusyConnection(c *Conn) *Conn { return c } alternative := p.leastBusyConn() - if alternative == nil || alternative.AvailableStreams()*120 > c.AvailableStreams()*100 { + if alternative == nil || alternative.AvailableStreams() * 120 > c.AvailableStreams() * 100 { return c } else { return alternative @@ -423,7 +423,7 @@ func (p *scyllaConnPicker) maybeReplaceWithLessBusyConnection(c *Conn) *Conn { } func isHeavyLoaded(c *Conn) bool { - return c.streams.NumStreams/2 > c.AvailableStreams() + return c.streams.NumStreams / 2 > c.AvailableStreams(); } func (p *scyllaConnPicker) leastBusyConn() *Conn { @@ -858,7 +858,7 @@ func ScyllaGetSourcePort(ctx context.Context) uint16 { // Returns a partitioner specific to the table, or "nil" // if the cluster-global partitioner should be used -func scyllaGetTablePartitioner(session *Session, keyspaceName, tableName string) (partitioner, error) { +func scyllaGetTablePartitioner(session *Session, keyspaceName, tableName string) (Partitioner, error) { isCdc, err := scyllaIsCdcTable(session, keyspaceName, tableName) if err != nil { return nil, err diff --git a/scylla_cdc.go b/scylla_cdc.go index 17de9f1b4..c4f8d5730 100644 --- a/scylla_cdc.go +++ b/scylla_cdc.go @@ -24,7 +24,7 @@ const ( type scyllaCDCPartitioner struct{} -var _ partitioner = scyllaCDCPartitioner{} +var _ Partitioner = scyllaCDCPartitioner{} func (p scyllaCDCPartitioner) Name() string { return scyllaCDCPartitionerName diff --git a/session.go b/session.go index 345e27742..23b661f47 100644 --- a/session.go +++ b/session.go @@ -986,7 +986,7 @@ type queryRoutingInfo struct { lwt bool // If not nil, represents a custom partitioner for the table. - partitioner partitioner + partitioner Partitioner keyspace string @@ -999,7 +999,7 @@ func (qri *queryRoutingInfo) isLWT() bool { return qri.lwt } -func (qri *queryRoutingInfo) getPartitioner() partitioner { +func (qri *queryRoutingInfo) getPartitioner() Partitioner { qri.mu.RLock() defer qri.mu.RUnlock() return qri.partitioner @@ -1310,7 +1310,7 @@ func (q *Query) IsLWT() bool { return q.routingInfo.isLWT() } -func (q *Query) GetCustomPartitioner() partitioner { +func (q *Query) GetCustomPartitioner() Partitioner { return q.routingInfo.getPartitioner() } @@ -1933,7 +1933,7 @@ func (b *Batch) IsLWT() bool { return b.routingInfo.isLWT() } -func (b *Batch) GetCustomPartitioner() partitioner { +func (b *Batch) GetCustomPartitioner() Partitioner { return b.routingInfo.getPartitioner() } @@ -2171,12 +2171,12 @@ type routingKeyInfoLRU struct { } type routingKeyInfo struct { - indexes []int - types []TypeInfo - keyspace string - table string + indexes []int + types []TypeInfo + keyspace string + table string lwt bool - partitioner partitioner + partitioner Partitioner } func (r *routingKeyInfo) String() string { diff --git a/token.go b/token.go index 9e3d3ab68..72d0ce4eb 100644 --- a/token.go +++ b/token.go @@ -17,7 +17,7 @@ import ( ) // a token partitioner -type partitioner interface { +type Partitioner interface { Name() string Hash([]byte) Token ParseString(string) Token @@ -135,7 +135,7 @@ func (ht hostToken) String() string { // a data structure for organizing the relationship between tokens and hosts type tokenRing struct { - partitioner partitioner + partitioner Partitioner // tokens map token range to primary replica. // The elements in tokens are sorted by token ascending.