Skip to content

Commit

Permalink
builtins: crdb_internal.sstable_metrics fixes
Browse files Browse the repository at this point in the history
This pr has the following fixes for the builtin `crdb_internal.sstable_metrics`

1. Remove the ',' from `node_id`
2. Change `approximate_span_bytes` to be a `uint64` instead of `[]byte`
3. Convert the `MVCCTimeInterval` user property to be human readable.

Informs: #102604
Release-note: None
  • Loading branch information
raggar committed Jul 21, 2023
1 parent e0235d0 commit ceb5cd5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/generated/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3310,7 +3310,7 @@ table. Returns an error if validation fails.</p>
</span></td><td>Volatile</td></tr>
<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>
</span></td><td>Volatile</td></tr>
<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>
<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, int 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>
</span></td><td>Stable</td></tr>
<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>
</span></td><td>Leakproof</td></tr>
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sem/builtins/fixed_oids.go
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,7 @@ var builtinOidsArray = []string{
2451: `st_asmvtgeom(geometry: geometry, bbox: box2d) -> geometry`,
2452: `crdb_internal.repaired_descriptor(descriptor: bytes, valid_descriptor_ids: int[], valid_job_ids: int[]) -> bytes`,
2453: `crdb_internal.reset_activity_tables() -> bool`,
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}`,
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, int AS approximate_span_bytes, jsonb AS metrics}`,
2455: `crdb_internal.repair_catalog_corruption(descriptor_id: int, corruption: string) -> bool`,
2456: `crdb_internal.merge_aggregated_stmt_metadata(input: jsonb[]) -> jsonb`,
2457: `crdb_internal.request_job_execution_details(jobID: int) -> bool`,
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/sem/builtins/generator_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -3125,8 +3125,8 @@ func (tssi *tableSpanStatsIterator) ResolvedType() *types.T {
}

var tableMetricsGeneratorType = types.MakeLabeledTuple(
[]*types.T{types.Int, types.Int, types.Int, types.Int, types.Bytes, types.Json},
[]string{"node_id,", "store_id", "level", "file_num", "approximate_span_bytes", "metrics"},
[]*types.T{types.Int, types.Int, types.Int, types.Int, types.Int, types.Json},
[]string{"node_id", "store_id", "level", "file_num", "approximate_span_bytes", "metrics"},
)

// tableMetricsIterator implements tree.ValueGenerator; it returns a set of
Expand Down Expand Up @@ -3186,7 +3186,7 @@ func (tmi *tableMetricsIterator) Values() (tree.Datums, error) {
tree.NewDInt(tree.DInt(tmi.storeID)),
tree.NewDInt(tree.DInt(metricsInfo.Level)),
tree.NewDInt(tree.DInt(metricsInfo.TableID)),
tree.NewDBytes(tree.DBytes(metricsInfo.ApproximateSpanBytes)),
tree.NewDInt(tree.DInt(metricsInfo.ApproximateSpanBytes)),
metricsJson,
}, nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/sql/sem/builtins/generator_builtins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestGetSSTableMetricsMultiNode(t *testing.T) {
var storeID int
var level int
var fileNum int
var approximateSpanBytes []byte
var approximateSpanBytes uint64
var metrics []byte

for idx, id := range tc.NodeIDs() {
Expand Down Expand Up @@ -127,6 +127,7 @@ func TestGetSSTableMetricsMultiNode(t *testing.T) {
require.Equal(t, nodeID, nodeIDArg)
require.Equal(t, storeID, storeIDArg)
require.NotEqual(t, fileNum, 0)
require.NotEqual(t, approximateSpanBytes, 0)
count++
}

Expand Down Expand Up @@ -184,7 +185,7 @@ func TestGetSSTableMetricsSingleNode(t *testing.T) {
var storeID int
var level int
var fileNum int
var approximateSpanBytes []byte
var approximateSpanBytes uint64
var metrics []byte

for rows.Next() {
Expand All @@ -193,6 +194,7 @@ func TestGetSSTableMetricsSingleNode(t *testing.T) {
require.Equal(t, nodeID, nodeIDArg)
require.Equal(t, storeID, storeIDArg)
require.NotEqual(t, fileNum, 0)
require.NotEqual(t, approximateSpanBytes, 0)
count++
}
require.Equal(t, 1, count)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/enginepb/rocksdb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ message SSTableMetricsInfo {
// table_info_json contains sstable properties, encoded as JSON
bytes table_info_json = 3 [(gogoproto.customname) = "TableInfoJSON"];
// approximate_span_bytes represents the total number of bytes that overlap the given keyspan
bytes approximate_span_bytes = 4 [(gogoproto.customname) = "ApproximateSpanBytes"];
uint64 approximate_span_bytes = 4 [(gogoproto.customname) = "ApproximateSpanBytes"];
}

// SSTUserProperties contains the user-added properties of a single sstable.
Expand Down
7 changes: 5 additions & 2 deletions pkg/storage/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -2032,8 +2032,11 @@ func (p *Pebble) GetTableMetrics(start, end roachpb.Key) ([]enginepb.SSTableMetr
}

tableID := sstableInfo.TableInfo.FileNum
approximateSpanBytes := sstableInfo.Properties.UserProperties["approximate-span-bytes"]
metricsInfo = append(metricsInfo, enginepb.SSTableMetricsInfo{TableID: uint64(tableID), Level: int32(level), ApproximateSpanBytes: []byte(approximateSpanBytes), TableInfoJSON: marshalTableInfo})
approximateSpanBytes, err := strconv.ParseUint(sstableInfo.Properties.UserProperties["approximate-span-bytes"], 10, 64)
if err != nil {
return []enginepb.SSTableMetricsInfo{}, err
}
metricsInfo = append(metricsInfo, enginepb.SSTableMetricsInfo{TableID: uint64(tableID), Level: int32(level), ApproximateSpanBytes: approximateSpanBytes, TableInfoJSON: marshalTableInfo})
}
}
return metricsInfo, nil
Expand Down

0 comments on commit ceb5cd5

Please sign in to comment.