Skip to content

Commit 4af8a54

Browse files
craig[bot]jayshrivastava
andcommitted
105577: sql: add crdb_internal.kv_protected_ts_records virtual table r=jayshrivastava a=jayshrivastava This change adds a new virtual table `crdb_internal.kv_protected_ts_records` which provides better visability into PTS records than `system.protected_ts_records`. This virtual table includes all columns from the system table and adds the following columns: - `num_ranges INT`: the number of ranges protected by the PTS record. Note this does not count ranges when the PTS record is protecting a database, cluster, or tenant. It only counts ranges protected by tables. Adding support for databases, clusters, and tenants is left as a TODO. - `decoded_meta JSON`: the decoded `meta` column from the system table. For the jobs `meta_type`, this contains the job ID. For the schedules `meta_type`, this is contains the schedule ID. - `decoded_target JSON`: the decoded `ptpb.Target` field. - `internal_meta JSON`: any additional metadata added by this table. For the jobs `meta_type`, this contains the job owner. For the schedules `meta_type`, this contains the schedule label and owner. This change also adds this table to the debug zip. Release note: None Closes: cockroachdb#104161 Epic: None Co-authored-by: Jayant Shrivastava <[email protected]>
2 parents 9cadb7c + 23f4850 commit 4af8a54

File tree

32 files changed

+1573
-740
lines changed

32 files changed

+1573
-740
lines changed

