Merge pull request #4915 from heyitsanthony/hash-barrier

etcdserver: force backend commit before acking physical compaction
This commit is contained in:
Anthony Romano 2016-03-31 21:36:57 -07:00
commit bdaba136a9
2 changed files with 15 additions and 4 deletions

View File

@ -98,6 +98,12 @@ func (s *EtcdServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.
result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{Compaction: r})
if r.Physical && result.physc != nil {
<-result.physc
// The compaction is done deleting keys; the hash is now settled
// but the data is not necessarily committed. If there's a crash,
// the hash may revert to a hash prior to compaction completing
// if the compaction resumes. Force the finished compaction to
// commit so it won't resume following a crash.
s.be.ForceCommit()
}
if err != nil {
return nil, err

View File

@ -357,16 +357,21 @@ func (s *store) restore() error {
}
_, scheduledCompactBytes := tx.UnsafeRange(metaBucketName, scheduledCompactKeyName, nil, 0)
scheduledCompact := int64(0)
if len(scheduledCompactBytes) != 0 {
scheduledCompact := bytesToRev(scheduledCompactBytes[0]).main
if scheduledCompact > s.compactMainRev {
log.Printf("storage: resume scheduled compaction at %d", scheduledCompact)
go s.Compact(scheduledCompact)
scheduledCompact = bytesToRev(scheduledCompactBytes[0]).main
if scheduledCompact <= s.compactMainRev {
scheduledCompact = 0
}
}
tx.Unlock()
if scheduledCompact != 0 {
s.Compact(scheduledCompact)
log.Printf("storage: resume scheduled compaction at %d", scheduledCompact)
}
return nil
}