Skip to content

Commit

Permalink
Merge pull request #35752 from bdarnell/backport21-merge-waitforappli…
Browse files Browse the repository at this point in the history
…cation

release-2.1: storage: Sync to disk before returning in WaitForApplication
  • Loading branch information
bdarnell authored Mar 18, 2019
2 parents 7ce9188 + c4771c2 commit deb08aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pkg/storage/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,18 @@ func Scan(engine Reader, start, end MVCCKey, max int64) ([]MVCCKeyValue, error)
})
return kvs, err
}

// WriteSyncNoop carries out a synchronous no-op write to the engine.
func WriteSyncNoop(ctx context.Context, eng Engine) error {
batch := eng.NewBatch()
defer batch.Close()

if err := batch.LogData(nil); err != nil {
return err
}

if err := batch.Commit(true /* sync */); err != nil {
return err
}
return nil
}
14 changes: 13 additions & 1 deletion pkg/storage/stores_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage/engine"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/retry"
)
Expand Down Expand Up @@ -102,7 +103,18 @@ func (is Server) WaitForApplication(
leaseAppliedIndex := repl.mu.state.LeaseAppliedIndex
repl.mu.RUnlock()
if leaseAppliedIndex >= req.LeaseIndex {
return nil
// For performance reasons, we don't sync to disk when
// applying raft commands. This means that if a node restarts
// after applying but before the next sync, its
// LeaseAppliedIndex could temporarily regress (until it
// reapplies its latest raft log entries).
//
// Merging relies on the monotonicity of the log applied
// index, so before returning ensure that rocksdb has synced
// everything up to this point to disk.
//
// https://github.com/cockroachdb/cockroach/issues/33120
return engine.WriteSyncNoop(ctx, s.engine)
}
}
if ctx.Err() == nil {
Expand Down

0 comments on commit deb08aa

Please sign in to comment.