Skip to content

Commit

Permalink
Merge pull request #13568 from horizonzy/avoid-always-put-metaterm
Browse files Browse the repository at this point in the history
Avoid always update meta term.
  • Loading branch information
ptabor authored Jan 22, 2022
2 parents f73d625 + 282e4e6 commit 17568a1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions server/storage/schema/cindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func ReadConsistentIndex(tx backend.ReadTx) (uint64, uint64) {

func UnsafeUpdateConsistentIndex(tx backend.BatchTx, index uint64, term uint64, onlyGrow bool) {
if index == 0 {
// Never save 0 as it means that we didn't loaded the real index yet.
// Never save 0 as it means that we didn't load the real index yet.
return
}

Expand All @@ -67,9 +67,19 @@ func UnsafeUpdateConsistentIndex(tx backend.BatchTx, index uint64, term uint64,
if term < oldTerm {
return
}
if term == oldTerm && index <= oldi {
return
if index > oldi {
bs1 := make([]byte, 8)
binary.BigEndian.PutUint64(bs1, index)
// put the index into the underlying backend
// tx has been locked in TxnBegin, so there is no need to lock it again
tx.UnsafePut(Meta, MetaConsistentIndexKeyName, bs1)
}
if term > 0 && term > oldTerm {
bs2 := make([]byte, 8)
binary.BigEndian.PutUint64(bs2, term)
tx.UnsafePut(Meta, MetaTermKeyName, bs2)
}
return
}

bs1 := make([]byte, 8)
Expand Down

0 comments on commit 17568a1

Please sign in to comment.