Skip to content

Commit e54e420

Browse files
authored
Fixed cloning of cluster status to retain server id and shard id generator (oxia-db#307)
1 parent 28e02ec commit e54e420

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

coordinator/model/cluster_status.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ func (n NamespaceStatus) Clone() NamespaceStatus {
9595

9696
func (c ClusterStatus) Clone() *ClusterStatus {
9797
r := &ClusterStatus{
98-
Namespaces: make(map[string]NamespaceStatus),
98+
Namespaces: make(map[string]NamespaceStatus),
99+
ShardIdGenerator: c.ShardIdGenerator,
100+
ServerIdx: c.ServerIdx,
99101
}
100102

101103
for name, n := range c.Namespaces {

coordinator/model/cluster_status_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func TestClusterStatus_Clone(t *testing.T) {
4444
},
4545
},
4646
},
47+
ShardIdGenerator: 5,
48+
ServerIdx: 7,
4749
}
4850

4951
cs2 := cs1.Clone()
@@ -56,4 +58,7 @@ func TestClusterStatus_Clone(t *testing.T) {
5658
assert.NotSame(t, cs1.Namespaces["test-ns"].Shards, cs2.Namespaces["test-ns"].Shards)
5759
assert.Equal(t, cs1.Namespaces["test-ns"].Shards[0], cs2.Namespaces["test-ns"].Shards[0])
5860
assert.NotSame(t, cs1.Namespaces["test-ns"].Shards[0], cs2.Namespaces["test-ns"].Shards[0])
61+
62+
assert.Equal(t, cs1.ShardIdGenerator, cs2.ShardIdGenerator)
63+
assert.Equal(t, cs1.ServerIdx, cs2.ServerIdx)
5964
}

0 commit comments

Comments
 (0)