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

release-20.2: backfill: clear bound account after index KV has been written #55092

Merged
merged 1 commit into from
Oct 1, 2020
Merged
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
14 changes: 14 additions & 0 deletions pkg/sql/backfill/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,12 @@ func (ib *IndexBackfiller) Close(ctx context.Context) {
}
}

// Clear releases the allocations on the IndexBackfiller's bound account,
// prepping it for reuse.
func (ib *IndexBackfiller) Clear(ctx context.Context) {
ib.boundAccount.Clear(ctx)
}

// initCols is a helper to populate column metadata of an IndexBackfiller. It
// populates the cols and colIdxMap fields.
func (ib *IndexBackfiller) initCols(desc *tabledesc.Immutable) {
Expand Down Expand Up @@ -628,6 +634,9 @@ func (ib *IndexBackfiller) init(

// BuildIndexEntriesChunk reads a chunk of rows from a table using the span sp
// provided, and builds all the added indexes.
// The method accounts for the memory used by the index entries for this chunk
// using the memory monitor associated with ib. It is the callers responsibility
// to clear the associated bound account when appropriate.
func (ib *IndexBackfiller) BuildIndexEntriesChunk(
ctx context.Context,
txn *kv.Txn,
Expand Down Expand Up @@ -789,5 +798,10 @@ func (ib *IndexBackfiller) RunIndexBackfillChunk(
return nil, ConvertBackfillError(ctx, tableDesc, batch)
}

// After the chunk entries have been written, we must clear the bound account
// tracking the memory usage for the chunk.
entries = nil
ib.Clear(ctx)

return key, nil
}
7 changes: 7 additions & 0 deletions pkg/sql/rowexec/indexbackfiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ func (ib *indexBackfiller) runChunk(
return nil, ib.wrapDupError(ctx, err)
}
}

// After the index KVs have been copied to the underlying BulkAdder, we can
// free the memory which was accounted when building the index entries of the
// current chunk.
entries = nil
ib.Clear(ctx)

if knobs.RunAfterBackfillChunk != nil {
if err := ib.adder.Flush(ctx); err != nil {
return nil, ib.wrapDupError(ctx, err)
Expand Down