mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(clustermgr): fix abnormal hardState commit
with #22897498 Signed-off-by: tangdeyi <tangdeyi@oppo.com>
This commit is contained in:
parent
4a96eeb26e
commit
c255d8f92f
@ -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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user