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

sql: change index backfill merger to use batch api #77055

Merged
merged 1 commit into from
Mar 3, 2022

Conversation

rhu713
Copy link
Contributor

@rhu713 rhu713 commented Feb 25, 2022

Use Batch API instead of txn.Scan() in order to limit the number of bytes per
batch response in the index backfill merger.

Fixes #76685.

Release note: None

@rhu713 rhu713 requested review from a team and stevendanna and removed request for a team February 25, 2022 20:21
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rhu713 rhu713 requested a review from a team February 25, 2022 20:22
Copy link
Contributor

@chengxiong-ruan chengxiong-ruan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @stevendanna)

settings.TenantWritable,
"bulkio.index_backfill.merge_batch_bytes",
"the max number of bytes we merge between temporary and adding indexes in a single batch",
16<<10,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this number come from? It feels small. Ideally what we'd do is both have this be larger and pull this much out of the memory monitor before issuing it.

At the very least, comment how this number was chosen.

Copy link
Collaborator

@stevendanna stevendanna Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to choose based on some prior art, we use 16 MB over in changefeeds:

const targetBytesPerScan = 16 << 20 // 16 MiB
Although we run those scans in parallel which we don't do yet here.

I opened an issue for the memory monitor here: #77123

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I'll use 16MiB here. It looks like it should be larger than 1000 KVs from looking at indexes in the demo. Also added the memory monitor and pull the merge_batch_bytes out of it before sending the request.

Comment on lines 324 to 325
optional int64 chunk_size = 6 [(gogoproto.nullable) = false];
optional int64 chunk_bytes = 7 [(gogoproto.nullable) = false];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in retrospect I don't think it's a great idea to put either of these in the spec. Instead, can we just have each of the processors read from the setting per batch? That way you could change it at runtime without a pause-resume cycle. Just a suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, implemented reading the setting at beginning of each batch.

sourceKV := &kvs[i]
destKeys := make([]roachpb.Key, len(resp.Rows))
for i := range resp.Rows {
sourceKV := &resp.Rows[i]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by: it feel sort of lame to allocate a new byte slice here for each key in destKeys. We could amortize the allocations by using a single slice of buffer and always appending to it and then sub-slicing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, changed implementation to use a single slice buffer.

@rhu713 rhu713 force-pushed the ib-merge-api branch 3 times, most recently from af1f309 to a657e1c Compare March 1, 2022 14:17
Use Batch API instead of txn.Scan() in order to limit the number of bytes per
batch response in the index backfill merger.

Fixes cockroachdb#76685.

Release justification: scan API change without changing functionality

Release note: None

Release justification:
@rhu713
Copy link
Contributor Author

rhu713 commented Mar 3, 2022

bors r+

@craig craig bot merged commit 960f2b4 into cockroachdb:master Mar 3, 2022
@craig
Copy link
Contributor

craig bot commented Mar 3, 2022

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: avoid use of txn.Scan API in IndexBackfillMerger
5 participants