-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
colexec: introduce batches with dynamic capacity
This commit introduces `DynamicBatchSizeHelper` which is a utility struct that helps operators achieve dynamic batch size behavior. The contract is that those operators that want such behavior are required to call `ResetMaybeReallocate` method which might allocate a new batch (it uses an exponential capacity growth until `coldata.BatchSize()` and also supports a minimum capacity argument). Most notably, the helper is now used by `cFetcher` as well as several other operators that could be the "sources of the batch' origination" (inboxes, ordered synchronizers, columnarizers) and a few others. The operators that are expected to take long time in order to produce a single batch (like joiners and aggregators) don't exhibit the dynamic batch size behavior. The main operator that I'm not sure about whether we want to exhibit the dynamic batch size behavior is `routerOutputOp`. Release note: None
- Loading branch information
1 parent
b121cb6
commit 3a93872
Showing
13 changed files
with
343 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package colexec | ||
|
||
import ( | ||
"github.com/cockroachdb/cockroach/pkg/col/coldata" | ||
"github.com/cockroachdb/cockroach/pkg/sql/colmem" | ||
"github.com/cockroachdb/cockroach/pkg/sql/types" | ||
) | ||
|
||
// NewDynamicBatchSizeHelper returns a new DynamicBatchSizeHelper. | ||
func NewDynamicBatchSizeHelper( | ||
allocator *colmem.Allocator, typs []*types.T, | ||
) *DynamicBatchSizeHelper { | ||
return &DynamicBatchSizeHelper{ | ||
allocator: allocator, | ||
typs: typs, | ||
} | ||
} | ||
|
||
// DynamicBatchSizeHelper is a utility struct that helps operators work with | ||
// batches of dynamic size. | ||
type DynamicBatchSizeHelper struct { | ||
allocator *colmem.Allocator | ||
typs []*types.T | ||
} | ||
|
||
// ResetMaybeReallocate returns a batch that is guaranteed to be in a "reset" | ||
// state and to have the capacity of at least minCapacity. The method will | ||
// grow the allocated capacity of the batch exponentially, until the batch | ||
// reaches coldata.BatchSize(). | ||
func (d *DynamicBatchSizeHelper) ResetMaybeReallocate( | ||
batch coldata.Batch, minCapacity int, | ||
) (_ coldata.Batch, reallocated bool) { | ||
reallocated = true | ||
if batch == nil { | ||
batch = d.allocator.NewMemBatchWithFixedCapacity(d.typs, minCapacity) | ||
} else if batch.Capacity() < coldata.BatchSize() { | ||
newCapacity := batch.Capacity() * 2 | ||
if newCapacity < minCapacity { | ||
newCapacity = minCapacity | ||
} | ||
if newCapacity > coldata.BatchSize() { | ||
newCapacity = coldata.BatchSize() | ||
} | ||
batch = d.allocator.NewMemBatchWithFixedCapacity(d.typs, newCapacity) | ||
} else { | ||
reallocated = false | ||
batch.ResetInternalBatch() | ||
} | ||
return batch, reallocated | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.