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

txn-file: Sort by chunks first during group to batches #1456

Merged
merged 1 commit into from
Sep 2, 2024
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
7 changes: 4 additions & 3 deletions txnkv/transaction/txn_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ func (cs *txnChunkSlice) groupToBatches(c *locate.RegionCache, bo *retry.Backoff
batches = append(batches, *batch)
}
sort.Slice(batches, func(i, j int) bool {
// Sort by both chunks and region, to make sure that primary key is in the first batch:
// Sort by chunks first, and then by region, to make sure that primary key is in the first batch:
// 1. Different batches may contain the same chunks.
// 2. Different batches may have regions with same start key (if region merge happens during grouping).
cmp := bytes.Compare(batches[i].region.StartKey, batches[j].region.StartKey)
// 3. Bigger batches may have regions with smaller start key (if region merge happens during grouping).
cmp := bytes.Compare(batches[i].Smallest(), batches[j].Smallest())
if cmp == 0 {
return bytes.Compare(batches[i].Smallest(), batches[j].Smallest()) < 0
return bytes.Compare(batches[i].region.StartKey, batches[j].region.StartKey) < 0
}
return cmp < 0
})
Expand Down
Loading