Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtins: crdb_internal.sstable_metrics fixes #107303

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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