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

[dnm] kv: expose (and use) byte batch response size limit #44341

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
43 changes: 37 additions & 6 deletions c-deps/libroach/protos/roachpb/api.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions c-deps/libroach/protos/roachpb/api.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 26 additions & 7 deletions pkg/kv/dist_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ func (ds *DistSender) divideAndSendBatchToRanges(
}
}()

canParallelize := ba.Header.MaxSpanRequestKeys == 0
canParallelize := ba.Header.MaxSpanRequestKeys == 0 && ba.Header.MaxSpanResponseBytes == 0
if ba.IsSingleCheckConsistencyRequest() {
// Don't parallelize full checksum requests as they have to touch the
// entirety of each replica of each range they touch.
Expand Down Expand Up @@ -1223,28 +1223,47 @@ func (ds *DistSender) divideAndSendBatchToRanges(
ba.UpdateTxn(resp.reply.Txn)
}

mightStopEarly := ba.MaxSpanRequestKeys > 0
mightStopEarly := ba.MaxSpanRequestKeys > 0 || ba.MaxSpanResponseBytes > 0
// Check whether we've received enough responses to exit query loop.
if mightStopEarly {
var replyResults int64
var addedNumKeys int64
var addedNumBytes int64
for _, r := range resp.reply.Responses {
replyResults += r.GetInner().Header().NumKeys
addedNumKeys += r.GetInner().Header().NumKeys
if scan, ok := r.GetInner().(*roachpb.ScanResponse); ok {
// TODO(tbg): deal with general requests.
for _, repr := range scan.BatchResponses {
addedNumBytes += int64(len(repr))
}
}
}
// Update MaxSpanRequestKeys, if applicable. Note that ba might be
// passed recursively to further divideAndSendBatchToRanges() calls.
if ba.MaxSpanRequestKeys > 0 {
if replyResults > ba.MaxSpanRequestKeys {
if addedNumKeys > ba.MaxSpanRequestKeys {
log.Fatalf(ctx, "received %d results, limit was %d",
replyResults, ba.MaxSpanRequestKeys)
addedNumKeys, ba.MaxSpanRequestKeys)
}
ba.MaxSpanRequestKeys -= replyResults
ba.MaxSpanRequestKeys -= addedNumKeys
// Exiting; any missing responses will be filled in via defer().
if ba.MaxSpanRequestKeys == 0 {
couldHaveSkippedResponses = true
resumeReason = roachpb.RESUME_KEY_LIMIT
return
}
}
if ba.MaxSpanResponseBytes > 0 {
if addedNumBytes > ba.MaxSpanResponseBytes {
ba.MaxSpanResponseBytes = 0
} else {
ba.MaxSpanResponseBytes -= addedNumBytes
}
if ba.MaxSpanResponseBytes == 0 {
couldHaveSkippedResponses = true
// TODO(tbg): make a real reason.
resumeReason = roachpb.RESUME_KEY_LIMIT
}
}
}
}

Expand Down
Loading