Skip to content

Commit

Permalink
storage: add ExportOptions.MaxIntents
Browse files Browse the repository at this point in the history
`Engine.ExportMVCCToSst()` implementations would previously fetch the
cluster setting `MaxIntentsPerWriteIntentError` internally from the
engine's cluster settings, which can be opaque.

This patch instead adds `ExportOptions.MaxIntents` and passes the
cluster setting in expicitly, for clarity. This is consistent with what
we already do for `ScanOptions.MaxIntents`.

Release note: None
  • Loading branch information
erikgrinaker committed Oct 29, 2021
1 parent 031fda7 commit af360f8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions pkg/kv/kvserver/batcheval/cmd_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func evalExport(

maxRunTime := exportRequestMaxIterationTime.Get(&cArgs.EvalCtx.ClusterSettings().SV)

var maxIntents uint64
if m := storage.MaxIntentsPerWriteIntentError.Get(&cArgs.EvalCtx.ClusterSettings().SV); m > 0 {
maxIntents = uint64(m)
}

// Time-bound iterators only make sense to use if the start time is set.
useTBI := args.EnableTimeBoundIteratorOptimization && !args.StartTime.IsEmpty()
// Only use resume timestamp if splitting mid key is enabled.
Expand All @@ -170,6 +175,7 @@ func evalExport(
ExportAllRevisions: exportAllRevisions,
TargetSize: targetSize,
MaxSize: maxSize,
MaxIntents: maxIntents,
StopMidKey: args.SplitMidKey,
UseTBI: useTBI,
ResourceLimiter: storage.NewResourceLimiter(storage.ResourceLimiterOptions{MaxRunTime: maxRunTime}, timeutil.DefaultTimeSource{}),
Expand Down
6 changes: 6 additions & 0 deletions pkg/storage/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ type ExportOptions struct {
// to an SST that exceeds maxSize, an error will be returned. This parameter
// exists to prevent creating SSTs which are too large to be used.
MaxSize uint64
// MaxIntents specifies the number of intents to collect and return in a
// WriteIntentError. The caller will likely resolve the returned intents and
// retry the call, which would be quadratic, so this significantly reduces the
// overall number of scans. 0 disables batching and returns the first intent,
// pass math.MaxUint64 to collect all.
MaxIntents uint64
// If StopMidKey is false, once function reaches targetSize it would continue
// adding all versions until it reaches next key or end of range. If true, it
// would stop immediately when targetSize is reached and return the next versions
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/mvcc_incremental_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func assertExportedErrs(
ExportAllRevisions: revisions,
TargetSize: big,
MaxSize: big,
MaxIntents: uint64(MaxIntentsPerWriteIntentError.Default()),
StopMidKey: false,
UseTBI: useTBI,
}, sstFile)
Expand Down
13 changes: 5 additions & 8 deletions pkg/storage/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,7 @@ func (p *Pebble) ExportMVCCToSst(
) (roachpb.BulkOpSummary, roachpb.Key, hlc.Timestamp, error) {
r := wrapReader(p)
// Doing defer r.Free() does not inline.
maxIntentCount := MaxIntentsPerWriteIntentError.Get(&p.settings.SV)
summary, k, err := pebbleExportToSst(ctx, r, exportOptions, dest, maxIntentCount)
summary, k, err := pebbleExportToSst(ctx, r, exportOptions, dest)
r.Free()
return summary, k.Key, k.Timestamp, err
}
Expand Down Expand Up @@ -1600,8 +1599,7 @@ func (p *pebbleReadOnly) ExportMVCCToSst(
) (roachpb.BulkOpSummary, roachpb.Key, hlc.Timestamp, error) {
r := wrapReader(p)
// Doing defer r.Free() does not inline.
maxIntentCount := MaxIntentsPerWriteIntentError.Get(&p.parent.settings.SV)
summary, k, err := pebbleExportToSst(ctx, r, exportOptions, dest, maxIntentCount)
summary, k, err := pebbleExportToSst(ctx, r, exportOptions, dest)
r.Free()
return summary, k.Key, k.Timestamp, err
}
Expand Down Expand Up @@ -1867,8 +1865,7 @@ func (p *pebbleSnapshot) ExportMVCCToSst(
) (roachpb.BulkOpSummary, roachpb.Key, hlc.Timestamp, error) {
r := wrapReader(p)
// Doing defer r.Free() does not inline.
maxIntentCount := MaxIntentsPerWriteIntentError.Get(&p.settings.SV)
summary, k, err := pebbleExportToSst(ctx, r, exportOptions, dest, maxIntentCount)
summary, k, err := pebbleExportToSst(ctx, r, exportOptions, dest)
r.Free()
return summary, k.Key, k.Timestamp, err
}
Expand Down Expand Up @@ -1989,7 +1986,7 @@ func (e *ExceedMaxSizeError) Error() string {
}

func pebbleExportToSst(
ctx context.Context, reader Reader, options ExportOptions, dest io.Writer, maxIntentCount int64,
ctx context.Context, reader Reader, options ExportOptions, dest io.Writer,
) (roachpb.BulkOpSummary, MVCCKey, error) {
var span *tracing.Span
ctx, span = tracing.ChildSpan(ctx, "pebbleExportToSst")
Expand Down Expand Up @@ -2115,7 +2112,7 @@ func pebbleExportToSst(
// If we do it means this export can't complete and is aborted. We need to loop over remaining data
// to collect all matching intents before returning them in an error to the caller.
if iter.NumCollectedIntents() > 0 {
for int64(iter.NumCollectedIntents()) < maxIntentCount {
for uint64(iter.NumCollectedIntents()) < options.MaxIntents {
iter.NextKey()
// If we encounter other errors during intent collection, we return our original write intent failure.
// We would find this new error again upon retry.
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/pebble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ func TestSstExportFailureIntentBatching(t *testing.T) {
ExportAllRevisions: true,
TargetSize: 0,
MaxSize: 0,
MaxIntents: uint64(MaxIntentsPerWriteIntentError.Default()),
StopMidKey: false,
UseTBI: true,
}, destination)
Expand Down

0 comments on commit af360f8

Please sign in to comment.