Add a UnsafeReadScheduledCompact and UnsafeReadFinishedCompact

Signed-off-by: caojiamingalan <alan.c.19971111@gmail.com>
This commit is contained in:
caojiamingalan 2023-07-17 14:45:00 -05:00
parent 8f4b6c9ed2
commit eb9bfaa983
2 changed files with 23 additions and 21 deletions

View File

@ -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) {
@ -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",
@ -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)

View File

@ -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) (int64, 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) (int64, bool) {
_, scheduledCompactBytes := tx.UnsafeRange(buckets.Meta, scheduledCompactKeyName, nil, 0)
if len(scheduledCompactBytes) != 0 {
return bytesToRev(scheduledCompactBytes[0]).main, true
}
return 0, false
}