fix(clustermgr): fix abnormal hardState commit

with #22897498

Signed-off-by: tangdeyi <tangdeyi@oppo.com>
This commit is contained in:
tangdeyi 2025-01-13 11:36:57 +08:00 committed by luckydog
parent 4a96eeb26e
commit c255d8f92f
2 changed files with 16 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import (
"runtime"
"sync"
"github.com/cubefs/cubefs/blobstore/util/log"
"go.etcd.io/etcd/raft/v3"
pb "go.etcd.io/etcd/raft/v3/raftpb"
)
@ -77,6 +78,11 @@ func OpenWal(dir string, sync bool) (*Wal, error) {
if err != nil {
return nil, err
}
// fix abnormal hardState commit
if w.hs.Commit > w.LastIndex() {
log.Warnf("fix abnormal hardState commit, firstIndex: %d, lastIndex: %d, hardState: %v", w.FirstIndex(), w.LastIndex(), w.hs)
w.hs.Commit = w.LastIndex()
}
return w, nil
}

View File

@ -151,5 +151,15 @@ func TestRaftWal(t *testing.T) {
require.Equal(t, uint64(1), hs.Vote)
require.Equal(t, uint64(100), hs.Commit)
err = wal.SaveHardState(pb.HardState{
Term: 5,
Vote: 1,
Commit: 200,
})
require.Nil(t, err)
wal.Close()
wal, err = OpenWal(dir, true)
require.Nil(t, err)
wal.Close()
}