pkg/ccl/changefeedccl/changefeed_dist.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/cdceval"
1616
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/changefeedbase"
17-
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/kvfeed"
1817
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
1918
"github.com/cockroachdb/cockroach/pkg/jobs/jobsprofiler"
2019
"github.com/cockroachdb/cockroach/pkg/kv"
@@ -521,7 +520,7 @@ type distResolver struct {
521520
func (r *distResolver) getRangesForSpans(
522521
ctx context.Context, spans []roachpb.Span,
523522
) ([]roachpb.Span, error) {
524-
spans, _, err := kvfeed.AllRangeSpans(ctx, r.DistSender, spans)
523+
spans, _, err := r.DistSender.AllRangeSpans(ctx, spans)
525524
return spans, err
526525
}
527526

pkg/ccl/changefeedccl/kvfeed/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ go_library(
2424
"//pkg/settings/cluster",
2525
"//pkg/sql/covering",
2626
"//pkg/storage/enginepb",
27-
"//pkg/util",
2827
"//pkg/util/admission/admissionpb",
2928
"//pkg/util/ctxgroup",
3029
"//pkg/util/hlc",

pkg/ccl/changefeedccl/kvfeed/scanner.go

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
2626
"github.com/cockroachdb/cockroach/pkg/sql/covering"
2727
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
28-
"github.com/cockroachdb/cockroach/pkg/util"
2928
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
3029
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
3130
"github.com/cockroachdb/cockroach/pkg/util/hlc"
@@ -254,7 +253,7 @@ func (p *scanRequestScanner) exportSpan(
254253
func getRangesToProcess(
255254
ctx context.Context, ds *kvcoord.DistSender, targetSpans []roachpb.Span,
256255
) ([]roachpb.Span, int, error) {
257-
ranges, numNodes, err := AllRangeSpans(ctx, ds, targetSpans)
256+
ranges, numNodes, err := ds.AllRangeSpans(ctx, targetSpans)
258257
if err != nil {
259258
return nil, 0, err
260259
}
@@ -324,40 +323,6 @@ func slurpScanResponse(
324323
return nil
325324
}
326325

327-
// AllRangeSpans returns the list of all ranges that cover input spans along with the
328-
// nodeCountHint indicating the number of nodes that host those ranges.
329-
func AllRangeSpans(
330-
ctx context.Context, ds *kvcoord.DistSender, spans []roachpb.Span,
331-
) (_ []roachpb.Span, nodeCountHint int, _ error) {
332-
ranges := make([]roachpb.Span, 0, len(spans))
333-
334-
it := kvcoord.MakeRangeIterator(ds)
335-
var replicas util.FastIntMap
336-
337-
for i := range spans {
338-
rSpan, err := keys.SpanAddr(spans[i])
339-
if err != nil {
340-
return nil, 0, err
341-
}
342-
for it.Seek(ctx, rSpan.Key, kvcoord.Ascending); ; it.Next(ctx) {
343-
if !it.Valid() {
344-
return nil, 0, it.Error()
345-
}
346-
ranges = append(ranges, roachpb.Span{
347-
Key: it.Desc().StartKey.AsRawKey(), EndKey: it.Desc().EndKey.AsRawKey(),
348-
})
349-
for _, r := range it.Desc().InternalReplicas {
350-
replicas.Set(int(r.NodeID), 0)
351-
}
352-
if !it.NeedAnother(rSpan) {
353-
break
354-
}
355-
}
356-
}
357-
358-
return ranges, replicas.Len(), nil
359-
}
360-
361326
// maxConcurrentScanRequests returns the number of concurrent scan requests.
362327
func maxConcurrentScanRequests(numNodesHint int, sv *settings.Values) int {
363328
// If the user specified ScanRequestLimit -- use that value.

pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ crdb_internal kv_inherited_role_members table admin NULL NULL
7272
crdb_internal kv_node_liveness table admin NULL NULL
7373
crdb_internal kv_node_status table admin NULL NULL
7474
crdb_internal kv_repairable_catalog_corruptions view admin NULL NULL
75+
crdb_internal kv_protected_ts_records table admin NULL NULL
7576
crdb_internal kv_store_status table admin NULL NULL
7677
crdb_internal kv_system_privileges view admin NULL NULL
7778
crdb_internal leases table admin NULL NULL

pkg/cli/testdata/zip/partial1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ debug zip --concurrency=1 --cpu-profile-duration=0s /dev/null
2929
[cluster] retrieving SQL data for crdb_internal.jobs... writing output: debug/crdb_internal.jobs.txt... done
3030
[cluster] retrieving SQL data for crdb_internal.kv_node_liveness... writing output: debug/crdb_internal.kv_node_liveness.txt... done
3131
[cluster] retrieving SQL data for crdb_internal.kv_node_status... writing output: debug/crdb_internal.kv_node_status.txt... done
32+
[cluster] retrieving SQL data for crdb_internal.kv_protected_ts_records... writing output: debug/crdb_internal.kv_protected_ts_records.txt... done
3233
[cluster] retrieving SQL data for crdb_internal.kv_store_status... writing output: debug/crdb_internal.kv_store_status.txt... done
3334
[cluster] retrieving SQL data for crdb_internal.kv_system_privileges... writing output: debug/crdb_internal.kv_system_privileges.txt... done
3435
[cluster] retrieving SQL data for crdb_internal.partitions... writing output: debug/crdb_internal.partitions.txt... done

pkg/cli/testdata/zip/partial1_excluded

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ debug zip /dev/null --concurrency=1 --exclude-nodes=2 --cpu-profile-duration=0
2929
[cluster] retrieving SQL data for crdb_internal.jobs... writing output: debug/crdb_internal.jobs.txt... done
3030
[cluster] retrieving SQL data for crdb_internal.kv_node_liveness... writing output: debug/crdb_internal.kv_node_liveness.txt... done
3131
[cluster] retrieving SQL data for crdb_internal.kv_node_status... writing output: debug/crdb_internal.kv_node_status.txt... done
32+
[cluster] retrieving SQL data for crdb_internal.kv_protected_ts_records... writing output: debug/crdb_internal.kv_protected_ts_records.txt... done
3233
[cluster] retrieving SQL data for crdb_internal.kv_store_status... writing output: debug/crdb_internal.kv_store_status.txt... done
3334
[cluster] retrieving SQL data for crdb_internal.kv_system_privileges... writing output: debug/crdb_internal.kv_system_privileges.txt... done
3435
[cluster] retrieving SQL data for crdb_internal.partitions... writing output: debug/crdb_internal.partitions.txt... done

pkg/cli/testdata/zip/partial2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ debug zip --concurrency=1 --cpu-profile-duration=0 /dev/null
2929
[cluster] retrieving SQL data for crdb_internal.jobs... writing output: debug/crdb_internal.jobs.txt... done
3030
[cluster] retrieving SQL data for crdb_internal.kv_node_liveness... writing output: debug/crdb_internal.kv_node_liveness.txt... done
3131
[cluster] retrieving SQL data for crdb_internal.kv_node_status... writing output: debug/crdb_internal.kv_node_status.txt... done
32+
[cluster] retrieving SQL data for crdb_internal.kv_protected_ts_records... writing output: debug/crdb_internal.kv_protected_ts_records.txt... done
3233
[cluster] retrieving SQL data for crdb_internal.kv_store_status... writing output: debug/crdb_internal.kv_store_status.txt... done
3334
[cluster] retrieving SQL data for crdb_internal.kv_system_privileges... writing output: debug/crdb_internal.kv_system_privileges.txt... done
3435
[cluster] retrieving SQL data for crdb_internal.partitions... writing output: debug/crdb_internal.partitions.txt... done

pkg/cli/testdata/zip/testzip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s /dev/null
2929
[cluster] retrieving SQL data for crdb_internal.jobs... writing output: debug/crdb_internal.jobs.txt... done
3030
[cluster] retrieving SQL data for crdb_internal.kv_node_liveness... writing output: debug/crdb_internal.kv_node_liveness.txt... done
3131
[cluster] retrieving SQL data for crdb_internal.kv_node_status... writing output: debug/crdb_internal.kv_node_status.txt... done
32+
[cluster] retrieving SQL data for crdb_internal.kv_protected_ts_records... writing output: debug/crdb_internal.kv_protected_ts_records.txt... done
3233
[cluster] retrieving SQL data for crdb_internal.kv_store_status... writing output: debug/crdb_internal.kv_store_status.txt... done
3334
[cluster] retrieving SQL data for crdb_internal.kv_system_privileges... writing output: debug/crdb_internal.kv_system_privileges.txt... done
3435
[cluster] retrieving SQL data for crdb_internal.partitions... writing output: debug/crdb_internal.partitions.txt... done

pkg/cli/testdata/zip/testzip_concurrent

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ zip
101101
[cluster] retrieving SQL data for crdb_internal.kv_node_status...
102102
[cluster] retrieving SQL data for crdb_internal.kv_node_status: done
103103
[cluster] retrieving SQL data for crdb_internal.kv_node_status: writing output: debug/crdb_internal.kv_node_status.txt...
104+
[cluster] retrieving SQL data for crdb_internal.kv_protected_ts_records...
105+
[cluster] retrieving SQL data for crdb_internal.kv_protected_ts_records: done
106+
[cluster] retrieving SQL data for crdb_internal.kv_protected_ts_records: writing output: debug/crdb_internal.kv_protected_ts_records.txt...
104107
[cluster] retrieving SQL data for crdb_internal.kv_store_status...
105108
[cluster] retrieving SQL data for crdb_internal.kv_store_status: done
106109
[cluster] retrieving SQL data for crdb_internal.kv_store_status: writing output: debug/crdb_internal.kv_store_status.txt...

pkg/cli/testdata/zip/testzip_external_process_virtualization

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ debug zip --concurrency=1 --cpu-profile-duration=1s /dev/null
3535
[cluster] retrieving SQL data for crdb_internal.kv_node_status... writing output: debug/crdb_internal.kv_node_status.txt...
3636
[cluster] retrieving SQL data for crdb_internal.kv_node_status: last request failed: ERROR: unimplemented: operation is unsupported in multi-tenancy mode (SQLSTATE 0A000)
3737
[cluster] retrieving SQL data for crdb_internal.kv_node_status: creating error output: debug/crdb_internal.kv_node_status.txt.err.txt... done
38+
[cluster] retrieving SQL data for crdb_internal.kv_protected_ts_records... writing output: debug/crdb_internal.kv_protected_ts_records.txt... done
3839
[cluster] retrieving SQL data for crdb_internal.kv_store_status... writing output: debug/crdb_internal.kv_store_status.txt...
3940
[cluster] retrieving SQL data for crdb_internal.kv_store_status: last request failed: ERROR: unimplemented: operation is unsupported in multi-tenancy mode (SQLSTATE 0A000)
4041
[cluster] retrieving SQL data for crdb_internal.kv_store_status: creating error output: debug/crdb_internal.kv_store_status.txt.err.txt... done

0 commit comments

Comments
 (0)