mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Add a UnsafeReadScheduledCompact and UnsafeReadFinishedCompact Signed-off-by: caojiamingalan <alan.c.19971111@gmail.com>
This commit is contained in:
parent
8f4b6c9ed2
commit
eb9bfaa983
@ -232,19 +232,9 @@ func (s *store) checkPrevCompactionCompleted() bool {
|
|||||||
tx := s.b.ReadTx()
|
tx := s.b.ReadTx()
|
||||||
tx.Lock()
|
tx.Lock()
|
||||||
defer tx.Unlock()
|
defer tx.Unlock()
|
||||||
_, scheduledCompactBytes := tx.UnsafeRange(buckets.Meta, scheduledCompactKeyName, nil, 0)
|
scheduledCompact, scheduledCompactFound := UnsafeReadScheduledCompact(tx)
|
||||||
scheduledCompact := int64(0)
|
finishedCompact, finishedCompactFound := UnsafeReadFinishedCompact(tx)
|
||||||
if len(scheduledCompactBytes) != 0 {
|
return scheduledCompact == finishedCompact && scheduledCompactFound == finishedCompactFound
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) compact(trace *traceutil.Trace, rev, prevCompactRev int64, prevCompactionCompleted bool) (<-chan struct{}, error) {
|
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 := s.b.ReadTx()
|
||||||
tx.Lock()
|
tx.Lock()
|
||||||
|
|
||||||
_, finishedCompactBytes := tx.UnsafeRange(buckets.Meta, finishedCompactKeyName, nil, 0)
|
finishedCompact, found := UnsafeReadFinishedCompact(tx)
|
||||||
if len(finishedCompactBytes) != 0 {
|
if found {
|
||||||
s.revMu.Lock()
|
s.revMu.Lock()
|
||||||
s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main
|
s.compactMainRev = finishedCompact
|
||||||
|
|
||||||
s.lg.Info(
|
s.lg.Info(
|
||||||
"restored last compact revision",
|
"restored last compact revision",
|
||||||
@ -356,11 +346,7 @@ func (s *store) restore() error {
|
|||||||
)
|
)
|
||||||
s.revMu.Unlock()
|
s.revMu.Unlock()
|
||||||
}
|
}
|
||||||
_, scheduledCompactBytes := tx.UnsafeRange(buckets.Meta, scheduledCompactKeyName, nil, 0)
|
scheduledCompact, _ := UnsafeReadScheduledCompact(tx)
|
||||||
scheduledCompact := int64(0)
|
|
||||||
if len(scheduledCompactBytes) != 0 {
|
|
||||||
scheduledCompact = bytesToRev(scheduledCompactBytes[0]).main
|
|
||||||
}
|
|
||||||
|
|
||||||
// index keys concurrently as they're loaded in from tx
|
// index keys concurrently as they're loaded in from tx
|
||||||
keysGauge.Set(0)
|
keysGauge.Set(0)
|
||||||
|
@ -41,3 +41,19 @@ func UnsafeSetScheduledCompact(tx backend.BatchTx, value int64) {
|
|||||||
revToBytes(revision{main: value}, rbytes)
|
revToBytes(revision{main: value}, rbytes)
|
||||||
tx.UnsafePut(buckets.Meta, scheduledCompactKeyName, 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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user