From 54ffae3c004d59c161beb0f58d4358f68516675f Mon Sep 17 00:00:00 2001 From: sylwiaszunejko Date: Thu, 14 Nov 2024 08:39:16 +0100 Subject: [PATCH 1/2] Check if localHost is not zero token node --- host_source.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/host_source.go b/host_source.go index dbe39ab93..4217e8895 100644 --- a/host_source.go +++ b/host_source.go @@ -885,7 +885,12 @@ func (r *ringDescriber) GetHosts() ([]*HostInfo, string, error) { return r.prevHosts, r.prevPartitioner, err } - hosts := append([]*HostInfo{localHost}, peerHosts...) + var hosts []*HostInfo + if !isZeroToken(localHost) { + hosts = []*HostInfo{localHost} + } + hosts = append(hosts, peerHosts...) + var partitioner string if len(hosts) > 0 { partitioner = hosts[0].Partitioner() From 33448ad7c3a57c7a13439a248eaaaa2be0fda98c Mon Sep 17 00:00:00 2001 From: sylwiaszunejko Date: Thu, 14 Nov 2024 09:33:57 +0100 Subject: [PATCH 2/2] Add test for isZeroToken function --- host_source_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/host_source_test.go b/host_source_test.go index bd45e75bf..a99c9549b 100644 --- a/host_source_test.go +++ b/host_source_test.go @@ -73,6 +73,25 @@ func TestIsValidPeer(t *testing.T) { } } +func TestIsZeroToken(t *testing.T) { + host := &HostInfo{ + rpcAddress: net.ParseIP("0.0.0.0"), + rack: "myRack", + hostId: "0", + dataCenter: "datacenter", + tokens: []string{"0", "1"}, + } + + if isZeroToken(host) { + t.Errorf("expected %+v to NOT be a zero-token host", host) + } + + host.tokens = []string{} + if !isZeroToken(host) { + t.Errorf("expected %+v to be a zero-token host", host) + } +} + func TestHostInfo_ConnectAddress(t *testing.T) { var localhost = net.IPv4(127, 0, 0, 1) tests := []struct {