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

Check if localHost is not zero token node #333

Merged
merged 2 commits into from
Nov 15, 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
7 changes: 6 additions & 1 deletion host_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions host_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading