Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
95141: storage: Add support for TargetBytes for EndTxn r=nvanbenschoten a=KaiSun314

Fixes: #77228

Intent resolution batches are sequenced on raft and each batch can
consist of 100-200 intents. If an intent key or even value in some cases
are large, it is possible that resolving all intents in the batch would
result in a raft command size exceeding the max raft command size
kv.raft.command.max_size.

To address this, we add support for TargetBytes in resolve intent and
resolve intent range commands, allowing us to stop resolving intents in
the batch as soon as we exceed the TargetBytes max bytes limit.

This PR adds byte pagination for synchronous intent resolution (i.e.
EndTxn / End Transaction).

Release note: None

97511: status: set codec from context in table stats requests r=knz a=dhartunian

Replaced usages of `TODOSQLCodec` with the codec from `sqlServer.execCfg`. This enables the DB and Table stats endpoints to work from tenants.

Resolves: #82879

Relates to: #90261, #90267, #90268, #90264, #89429

Epic: CRDB-12100

Release note: None

97657: sql,mon: expose the memory monitors as virtual table r=yuzefovich a=yuzefovich

This commit adjusts our memory monitors to be able to traverse the whole
monitor tree starting at the root monitor. In particular, this commit
introduces a doubly-linked list of "siblings" and stores the reference
to the head in the parent. Whenever a monitor is `Start`ed, it is
included as the new head of its parent's children list, whenever a monitor
is `Stop`ped, it is removed from that list. The overhead of this
additional tracking should be negligible since only the parent's lock
needs to be acquired twice throughout the lifetime of a monitor (thus,
assuming relatevily long-lived sessions, this wouldn't affect the root
monitor) and the increase in allocations is minor.

