Skip to content

Commit ed913a3

Browse files
authored
Merge pull request #159294 from yuzefovich/blathers/backport-release-26.1-159113
release-26.1: kvcoord: optimize txn write buffer for read-only txns
2 parents 20b61d1 + d090658 commit ed913a3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/kv/kvclient/kvcoord/txn_interceptor_write_buffer.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,15 @@ func (twb *txnWriteBuffer) mergeWithScanResp(
11621162
"with COL_BATCH_RESPONSE scan format")
11631163
}
11641164

1165+
if twb.buffer.Len() == 0 {
1166+
// If we haven't buffered any writes, then we can just return the server
1167+
// response unchanged.
1168+
// TODO(yuzefovich): we could take the optimization further by examining
1169+
// whether any buffered writes overlap with the Scan request and
1170+
// skipping the merge step if not.
1171+
return resp, nil
1172+
}
1173+
11651174
respIter := newScanRespIter(req, resp)
11661175
// First, calculate the size of the merged response. This then allows us to
11671176
// exactly pre-allocate the response slice when constructing the respMerger.
@@ -1186,6 +1195,15 @@ func (twb *txnWriteBuffer) mergeWithReverseScanResp(
11861195
"ReverseScanRequest with COL_BATCH_RESPONSE scan format")
11871196
}
11881197

1198+
if twb.buffer.Len() == 0 {
1199+
// If we haven't buffered any writes, then we can just return the server
1200+
// response unchanged.
1201+
// TODO(yuzefovich): we could take the optimization further by examining
1202+
// whether any buffered writes overlap with the ReverseScan request and
1203+
// skipping the merge step if not.
1204+
return resp, nil
1205+
}
1206+
11891207
respIter := newReverseScanRespIter(req, resp)
11901208
// First, calculate the size of the merged response. This then allows us to
11911209
// exactly pre-allocate the response slice when constructing the respMerger.

0 commit comments

Comments
 (0)