Skip to content

Commit bdaae64

Browse files
craig[bot]Rahul Aggarwalrickystewart
committed
106527: builtins: Added `ApproximateSpanBytes` column r=RahulAggarwal1016 a=RahulAggarwal1016 Added a column (`ApproximateSpanBytes`) to the `crdb_internal.sstable_metrics()` builtin generator function to display the number of bytes that the given user key span overlaps with. Informs: cockroachdb#94659 Release note: None 106600: dev: use `bazel test` to run acceptance tests, not `bazel run` r=rail a=rickystewart This is probably some oversight or historical artifact, but `bazel test` is conceptually correct and what we should be using in CI. Epic: CRDB-17171 Release note: None Co-authored-by: Rahul Aggarwal <[email protected]> Co-authored-by: Ricky Stewart <[email protected]>
3 parents 2045f0b + feb9988 + c421c85 commit bdaae64

File tree

8 files changed

+17
-11
lines changed

8 files changed

+17
-11
lines changed

dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fi
88
set -euo pipefail
99

1010
# Bump this counter to force rebuilding `dev` on all machines.
11-
DEV_VERSION=77
11+
DEV_VERSION=78
1212

1313
THIS_DIR=$(cd "$(dirname "$0")" && pwd)
1414
BINARY_DIR=$THIS_DIR/bin/dev-versions

docs/generated/sql/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3308,7 +3308,7 @@ table. Returns an error if validation fails.</p>
33083308
</span></td><td>Volatile</td></tr>
33093309
<tr><td><a name="crdb_internal.set_vmodule"></a><code>crdb_internal.set_vmodule(vmodule_string: <a href="string.html">string</a>) &rarr; <a href="int.html">int</a></code></td><td><span class="funcdesc"><p>Set the equivalent of the <code>--vmodule</code> flag on the gateway node processing this request; it affords control over the logging verbosity of different files. Example syntax: <code>crdb_internal.set_vmodule('recordio=2,file=1,gfs*=3')</code>. Reset with: <code>crdb_internal.set_vmodule('')</code>. Raising the verbosity can severely affect performance.</p>
33103310
</span></td><td>Volatile</td></tr>
3311-
<tr><td><a name="crdb_internal.sstable_metrics"></a><code>crdb_internal.sstable_metrics(node_id: <a href="int.html">int</a>, store_id: <a href="int.html">int</a>, start_key: <a href="bytes.html">bytes</a>, end_key: <a href="bytes.html">bytes</a>) &rarr; tuple{int AS node_id,, int AS store_id, int AS level, int AS file_num, jsonb AS metrics}</code></td><td><span class="funcdesc"><p>Returns statistics for the sstables containing keys in the range start_key and end_key for the provided node id.</p>
3311+
<tr><td><a name="crdb_internal.sstable_metrics"></a><code>crdb_internal.sstable_metrics(node_id: <a href="int.html">int</a>, store_id: <a href="int.html">int</a>, start_key: <a href="bytes.html">bytes</a>, end_key: <a href="bytes.html">bytes</a>) &rarr; tuple{int AS node_id,, int AS store_id, int AS level, int AS file_num, bytes AS approximate_span_<a href="bytes.html">bytes</a>, jsonb AS metrics}</code></td><td><span class="funcdesc"><p>Returns statistics for the sstables containing keys in the range start_key and end_key for the provided node id.</p>
33123312
</span></td><td>Stable</td></tr>
33133313
<tr><td><a name="crdb_internal.table_span"></a><code>crdb_internal.table_span(table_id: <a href="int.html">int</a>) &rarr; <a href="bytes.html">bytes</a>[]</code></td><td><span class="funcdesc"><p>This function returns the span that contains the keys for the given table.</p>
33143314
</span></td><td>Leakproof</td></tr>

pkg/cmd/dev/acceptance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (d *dev) acceptance(cmd *cobra.Command, commandLine []string) error {
7676
cockroachBin := filepath.Join(workspace, "artifacts", "cockroach-short")
7777

7878
var args []string
79-
args = append(args, "run", "//pkg/acceptance:acceptance_test", "--config=test")
79+
args = append(args, "test", "//pkg/acceptance:acceptance_test")
8080
if numCPUs != 0 {
8181
args = append(args, fmt.Sprintf("--local_cpu_resources=%d", numCPUs))
8282
}

pkg/sql/sem/builtins/fixed_oids.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ var builtinOidsArray = []string{
24242424
2451: `st_asmvtgeom(geometry: geometry, bbox: box2d) -> geometry`,
24252425
2452: `crdb_internal.repaired_descriptor(descriptor: bytes, valid_descriptor_ids: int[], valid_job_ids: int[]) -> bytes`,
24262426
2453: `crdb_internal.reset_activity_tables() -> bool`,
2427-
2454: `crdb_internal.sstable_metrics(node_id: int, store_id: int, start_key: bytes, end_key: bytes) -> tuple{int AS node_id,, int AS store_id, int AS level, int AS file_num, jsonb AS metrics}`,
2427+
2454: `crdb_internal.sstable_metrics(node_id: int, store_id: int, start_key: bytes, end_key: bytes) -> tuple{int AS node_id,, int AS store_id, int AS level, int AS file_num, bytes AS approximate_span_bytes, jsonb AS metrics}`,
24282428
2455: `crdb_internal.repair_catalog_corruption(descriptor_id: int, corruption: string) -> bool`,
24292429
2456: `crdb_internal.merge_aggregated_stmt_metadata(input: jsonb[]) -> jsonb`,
24302430
}

pkg/sql/sem/builtins/generator_builtins.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,8 +3125,8 @@ func (tssi *tableSpanStatsIterator) ResolvedType() *types.T {
31253125
}
31263126

31273127
var tableMetricsGeneratorType = types.MakeLabeledTuple(
3128-
[]*types.T{types.Int, types.Int, types.Int, types.Int, types.Json},
3129-
[]string{"node_id,", "store_id", "level", "file_num", "metrics"},
3128+
[]*types.T{types.Int, types.Int, types.Int, types.Int, types.Bytes, types.Json},
3129+
[]string{"node_id,", "store_id", "level", "file_num", "approximate_span_bytes", "metrics"},
31303130
)
31313131

31323132
// tableMetricsIterator implements tree.ValueGenerator; it returns a set of
@@ -3186,6 +3186,7 @@ func (tmi *tableMetricsIterator) Values() (tree.Datums, error) {
31863186
tree.NewDInt(tree.DInt(tmi.storeID)),
31873187
tree.NewDInt(tree.DInt(metricsInfo.Level)),
31883188
tree.NewDInt(tree.DInt(metricsInfo.TableID)),
3189+
tree.NewDBytes(tree.DBytes(metricsInfo.ApproximateSpanBytes)),
31893190
metricsJson,
31903191
}, nil
31913192
}

