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

refactor: Improve Zone Initialization and Node Shards Assignment #154

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
21 changes: 16 additions & 5 deletions pkg/cluster/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ func SetMappingAlg(algVersion uint32) {
newMappingAlg = true
}

// NewZone creates a new zone with the specified attributes.
func NewZone(zoneid uint32, numNodes uint32) *Zone {
zone := newZone(zoneid, numNodes)
return &zone
}

func NewZoneFromConfig(zoneid uint32, numNodes uint32, numZones uint32, numShards uint32) *Zone {
zone := Zone{
Zoneid: zoneid,
NumNodes: numNodes,
Nodes: make([]Node, 1, numNodes),
}
zone := newZone(zoneid, numNodes)

// Populate Nodes
zone.initShardsAsssignment(numZones, numShards)
Expand Down Expand Up @@ -385,3 +387,12 @@ func (list byWeight) Swap(i, j int) {
func (list byWeight) Less(i, j int) bool {
return list[i].weight > list[j].weight
}

// newZone initializes and returns a new zone with the specified attributes.
func newZone(zoneid uint32, numNodes uint32) Zone {
return Zone{
Zoneid: zoneid,
NumNodes: numNodes,
Nodes: make([]Node, 1, numNodes),
}
}
2 changes: 1 addition & 1 deletion pkg/etcd/etcdreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (cr *EtcdReader) readNodesShards(c *cluster.Cluster, tag string, offset int

// the prefix fetch is sorted by key in reverse order
if c.Zones[zoneid] == nil {
c.Zones[zoneid] = cluster.NewZoneFromConfig(uint32(zoneid), uint32(nodeid+1), c.NumZones, c.NumShards)
c.Zones[zoneid] = cluster.NewZone(uint32(zoneid), uint32(nodeid+1))
}

c.Zones[zoneid].Nodes[nodeid].StringToNode(uint32(zoneid), uint32(nodeid),
Expand Down