diff --git a/go.mod b/go.mod index 3d68270eeb6..2f82d40365e 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/soheilhy/cmux v0.1.4 github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.1 - github.com/stretchr/testify v1.3.0 // indirect + github.com/stretchr/testify v1.3.0 github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966 github.com/urfave/cli v1.20.0 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 diff --git a/mvcc/kvstore.go b/mvcc/kvstore.go index 44190871249..d688dcd1cfa 100644 --- a/mvcc/kvstore.go +++ b/mvcc/kvstore.go @@ -381,6 +381,7 @@ func (s *store) restore() error { _, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0) if len(finishedCompactBytes) != 0 { + s.revMu.Lock() s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main if s.lg != nil { @@ -393,6 +394,7 @@ func (s *store) restore() error { } else { plog.Printf("restore compact to %d", s.compactMainRev) } + s.revMu.Unlock() } _, scheduledCompactBytes := tx.UnsafeRange(metaBucketName, scheduledCompactKeyName, nil, 0) scheduledCompact := int64(0) @@ -421,16 +423,22 @@ func (s *store) restore() error { revToBytes(newMin, min) } close(rkvc) - s.currentRev = <-revc - // keys in the range [compacted revision -N, compaction] might all be deleted due to compaction. - // the correct revision should be set to compaction revision in the case, not the largest revision - // we have seen. - if s.currentRev < s.compactMainRev { - s.currentRev = s.compactMainRev - } - if scheduledCompact <= s.compactMainRev { - scheduledCompact = 0 + { + s.revMu.Lock() + s.currentRev = <-revc + + // keys in the range [compacted revision -N, compaction] might all be deleted due to compaction. + // the correct revision should be set to compaction revision in the case, not the largest revision + // we have seen. + if s.currentRev < s.compactMainRev { + s.currentRev = s.compactMainRev + } + + if scheduledCompact <= s.compactMainRev { + scheduledCompact = 0 + } + s.revMu.Unlock() } for key, lid := range keyToLease {