YSQL: Add attributes (jsonb) to yb_tablet_metadata#30294
YSQL: Add attributes (jsonb) to yb_tablet_metadata#30294keisku wants to merge 7 commits intoyugabyte:masterfrom
attributes (jsonb) to yb_tablet_metadata#30294Conversation
✅ Deploy Preview for infallible-bardeen-164bc9 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
5822cce to
0f7c9c3
Compare
2acbff4 to
b463c61
Compare
jasonyb
left a comment
There was a problem hiding this comment.
docs/content/stable/explore/observability/yb-tablet-metadata.md:
diff --git a/docs/content/stable/explore/observability/yb-tablet-metadata.md b/docs/content/stable/explore/observability/yb-tablet-metadata.md
index 112465c01b..9963e1a468 100644
--- a/docs/content/stable/explore/observability/yb-tablet-metadata.md
+++ b/docs/content/stable/explore/observability/yb-tablet-metadata.md
@@ -37,6 +37,8 @@ The following table describes the columns of the `yb_tablet_metadata` view.
| end_hash_code | int | Ending hash code (exclusive) for the tablet. (NULL for range-sharded tables.) |
| leader | text | IP address, port of the leader node for the tablet. |
| replicas | text[] | A list of replica IP addresses and port (includes leader) associated with the tablet. |
+| active_ssts_size | bigint[] | Per-replica SST files size in bytes, in the same order as replicas. |
+| wals_size | bigint[] | Per-replica WAL files size in bytes, in the same order as replicas. |
## Examples
yb.port.rules.out
diff --git a/src/postgres/src/test/regress/expected/yb.orig.tablet_metadata.out b/src/postgres/src/test/regress/expected/yb.orig.tablet_metadata.out
index b6981e2f4f..29f230dc80 100644
--- a/src/postgres/src/test/regress/expected/yb.orig.tablet_metadata.out
+++ b/src/postgres/src/test/regress/expected/yb.orig.tablet_metadata.out
@@ -15,6 +15,21 @@ ORDER BY start_hash_code NULLS FIRST;
test_table_1 | yugabyte | 32768 | 65536
(3 rows)
+-- Test that active_ssts_size and wals_size columns are present and are arrays
+SELECT
+ relname,
+ pg_typeof(active_ssts_size) AS sst_type,
+ pg_typeof(wals_size) AS wal_type,
+ array_length(active_ssts_size, 1) = array_length(replicas, 1) AS sizes_match_replicas
+FROM yb_tablet_metadata
+WHERE relname = 'test_table_1'
+ORDER BY start_hash_code NULLS FIRST
+LIMIT 1;
+ relname | sst_type | wal_type | sizes_match_replicas
+--------------+----------+----------+----------------------
+ test_table_1 | bigint[] | bigint[] | t
+(1 row)
+
-- Test that we are able to join with yb_servers()
SELECT
ytm.relname,
|
@keisku Instead of adding two fields, we would want a single json column for all the tablet attributes. This will ensure that the other tablet properties could be added in future without modifying the schema of the table cc: @IshanChhangani @GauravSingh-yb @jasonyb |
|
Sorry there are so many things to review. I appreciate your help.
I am working on this. |
{active_ssts,wals}_size to yb_tablet_metadataattributes (jsonb) to yb_tablet_metadata
|
I've addressed review points and updated the PR title/description accordingly 👍 |
|
@jasonyb any chance you could take a look at this PR again? |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Free Tier Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable autofix in the Cursor dashboard.
src/yb/yql/pgwrapper/ysql_migrations/V101__29665__yb_tablet_metadata_sizes.sql
Show resolved
Hide resolved
jasonyb
left a comment
There was a problem hiding this comment.
sorry for the wait. I was OOO
| qsort_arg(sort_idxs, nreplicas, sizeof(int), | ||
| replica_index_cmp, tablet->replicas); |
There was a problem hiding this comment.
given jsonb does not preserve ordering, you can leave the replicas code untouched and do the attributes code separately
src/yb/yql/pgwrapper/ysql_migrations/V101__29665__yb_tablet_metadata_sizes.sql
Show resolved
Hide resolved
|
@jasonyb Updated the code to address your review points! |
| /* | ||
| * Build JSONB attributes before sorting replicas, because the | ||
| * parallel size arrays must stay aligned with the replica order. | ||
| * JSONB does not preserve key order so sorting is unnecessary. |
There was a problem hiding this comment.
What is "parallel size arrays"? I don't see a reason why you need to handle attributes before replicas. The sort is on a local list variable. If there is no strong reason, the order should be the expected values[8] then [9]
There was a problem hiding this comment.
Sorry for the confusion. I missed this in my self-review. Fixed order to values[8], values[9] and removed the misleading comment.
Rename active_ssts_size/wals_size to active_sst_sizes/wal_sizes across proto, pggate, catalog manager, system views, and migration. Use uint64 datums instead of CString to match the bigint[] column type. Make the migration resilient to OID changes by looking up yb_get_tablet_metadata by name instead of hardcoded OID. Move size column validation from C++ mini-test to pg_regress, covering array alignment, non-negative sizes, and replica-tserver correspondence.
jasonyb
left a comment
There was a problem hiding this comment.
Please read src/postgres/src/tools/pgindent/README and run yb_pgindent and only keep changes relevant to your changes.
fix test failure:
./yb_build.sh fastdebug --java-test 'org.yb.pgsql.TestPgRegressRules#testPgRegressRules' --gcc12
diff -U3 ${TEST_TMPDIR}/pgregress_output/yb_pg_rules_schedule/expected/yb.port.rules.out ${TEST_TMPDIR}/pgregress_output/yb_pg_rules_schedule/results/yb.port.rules.out
--- ${TEST_TMPDIR}/pgregress_output/yb_pg_rules_schedule/expected/yb.port.rules.out 2026-03-12 23:45:22.191187135 +0000
+++ ${TEST_TMPDIR}/pgregress_output/yb_pg_rules_schedule/results/yb.port.rules.out 2026-03-12 23:45:22.135187232 +0000
@@ -2786,8 +2786,9 @@
t.start_hash_code,
t.end_hash_code,
t.leader,
- t.replicas
- FROM ((yb_get_tablet_metadata() t(tablet_id, object_uuid, namespace, object_name, type, start_hash_code, end_hash_code, leader, replicas)
+ t.replicas,
+ t.attributes
+ FROM ((yb_get_tablet_metadata() t(tablet_id, object_uuid, namespace, object_name, type, start_hash_code, end_hash_code, leader, replicas, attributes)
LEFT JOIN pg_class c ON ((c.relname = t.object_name)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (((t.namespace = 'system'::text) AND (t.object_name = 'transactions'::text)) OR ((t.type = 'YSQL'::text) AND (n.nspname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name]))));
Also saw many pgvector test failures such as the following, but it is possibly unrelated to your change:
./yb_build.sh fastdebug --cxx-test pgwrapper_pg_vector_index-test --gtest_filter 'PgVectorIndexTest.BootstrapFlushedVectorIndexes/ColocatedPackingV2' --gcc12
I0312 23:42:53.120318 9706 pg_vector_index-test.cc:454] RowsMatch: Query: SELECT * FROM test AS t ORDER BY embedding <-> '[0.0, 0.0, 0.0]' LIMIT 5
I0312 23:42:53.209281 9706 pg_vector_index-test.cc:456] RowsMatch: Result: []
I0312 23:42:53.209326 9706 pg_vector_index-test.cc:457] RowsMatch: Expected: [1, [1, 2, 3], 2, [2, 4, 6], 3, [3, 6, 9], 4, [4, 8, 12], 5, [5, 10, 15]]
I0312 23:42:53.209331 9706 pg_vector_index-test.cc:460] RowsMatch: Wrong number of results: 0, while 5 expected
../../src/yb/yql/pgwrapper/pg_vector_index-test.cc:478: Failure
Value of: RowsMatch(conn, filter, expected, limit)
Actual: false
Expected: true
| jb_key.val.string.len = 16; | ||
| pushJsonbValue(&jb_state, WJB_KEY, &jb_key); | ||
| jb_val.type = jbvNumeric; | ||
| jb_val.val.numeric = DatumGetNumeric( |
There was a problem hiding this comment.
Error (S&RX) bad_opening_paren
There should be no linebreak after (
| jb_key.val.string.len = 9; | ||
| pushJsonbValue(&jb_state, WJB_KEY, &jb_key); | ||
| jb_val.type = jbvNumeric; | ||
| jb_val.val.numeric = DatumGetNumeric( |
There was a problem hiding this comment.
Error (S&RX) bad_opening_paren
There should be no linebreak after (
| #endif | ||
| #include "storage/procarray.h" | ||
| #include "tcop/utility.h" | ||
| #include "utils/array.h" |
There was a problem hiding this comment.
| #include "utils/array.h" |
Closes #29665
Testing
Upgrade ysql.
Able to see
active_ssts_sizeandwals_sizein theyb_tablet_metadata.Run this right after creating a cluster
Create a test table
./bin/ysqlsh -c "CREATE TABLE test_sizes (k INT PRIMARY KEY, v TEXT);" CREATE TABLESee values in
attributes.Checked the UI.
Insert 29000 rows.
active_ssts_sizeandwals_sizein theattributesincreased.Checked the UI.
Note
Medium Risk
Changes the
yb_get_tablet_metadatasystem function/view signature and adds a new migration, which could impact clients or tests that depend on the previous column set. Also extends master-to-pggate protobuf plumbing for per-replica size metrics, so mismatched versions or edge cases around missing metrics could surface.Overview
Adds an
attributes(jsonb) column toyb_tablet_metadata(and underlyingyb_get_tablet_metadata()record) that returns per-replicaactive_sst_sizesandwal_sizeskeyed by replica address.Plumbs replica size data from master tablet metadata through protobuf (
TabletStatusPB), pggate descriptors, and Postgres JSONB construction, and includes a new YSQL migration plus updated regression tests and docs/examples to reflect the new column.Written by Cursor Bugbot for commit 79d4847. This will update automatically on new commits. Configure here.