pkg/sql/sem/builtins/generator_builtins_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func TestGetSSTableMetricsMultiNode(t *testing.T) {
9090
var storeID int
9191
var level int
9292
var fileNum int
93+
var approximateSpanBytes []byte
9394
var metrics []byte
9495

9596
for idx, id := range tc.NodeIDs() {
@@ -121,7 +122,7 @@ func TestGetSSTableMetricsMultiNode(t *testing.T) {
121122
nodeIDArg, storeIDArg))
122123

123124
for rows.Next() {
124-
require.NoError(t, rows.Scan(&nodeID, &storeID, &level, &fileNum, &metrics))
125+
require.NoError(t, rows.Scan(&nodeID, &storeID, &level, &fileNum, &approximateSpanBytes, &metrics))
125126
require.NoError(t, json.Unmarshal(metrics, &enginepb.SSTableMetricsInfo{}))
126127
require.Equal(t, nodeID, nodeIDArg)
127128
require.Equal(t, storeID, storeIDArg)
@@ -137,7 +138,7 @@ func TestGetSSTableMetricsMultiNode(t *testing.T) {
137138
nodeIDArg, storeIDArg))
138139

139140
for rows.Next() {
140-
require.NoError(t, rows.Scan(&nodeID, &storeID, &level, &fileNum, &metrics))
141+
require.NoError(t, rows.Scan(&nodeID, &storeID, &level, &fileNum, &approximateSpanBytes, &metrics))
141142
require.NoError(t, json.Unmarshal(metrics, &enginepb.SSTableMetricsInfo{}))
142143
require.Equal(t, nodeID, nodeIDArg)
143144
require.Equal(t, storeID, storeIDArg)
@@ -183,10 +184,11 @@ func TestGetSSTableMetricsSingleNode(t *testing.T) {
183184
var storeID int
184185
var level int
185186
var fileNum int
187+
var approximateSpanBytes []byte
186188
var metrics []byte
187189

188190
for rows.Next() {
189-
require.NoError(t, rows.Scan(&nodeID, &storeID, &level, &fileNum, &metrics))
191+
require.NoError(t, rows.Scan(&nodeID, &storeID, &level, &fileNum, &approximateSpanBytes, &metrics))
190192
require.NoError(t, json.Unmarshal(metrics, &enginepb.SSTableMetricsInfo{}))
191193
require.Equal(t, nodeID, nodeIDArg)
192194
require.Equal(t, storeID, storeIDArg)

pkg/storage/enginepb/rocksdb.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ message SSTableMetricsInfo {
2222
uint64 table_id = 2 [(gogoproto.customname) = "TableID"];
2323
// table_info_json contains sstable properties, encoded as JSON
2424
bytes table_info_json = 3 [(gogoproto.customname) = "TableInfoJSON"];
25+
// approximate_span_bytes represents the total number of bytes that overlap the given keyspan
26+
bytes approximate_span_bytes = 4 [(gogoproto.customname) = "ApproximateSpanBytes"];
2527
}
2628

2729
// SSTUserProperties contains the user-added properties of a single sstable.

pkg/storage/pebble.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ func (p *Pebble) PreIngestDelay(ctx context.Context) {
20102010

20112011
// GetTableMetrics implements the Engine interface.
20122012
func (p *Pebble) GetTableMetrics(start, end roachpb.Key) ([]enginepb.SSTableMetricsInfo, error) {
2013-
tableInfo, err := p.db.SSTables(pebble.WithKeyRangeFilter(start, end))
2013+
tableInfo, err := p.db.SSTables(pebble.WithKeyRangeFilter(start, end), pebble.WithProperties(), pebble.WithApproximateSpanBytes())
20142014

20152015
if err != nil {
20162016
return []enginepb.SSTableMetricsInfo{}, err
@@ -2032,7 +2032,8 @@ func (p *Pebble) GetTableMetrics(start, end roachpb.Key) ([]enginepb.SSTableMetr
20322032
}
20332033

20342034
tableID := sstableInfo.TableInfo.FileNum
2035-
metricsInfo = append(metricsInfo, enginepb.SSTableMetricsInfo{TableID: uint64(tableID), Level: int32(level), TableInfoJSON: marshalTableInfo})
2035+
approximateSpanBytes := sstableInfo.Properties.UserProperties["approximate-span-bytes"]
2036+
metricsInfo = append(metricsInfo, enginepb.SSTableMetricsInfo{TableID: uint64(tableID), Level: int32(level), ApproximateSpanBytes: []byte(approximateSpanBytes), TableInfoJSON: marshalTableInfo})
20362037
}
20372038
}
20382039
return metricsInfo, nil

0 commit comments

Comments
 (0)