This required clarification on how locks on a parent and a child can be
held at the same time. In particular, since the main code path is
acquiring locks "upwards" (meaning when growing the child's budget we
might need to grow the parent's budget, and "growing" locks the
corresponding monitor), whenever we want to traverse the tree from the
root down, we have to unlock the parent's monitor before recursing into
the children. As a result, the traversal might give us an inconsistent
view (where a recently stopped child can contribute to the usage of the
parent while we don't recurse into that child). This seems acceptable.

This ability to traverse the whole monitor tree is now exposed as a new
virtual table `crdb_internal.node_memory_monitors` which includes a line
for each monitor active at the time of table generation (subject to
possible inconsistency mentioned above). The table includes the name of
the monitors which can be suggestive about the activity on the cluster,
thus, access to this table is gated on the "view activity" permissions.
The usage of the virtual table to expose the memory monitors information
results in flattening of the tree; however, one of the fields is
a "level" (or "generation") in relation to the root, plus the ordering
of rows is very specific, so we can still format the output to see the
hierarchy. We also assign IDs to the monitors (which is their pointer
address). Exposing this information as a virtual table allows us to use
SQL to analyze it.

Here is one example of visualizing it:
```
[email protected]:26257/defaultdb> SELECT repeat('    ', level) || name || ' ' || crdb_internal.humanize_bytes(used) FROM crdb_internal.node_memory_monitors;
                             ?column?
-------------------------------------------------------------------
  root 0 B
      internal-planner.‹root›.‹resume-job-101› 0 B
      internal-planner.‹node›.‹resume-job-100› 0 B
      internal-planner.‹node›.‹resume-job-842810460057567233› 0 B
      sql 900 KiB
          session root 20 KiB
              txn 10 KiB
                  flow e595eb80 10 KiB
              session 0 B
              txn-fingerprint-id-cache 0 B
          internal SQL executor 0 B
          internal SQL executor 0 B
          internal sql executor 0 B
          conn 105 KiB
          internal SQL executor 70 KiB
          internal SQL executor 60 KiB
          SQLStats 540 KiB
          SQLStats 0 B
      distsql 0 B
      server-cache-mon 0 B
      bulk-mon 0 B
          backup-mon 0 B
          backfill-mon 0 B
      pre-conn 105 KiB
      closed-session-cache 190 KiB
      timeseries-results 0 B
      timeseries-workers 0 B
      kv-mem 20 KiB
          rangefeed-monitor 0 B
          rangefeed-system-monitor 0 B
(30 rows)
```

There are a couple of additional minor improvements:
- we now include the short FlowID into the flow's memory monitor name.
Combined with the distsql_flows virtual table we'll be able to get the
stmt fingerprint for the remote flows running on a node.
- new `crdb_internal.humanize_bytes` builtin function is introduced.

Note that the corresponding `cluster_memory_monitors` virtual table is
not introduced out of caution. In particular, this would lead to RPCs
issued to all nodes in the cluster, and since each node can have on the
order of hundreds of thousands monitors, the response to each RPC could
have non-trivial network cost. We can revisit this decision later if we
find that a cluster level view of the memory monitors is desirable, but
for now a node level view seems like a big improvement on its own.

Addresses: #35097.
Fixes: #90551.

Release note (sql change): New internal virtual table
`crdb_internal.memory_monitors` is introduced. It exposes all of the
current reservations with the memory accounting system on a single node.
Access to the table requires VIEWACTIVITY or VIEWACTIVITYREDACTED
permissions.

97853: builtins: fix crdb_internal.hide_sql_constants array overload r=xinhaoz a=xinhaoz

Previously, erroring on parsing a stmt provided in one of the array elements to crdb_internal.hide_sql_constants would result in an error. This commit ensures that the empty string is returned for an unparseable stmt.

Epic: none

Release note: None

Co-authored-by: Kai Sun <[email protected]>
Co-authored-by: David Hartunian <[email protected]>
Co-authored-by: Yahor Yuzefovich <[email protected]>
Co-authored-by: Xin Hao Zhang <[email protected]>
  • Loading branch information
5 people committed Mar 1, 2023
5 parents f867ce5 + 94fe04e + 4308e91 + b6d04fd + 17f635d commit c3348b0
Show file tree
Hide file tree
Showing 32 changed files with 1,535 additions and 719 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ crdb_internal node_contention_events table admin NULL NULL
crdb_internal node_distsql_flows table admin NULL NULL
crdb_internal node_execution_insights table admin NULL NULL
crdb_internal node_inflight_trace_spans table admin NULL NULL
crdb_internal node_memory_monitors table admin NULL NULL
crdb_internal node_metrics table admin NULL NULL
crdb_internal node_queries table admin NULL NULL
crdb_internal node_runtime_info table admin NULL NULL
Expand Down
41 changes: 39 additions & 2 deletions pkg/ccl/serverccl/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import (
var adminPrefix = "/_admin/v1/"

func getAdminJSONProto(
ts serverutils.TestServerInterface, path string, response protoutil.Message,
ts serverutils.TestTenantInterface, path string, response protoutil.Message,
) error {
return getAdminJSONProtoWithAdminOption(ts, path, response, true)
}

func getAdminJSONProtoWithAdminOption(
ts serverutils.TestServerInterface, path string, response protoutil.Message, isAdmin bool,
ts serverutils.TestTenantInterface, path string, response protoutil.Message, isAdmin bool,
) error {
return serverutils.GetJSONProtoWithAdminOption(ts, adminPrefix+path, response, isAdmin)
}
Expand Down Expand Up @@ -195,3 +195,40 @@ func TestListTenants(t *testing.T) {
}
require.True(t, appTenantFound, "test tenant not found")
}

func TestTableAndDatabaseDetailsAndStats(t *testing.T) {
defer leaktest.AfterTest(t)()

ctx := context.Background()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop(ctx)

st, db := serverutils.StartTenant(t, s, base.TestTenantArgs{
TenantID: serverutils.TestTenantID(),
})
_, err := db.Exec("CREATE TABLE test (id int)")
require.NoError(t, err)
_, err = db.Exec("INSERT INTO test VALUES (1)")
require.NoError(t, err)

// DatabaseDetails
dbResp := &serverpb.DatabaseDetailsResponse{}
err = getAdminJSONProto(st, "databases/defaultdb", dbResp)
require.NoError(t, err)

require.Equal(t, dbResp.TableNames[0], "public.test")

// TableStats
tableStatsResp := &serverpb.TableStatsResponse{}
err = getAdminJSONProto(st, "databases/defaultdb/tables/public.test/stats", tableStatsResp)
require.NoError(t, err)

require.Greater(t, tableStatsResp.Stats.LiveBytes, int64(0))

// TableDetails
tableDetailsResp := &serverpb.TableDetailsResponse{}
err = getAdminJSONProto(st, "databases/defaultdb/tables/public.test", tableDetailsResp)
require.NoError(t, err)

require.Greater(t, tableDetailsResp.DataLiveBytes, int64(0))
}
5 changes: 5 additions & 0 deletions pkg/cli/testdata/zip/partial1
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ debug zip --concurrency=1 --cpu-profile-duration=0s /dev/null
[node 1] retrieving SQL data for crdb_internal.node_distsql_flows... writing output: debug/nodes/1/crdb_internal.node_distsql_flows.txt... done
[node 1] retrieving SQL data for crdb_internal.node_execution_insights... writing output: debug/nodes/1/crdb_internal.node_execution_insights.txt... done
[node 1] retrieving SQL data for crdb_internal.node_inflight_trace_spans... writing output: debug/nodes/1/crdb_internal.node_inflight_trace_spans.txt... done
[node 1] retrieving SQL data for crdb_internal.node_memory_monitors... writing output: debug/nodes/1/crdb_internal.node_memory_monitors.txt... done
[node 1] retrieving SQL data for crdb_internal.node_metrics... writing output: debug/nodes/1/crdb_internal.node_metrics.txt... done
[node 1] retrieving SQL data for crdb_internal.node_queries... writing output: debug/nodes/1/crdb_internal.node_queries.txt... done
[node 1] retrieving SQL data for crdb_internal.node_runtime_info... writing output: debug/nodes/1/crdb_internal.node_runtime_info.txt... done
Expand Down Expand Up @@ -206,6 +207,9 @@ debug zip --concurrency=1 --cpu-profile-duration=0s /dev/null
[node 2] retrieving SQL data for crdb_internal.node_inflight_trace_spans... writing output: debug/nodes/2/crdb_internal.node_inflight_trace_spans.txt...
[node 2] retrieving SQL data for crdb_internal.node_inflight_trace_spans: last request failed: dial tcp ...
[node 2] retrieving SQL data for crdb_internal.node_inflight_trace_spans: creating error output: debug/nodes/2/crdb_internal.node_inflight_trace_spans.txt.err.txt... done
[node 2] retrieving SQL data for crdb_internal.node_memory_monitors... writing output: debug/nodes/2/crdb_internal.node_memory_monitors.txt...
[node 2] retrieving SQL data for crdb_internal.node_memory_monitors: last request failed: dial tcp ...
[node 2] retrieving SQL data for crdb_internal.node_memory_monitors: creating error output: debug/nodes/2/crdb_internal.node_memory_monitors.txt.err.txt... done
[node 2] retrieving SQL data for crdb_internal.node_metrics... writing output: debug/nodes/2/crdb_internal.node_metrics.txt...
[node 2] retrieving SQL data for crdb_internal.node_metrics: last request failed: dial tcp ...
[node 2] retrieving SQL data for crdb_internal.node_metrics: creating error output: debug/nodes/2/crdb_internal.node_metrics.txt.err.txt... done
Expand Down Expand Up @@ -276,6 +280,7 @@ debug zip --concurrency=1 --cpu-profile-duration=0s /dev/null
[node 3] retrieving SQL data for crdb_internal.node_distsql_flows... writing output: debug/nodes/3/crdb_internal.node_distsql_flows.txt... done
[node 3] retrieving SQL data for crdb_internal.node_execution_insights... writing output: debug/nodes/3/crdb_internal.node_execution_insights.txt... done
[node 3] retrieving SQL data for crdb_internal.node_inflight_trace_spans... writing output: debug/nodes/3/crdb_internal.node_inflight_trace_spans.txt... done
[node 3] retrieving SQL data for crdb_internal.node_memory_monitors... writing output: debug/nodes/3/crdb_internal.node_memory_monitors.txt... done
[node 3] retrieving SQL data for crdb_internal.node_metrics... writing output: debug/nodes/3/crdb_internal.node_metrics.txt... done
[node 3] retrieving SQL data for crdb_internal.node_queries... writing output: debug/nodes/3/crdb_internal.node_queries.txt... done
[node 3] retrieving SQL data for crdb_internal.node_runtime_info... writing output: debug/nodes/3/crdb_internal.node_runtime_info.txt... done
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/testdata/zip/partial1_excluded
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ debug zip /dev/null --concurrency=1 --exclude-nodes=2 --cpu-profile-duration=0
[node 1] retrieving SQL data for crdb_internal.node_distsql_flows... writing output: debug/nodes/1/crdb_internal.node_distsql_flows.txt... done
[node 1] retrieving SQL data for crdb_internal.node_execution_insights... writing output: debug/nodes/1/crdb_internal.node_execution_insights.txt... done
[node 1] retrieving SQL data for crdb_internal.node_inflight_trace_spans... writing output: debug/nodes/1/crdb_internal.node_inflight_trace_spans.txt... done
[node 1] retrieving SQL data for crdb_internal.node_memory_monitors... writing output: debug/nodes/1/crdb_internal.node_memory_monitors.txt... done
[node 1] retrieving SQL data for crdb_internal.node_metrics... writing output: debug/nodes/1/crdb_internal.node_metrics.txt... done
[node 1] retrieving SQL data for crdb_internal.node_queries... writing output: debug/nodes/1/crdb_internal.node_queries.txt... done
[node 1] retrieving SQL data for crdb_internal.node_runtime_info... writing output: debug/nodes/1/crdb_internal.node_runtime_info.txt... done
Expand Down Expand Up @@ -185,6 +186,7 @@ debug zip /dev/null --concurrency=1 --exclude-nodes=2 --cpu-profile-duration=0
[node 3] retrieving SQL data for crdb_internal.node_distsql_flows... writing output: debug/nodes/3/crdb_internal.node_distsql_flows.txt... done
[node 3] retrieving SQL data for crdb_internal.node_execution_insights... writing output: debug/nodes/3/crdb_internal.node_execution_insights.txt... done
[node 3] retrieving SQL data for crdb_internal.node_inflight_trace_spans... writing output: debug/nodes/3/crdb_internal.node_inflight_trace_spans.txt... done
[node 3] retrieving SQL data for crdb_internal.node_memory_monitors... writing output: debug/nodes/3/crdb_internal.node_memory_monitors.txt... done
[node 3] retrieving SQL data for crdb_internal.node_metrics... writing output: debug/nodes/3/crdb_internal.node_metrics.txt... done
[node 3] retrieving SQL data for crdb_internal.node_queries... writing output: debug/nodes/3/crdb_internal.node_queries.txt... done
[node 3] retrieving SQL data for crdb_internal.node_runtime_info... writing output: debug/nodes/3/crdb_internal.node_runtime_info.txt... done
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/testdata/zip/partial2
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ debug zip --concurrency=1 --cpu-profile-duration=0 /dev/null
[node 1] retrieving SQL data for crdb_internal.node_distsql_flows... writing output: debug/nodes/1/crdb_internal.node_distsql_flows.txt... done
[node 1] retrieving SQL data for crdb_internal.node_execution_insights... writing output: debug/nodes/1/crdb_internal.node_execution_insights.txt... done
[node 1] retrieving SQL data for crdb_internal.node_inflight_trace_spans... writing output: debug/nodes/1/crdb_internal.node_inflight_trace_spans.txt... done
[node 1] retrieving SQL data for crdb_internal.node_memory_monitors... writing output: debug/nodes/1/crdb_internal.node_memory_monitors.txt... done
[node 1] retrieving SQL data for crdb_internal.node_metrics... writing output: debug/nodes/1/crdb_internal.node_metrics.txt... done
[node 1] retrieving SQL data for crdb_internal.node_queries... writing output: debug/nodes/1/crdb_internal.node_queries.txt... done
[node 1] retrieving SQL data for crdb_internal.node_runtime_info... writing output: debug/nodes/1/crdb_internal.node_runtime_info.txt... done
Expand Down Expand Up @@ -184,6 +185,7 @@ debug zip --concurrency=1 --cpu-profile-duration=0 /dev/null
[node 3] retrieving SQL data for crdb_internal.node_distsql_flows... writing output: debug/nodes/3/crdb_internal.node_distsql_flows.txt... done
[node 3] retrieving SQL data for crdb_internal.node_execution_insights... writing output: debug/nodes/3/crdb_internal.node_execution_insights.txt... done
[node 3] retrieving SQL data for crdb_internal.node_inflight_trace_spans... writing output: debug/nodes/3/crdb_internal.node_inflight_trace_spans.txt... done
[node 3] retrieving SQL data for crdb_internal.node_memory_monitors... writing output: debug/nodes/3/crdb_internal.node_memory_monitors.txt... done
[node 3] retrieving SQL data for crdb_internal.node_metrics... writing output: debug/nodes/3/crdb_internal.node_metrics.txt... done
[node 3] retrieving SQL data for crdb_internal.node_queries... writing output: debug/nodes/3/crdb_internal.node_queries.txt... done
[node 3] retrieving SQL data for crdb_internal.node_runtime_info... writing output: debug/nodes/3/crdb_internal.node_runtime_info.txt... done
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/testdata/zip/testzip
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s /dev/null
[node 1] retrieving SQL data for crdb_internal.node_distsql_flows... writing output: debug/nodes/1/crdb_internal.node_distsql_flows.txt... done
[node 1] retrieving SQL data for crdb_internal.node_execution_insights... writing output: debug/nodes/1/crdb_internal.node_execution_insights.txt... done
[node 1] retrieving SQL data for crdb_internal.node_inflight_trace_spans... writing output: debug/nodes/1/crdb_internal.node_inflight_trace_spans.txt... done
[node 1] retrieving SQL data for crdb_internal.node_memory_monitors... writing output: debug/nodes/1/crdb_internal.node_memory_monitors.txt... done
[node 1] retrieving SQL data for crdb_internal.node_metrics... writing output: debug/nodes/1/crdb_internal.node_metrics.txt... done
[node 1] retrieving SQL data for crdb_internal.node_queries... writing output: debug/nodes/1/crdb_internal.node_queries.txt... done
[node 1] retrieving SQL data for crdb_internal.node_runtime_info... writing output: debug/nodes/1/crdb_internal.node_runtime_info.txt... done
Expand Down
9 changes: 9 additions & 0 deletions pkg/cli/testdata/zip/testzip_concurrent
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ zip
[node 1] retrieving SQL data for crdb_internal.node_inflight_trace_spans...
[node 1] retrieving SQL data for crdb_internal.node_inflight_trace_spans: done
[node 1] retrieving SQL data for crdb_internal.node_inflight_trace_spans: writing output: debug/nodes/1/crdb_internal.node_inflight_trace_spans.txt...
[node 1] retrieving SQL data for crdb_internal.node_memory_monitors...
[node 1] retrieving SQL data for crdb_internal.node_memory_monitors: done
[node 1] retrieving SQL data for crdb_internal.node_memory_monitors: writing output: debug/nodes/1/crdb_internal.node_memory_monitors.txt...
[node 1] retrieving SQL data for crdb_internal.node_metrics...
[node 1] retrieving SQL data for crdb_internal.node_metrics: done
[node 1] retrieving SQL data for crdb_internal.node_metrics: writing output: debug/nodes/1/crdb_internal.node_metrics.txt...
Expand Down Expand Up @@ -665,6 +668,9 @@ zip
[node 2] retrieving SQL data for crdb_internal.node_inflight_trace_spans...
[node 2] retrieving SQL data for crdb_internal.node_inflight_trace_spans: done
[node 2] retrieving SQL data for crdb_internal.node_inflight_trace_spans: writing output: debug/nodes/2/crdb_internal.node_inflight_trace_spans.txt...
[node 2] retrieving SQL data for crdb_internal.node_memory_monitors...
[node 2] retrieving SQL data for crdb_internal.node_memory_monitors: done
[node 2] retrieving SQL data for crdb_internal.node_memory_monitors: writing output: debug/nodes/2/crdb_internal.node_memory_monitors.txt...
[node 2] retrieving SQL data for crdb_internal.node_metrics...
[node 2] retrieving SQL data for crdb_internal.node_metrics: done
[node 2] retrieving SQL data for crdb_internal.node_metrics: writing output: debug/nodes/2/crdb_internal.node_metrics.txt...
Expand Down Expand Up @@ -1011,6 +1017,9 @@ zip
[node 3] retrieving SQL data for crdb_internal.node_inflight_trace_spans...
[node 3] retrieving SQL data for crdb_internal.node_inflight_trace_spans: done
[node 3] retrieving SQL data for crdb_internal.node_inflight_trace_spans: writing output: debug/nodes/3/crdb_internal.node_inflight_trace_spans.txt...
[node 3] retrieving SQL data for crdb_internal.node_memory_monitors...
[node 3] retrieving SQL data for crdb_internal.node_memory_monitors: done
[node 3] retrieving SQL data for crdb_internal.node_memory_monitors: writing output: debug/nodes/3/crdb_internal.node_memory_monitors.txt...
[node 3] retrieving SQL data for crdb_internal.node_metrics...
[node 3] retrieving SQL data for crdb_internal.node_metrics: done
[node 3] retrieving SQL data for crdb_internal.node_metrics: writing output: debug/nodes/3/crdb_internal.node_metrics.txt...
Expand Down
11 changes: 11 additions & 0 deletions pkg/cli/zip_table_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,17 @@ var zipInternalTablesPerNode = DebugZipTableRegistry{
) SELECT trace_id, parent_span_id, span_id, goroutine_id, finished, start_time, duration, operation, payload_type
FROM spans, LATERAL crdb_internal.payloads_for_span(span_id)`,
},
"crdb_internal.node_memory_monitors": {
nonSensitiveCols: NonSensitiveColumns{
"level",
"name",
"id",
"parent_id",
"used",
"reserved_used",
"reserved_reserved",
},
},
"crdb_internal.node_metrics": {
nonSensitiveCols: NonSensitiveColumns{
"store_id",
Expand Down
49 changes: 30 additions & 19 deletions pkg/kv/kvserver/batcheval/cmd_end_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ func IsEndTxnTriggeringRetryError(
}

const lockResolutionBatchSize = 500
const lockResolutionBatchByteSize = 4 << 20 // 4 MB.

// resolveLocalLocks synchronously resolves any locks that are local to this
// range in the same batch and returns those lock spans. The remainder are
Expand All @@ -541,17 +542,19 @@ func resolveLocalLocks(
evalCtx EvalContext,
) (resolvedLocks []roachpb.LockUpdate, externalLocks []roachpb.Span, _ error) {
var resolveAllowance int64 = lockResolutionBatchSize
var targetBytes int64 = lockResolutionBatchByteSize
if args.InternalCommitTrigger != nil {
// If this is a system transaction (such as a split or merge), don't
// enforce the resolve allowance. These transactions rely on having
// their locks resolved synchronously.
resolveAllowance = 0
targetBytes = 0
}
return resolveLocalLocksWithPagination(ctx, desc, readWriter, ms, args, txn, evalCtx, resolveAllowance)
return resolveLocalLocksWithPagination(ctx, desc, readWriter, ms, args, txn, evalCtx, resolveAllowance, targetBytes)
}

// resolveLocalLocksWithPagination is resolveLocalLocks but with a max key
// limit.
// resolveLocalLocksWithPagination is resolveLocalLocks but with a max key and
// target bytes limit.
func resolveLocalLocksWithPagination(
ctx context.Context,
desc *roachpb.RangeDescriptor,
Expand All @@ -561,6 +564,7 @@ func resolveLocalLocksWithPagination(
txn *roachpb.Transaction,
evalCtx EvalContext,
maxKeys int64,
targetBytes int64,
) (resolvedLocks []roachpb.LockUpdate, externalLocks []roachpb.Span, _ error) {
if mergeTrigger := args.InternalCommitTrigger.GetMergeTrigger(); mergeTrigger != nil {
// If this is a merge, then use the post-merge descriptor to determine
Expand Down Expand Up @@ -592,26 +596,33 @@ func resolveLocalLocksWithPagination(
//
// Note that the underlying pebbleIterator will still be reused
// since readWriter is a pebbleBatch in the typical case.
ok, _, _, err := storage.MVCCResolveWriteIntent(ctx, readWriter, ms, update,
storage.MVCCResolveWriteIntentOptions{})
ok, numBytes, resumeSpan, err := storage.MVCCResolveWriteIntent(ctx, readWriter, ms, update,
storage.MVCCResolveWriteIntentOptions{TargetBytes: targetBytes})
if err != nil {
return 0, 0, 0, errors.Wrapf(err, "resolving write intent at %s on end transaction [%s]", span, txn.Status)
}
if ok {
numKeys = 1
}
resolvedLocks = append(resolvedLocks, update)
// If requested, replace point tombstones with range tombstones.
if ok && evalCtx.EvalKnobs().UseRangeTombstonesForPointDeletes {
if err := storage.ReplacePointTombstonesWithRangeTombstones(
ctx, spanset.DisableReadWriterAssertions(readWriter),
ms, update.Key, update.EndKey); err != nil {
return 0, 0, 0, errors.Wrapf(err,
"replacing point tombstones with range tombstones for write intent at %s on end transaction [%s]",
span, txn.Status)
if resumeSpan != nil {
externalLocks = append(externalLocks, *resumeSpan)
resumeReason = kvpb.RESUME_BYTE_LIMIT
} else {
// !ok && resumeSpan == nil is a valid condition that means
// that no intent was found.
resolvedLocks = append(resolvedLocks, update)
// If requested, replace point tombstones with range tombstones.
if ok && evalCtx.EvalKnobs().UseRangeTombstonesForPointDeletes {
if err := storage.ReplacePointTombstonesWithRangeTombstones(
ctx, spanset.DisableReadWriterAssertions(readWriter),
ms, update.Key, update.EndKey); err != nil {
return 0, 0, 0, errors.Wrapf(err,
"replacing point tombstones with range tombstones for write intent at %s on end transaction [%s]",
span, txn.Status)
}
}
}
return numKeys, 0, 0, nil
return numKeys, numBytes, resumeReason, nil
}
// For update ranges, cut into parts inside and outside our key
// range. Resolve locally inside, delegate the rest. In particular,
Expand All @@ -620,8 +631,8 @@ func resolveLocalLocksWithPagination(
externalLocks = append(externalLocks, outSpans...)
if inSpan != nil {
update.Span = *inSpan
numKeys, _, resumeSpan, resumeReason, err := storage.MVCCResolveWriteIntentRange(ctx, readWriter, ms, update,
storage.MVCCResolveWriteIntentRangeOptions{MaxKeys: maxKeys})
numKeys, numBytes, resumeSpan, resumeReason, err := storage.MVCCResolveWriteIntentRange(ctx, readWriter, ms, update,
storage.MVCCResolveWriteIntentRangeOptions{MaxKeys: maxKeys, TargetBytes: targetBytes})
if err != nil {
return 0, 0, 0, errors.Wrapf(err, "resolving write intent range at %s on end transaction [%s]", span, txn.Status)
}
Expand All @@ -643,12 +654,12 @@ func resolveLocalLocksWithPagination(
span, txn.Status)
}
}
return numKeys, 0, resumeReason, nil
return numKeys, numBytes, resumeReason, nil
}
return 0, 0, 0, nil
}

numKeys, _, _, err := storage.MVCCPaginate(ctx, maxKeys, 0 /* targetBytes */, false /* allowEmpty */, f)
numKeys, _, _, err := storage.MVCCPaginate(ctx, maxKeys, targetBytes, false /* allowEmpty */, f)
if err != nil {
return nil, nil, err
}
Expand Down
Loading

0 comments on commit c3348b0

Please sign in to comment.