Skip to content

Commit

Permalink
server/cluster: fix storing old store info into storage when handling…
Browse files Browse the repository at this point in the history
… heartbeat (tikv#2715)

Signed-off-by: Howard Lau <howardlau1999@hotmail.com>
Signed-off-by: ZenoTan <zenotan1998@gmail.com>
  • Loading branch information
howardlau1999 authored Aug 3, 2020
1 parent eb6a4c3 commit 4bcf549
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func (c *RaftCluster) HandleStoreHeartbeat(stats *pdpb.StoreStats) error {
zap.Uint64("available", newStore.GetAvailable()))
}
if newStore.NeedPersist() && c.storage != nil {
if err := c.storage.SaveStore(store.GetMeta()); err != nil {
if err := c.storage.SaveStore(newStore.GetMeta()); err != nil {
log.Error("failed to persist store", zap.Uint64("store-id", newStore.GetID()))
} else {
newStore = newStore.Clone(core.SetLastPersistTime(time.Now()))
Expand Down
7 changes: 5 additions & 2 deletions server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (s *testClusterInfoSuite) TestStoreHeartbeat(c *C) {

n, np := uint64(3), uint64(3)
stores := newTestStores(n)
storeMetasAfterHeartbeat := make([]*metapb.Store, 0, n)
regions := newTestRegions(n, np)

for _, region := range regions {
Expand All @@ -74,16 +75,18 @@ func (s *testClusterInfoSuite) TestStoreHeartbeat(c *C) {
s := cluster.GetStore(store.GetID())
c.Assert(s.GetLastHeartbeatTS().UnixNano(), Not(Equals), int64(0))
c.Assert(s.GetStoreStats(), DeepEquals, storeStats)

storeMetasAfterHeartbeat = append(storeMetasAfterHeartbeat, s.GetMeta())
}

c.Assert(cluster.GetStoreCount(), Equals, int(n))

for _, store := range stores {
for i, store := range stores {
tmp := &metapb.Store{}
ok, err := cluster.storage.LoadStore(store.GetID(), tmp)
c.Assert(ok, IsTrue)
c.Assert(err, IsNil)
c.Assert(tmp, DeepEquals, store.GetMeta())
c.Assert(tmp, DeepEquals, storeMetasAfterHeartbeat[i])
}
}

Expand Down

0 comments on commit 4bcf549

Please sign in to comment.