Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kv/kvprober: use single batch in write probe #80007

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/kv/kvprober/kvprober.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,15 @@ func (p *proberOpsImpl) Read(key interface{}) func(context.Context, *kv.Txn) err
// GC will clean it up.
func (p *proberOpsImpl) Write(key interface{}) func(context.Context, *kv.Txn) error {
return func(ctx context.Context, txn *kv.Txn) error {
if err := txn.Put(ctx, key, putValue); err != nil {
return err
}
return txn.Del(ctx, key)
// Use a single batch so that the entire txn requires a single pass
// through Raft. It's not strictly necessary that we Put before we
// Del the key, because a Del is blind and leaves a tombstone even
// when the key is not live, but this is not guaranteed by the API,
// so we avoid depending on a subtlety of the implementation.
b := txn.NewBatch()
b.Put(key, putValue)
b.Del(key)
return txn.CommitInBatch(ctx, b)
}
}

Expand Down