Skip to content

Commit

Permalink
refactor: Improve Zone Initialization and Node Shards Assignment in
Browse files Browse the repository at this point in the history
refactor: Improve Zone Initialization and Node Shards Assignment in
  • Loading branch information
Sufiyan-Mirza committed Sep 24, 2023
1 parent ca68aa1 commit 5ae4002
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
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

0 comments on commit 5ae4002

Please sign in to comment.