Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 Add a UnsafeReadScheduledCompact and UnsafeReadFinishedCompact

Signed-off-by: caojiamingalan <alan.c.19971111@gmail.com>
  • Loading branch information
CaojiamingAlan committed Jul 17, 2023
1 parent 8f4b6c9 commit dd78032
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
28 changes: 7 additions & 21 deletions server/mvcc/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,9 @@ func (s *store) checkPrevCompactionCompleted() bool {
tx := s.b.ReadTx()
tx.Lock()
defer tx.Unlock()
_, scheduledCompactBytes := tx.UnsafeRange(buckets.Meta, scheduledCompactKeyName, nil, 0)
scheduledCompact := int64(0)
if len(scheduledCompactBytes) != 0 {
scheduledCompact = bytesToRev(scheduledCompactBytes[0]).main
}

_, finishedCompactBytes := tx.UnsafeRange(buckets.Meta, finishedCompactKeyName, nil, 0)
finishedCompact := int64(0)
if len(finishedCompactBytes) != 0 {
finishedCompact = bytesToRev(finishedCompactBytes[0]).main

}
return scheduledCompact == finishedCompact
scheduledCompact, scheduledCompactFound := UnsafeReadScheduledCompact(tx)
finishedCompact, finishedCompactFound := UnsafeReadFinishedCompact(tx)
return scheduledCompact == finishedCompact && scheduledCompactFound == finishedCompactFound
}

func (s *store) compact(trace *traceutil.Trace, rev, prevCompactRev int64, prevCompactionCompleted bool) (<-chan struct{}, error) {
Expand Down Expand Up @@ -343,10 +333,10 @@ func (s *store) restore() error {
tx := s.b.ReadTx()
tx.Lock()

_, finishedCompactBytes := tx.UnsafeRange(buckets.Meta, finishedCompactKeyName, nil, 0)
if len(finishedCompactBytes) != 0 {
finishedCompact, found := UnsafeReadFinishedCompact(tx)
if found {
s.revMu.Lock()
s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main
s.compactMainRev = finishedCompact

s.lg.Info(
"restored last compact revision",
Expand All @@ -356,11 +346,7 @@ func (s *store) restore() error {
)
s.revMu.Unlock()
}
_, scheduledCompactBytes := tx.UnsafeRange(buckets.Meta, scheduledCompactKeyName, nil, 0)
scheduledCompact := int64(0)
if len(scheduledCompactBytes) != 0 {
scheduledCompact = bytesToRev(scheduledCompactBytes[0]).main
}
scheduledCompact, _ := UnsafeReadScheduledCompact(tx)

// index keys concurrently as they're loaded in from tx
keysGauge.Set(0)
Expand Down
16 changes: 16 additions & 0 deletions server/mvcc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ func UnsafeSetScheduledCompact(tx backend.BatchTx, value int64) {
revToBytes(revision{main: value}, rbytes)
tx.UnsafePut(buckets.Meta, scheduledCompactKeyName, rbytes)
}

func UnsafeReadFinishedCompact(tx backend.ReadTx) (finishedCompact int64, found bool) {
_, finishedCompactBytes := tx.UnsafeRange(buckets.Meta, finishedCompactKeyName, nil, 0)
if len(finishedCompactBytes) != 0 {
return bytesToRev(finishedCompactBytes[0]).main, true
}
return 0, false
}

func UnsafeReadScheduledCompact(tx backend.ReadTx) (scheduledCompact int64, found bool) {
_, scheduledCompactBytes := tx.UnsafeRange(buckets.Meta, scheduledCompactKeyName, nil, 0)
if len(scheduledCompactBytes) != 0 {
return bytesToRev(scheduledCompactBytes[0]).main, true
}
return 0, false
}

0 comments on commit dd78032

Please sign in to comment.