Skip to content

Commit 74b9d90

Browse files
committed
Rename and fix tablet metadata size columns
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.
1 parent b463c61 commit 74b9d90

File tree

12 files changed

+114
-95
lines changed

12 files changed

+114
-95
lines changed

docs/content/stable/explore/observability/yb-tablet-metadata.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ The following table describes the columns of the `yb_tablet_metadata` view.
3737
| end_hash_code | int | Ending hash code (exclusive) for the tablet. (NULL for range-sharded tables.) |
3838
| leader | text | IP address, port of the leader node for the tablet. |
3939
| replicas | text[] | A list of replica IP addresses and port (includes leader) associated with the tablet. |
40+
| active_ssts_size | bigint[] | Per-replica SST files size in bytes, in the same order as replicas. |
41+
| wals_size | bigint[] | Per-replica WAL files size in bytes, in the same order as replicas. |
4042

4143
## Examples
4244

@@ -268,4 +270,3 @@ SELECT
268270
| 99ed7472ccde4af787cb0bcfd4fd90bd | yugabyte | test_table | 0 | 32768 | RocksDB_NewIterator | TServer | DiskIO | 1 |
269271
+----------------------------------+----------+------------------+-----------------+---------------+------------------------------------+----------------------+-----------------+-------+
270272
```
271-

src/postgres/src/backend/catalog/yb_system_views.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ CREATE VIEW yb_tablet_metadata AS
6868
t.end_hash_code,
6969
t.leader,
7070
t.replicas,
71-
t.active_ssts_size,
72-
t.wals_size
71+
t.active_sst_sizes,
72+
t.wal_sizes
7373
FROM
7474
yb_get_tablet_metadata() t
7575
LEFT JOIN

src/postgres/src/backend/utils/misc/pg_yb_utils.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8419,8 +8419,8 @@ replica_index_cmp(const void *a, const void *b, void *arg)
84198419
* - end_hash_code: int32
84208420
* - leader: text
84218421
* - replicas: text[]
8422-
* - active_ssts_size: int8[]
8423-
* - wals_size: int8[]
8422+
* - active_sst_sizes: int8[]
8423+
* - wal_sizes: int8[]
84248424
*
84258425
* The start_hash_code and end_hash_code are the hash codes of the start and end
84268426
* keys of the tablet for hash sharded tables. Leader is provided as a separate
@@ -8508,7 +8508,7 @@ yb_get_tablet_metadata(PG_FUNCTION_ARGS)
85088508
if (tablet->replicas_count > 0)
85098509
{
85108510
size_t nreplicas = tablet->replicas_count;
8511-
int *sort_idx;
8511+
int *sort_idxs;
85128512
Datum *text_elems;
85138513
Datum *sst_elems;
85148514
Datum *wal_elems;
@@ -8522,11 +8522,11 @@ yb_get_tablet_metadata(PG_FUNCTION_ARGS)
85228522
* Build a sort index so replicas and their sizes stay parallel
85238523
* after lexicographic sorting.
85248524
*/
8525-
sort_idx = palloc(nreplicas * sizeof(int));
8525+
sort_idxs = palloc(nreplicas * sizeof(int));
85268526
for (size_t idx = 0; idx < nreplicas; idx++)
8527-
sort_idx[idx] = (int) idx;
8527+
sort_idxs[idx] = (int) idx;
85288528

8529-
qsort_arg(sort_idx, nreplicas, sizeof(int),
8529+
qsort_arg(sort_idxs, nreplicas, sizeof(int),
85308530
replica_index_cmp, tablet->replicas);
85318531

85328532
text_elems = palloc(nreplicas * sizeof(Datum));
@@ -8535,15 +8535,15 @@ yb_get_tablet_metadata(PG_FUNCTION_ARGS)
85358535

85368536
for (size_t idx = 0; idx < nreplicas; idx++)
85378537
{
8538-
int si = sort_idx[idx];
8538+
int si = sort_idxs[idx];
85398539

85408540
text_elems[idx] = CStringGetTextDatum(tablet->replicas[si]);
8541-
sst_elems[idx] = Int64GetDatum(
8542-
tablet->replicas_sst_files_size
8543-
? (int64) tablet->replicas_sst_files_size[si] : 0);
8544-
wal_elems[idx] = Int64GetDatum(
8545-
tablet->replicas_wal_files_size
8546-
? (int64) tablet->replicas_wal_files_size[si] : 0);
8541+
sst_elems[idx] = UInt64GetDatum(
8542+
tablet->replica_sst_sizes
8543+
? tablet->replica_sst_sizes[si] : 0);
8544+
wal_elems[idx] = UInt64GetDatum(
8545+
tablet->replica_wal_sizes
8546+
? tablet->replica_wal_sizes[si] : 0);
85478547
}
85488548

85498549
values[8] = PointerGetDatum(
@@ -8556,7 +8556,7 @@ yb_get_tablet_metadata(PG_FUNCTION_ARGS)
85568556
construct_array(wal_elems, (int) nreplicas,
85578557
INT8OID, 8, FLOAT8PASSBYVAL, TYPALIGN_DOUBLE));
85588558

8559-
pfree(sort_idx);
8559+
pfree(sort_idxs);
85608560
pfree(text_elems);
85618561
pfree(sst_elems);
85628562
pfree(wal_elems);

src/postgres/src/include/catalog/pg_proc.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12235,7 +12235,7 @@
1223512235
proretset => 't', provolatile => 'v', proparallel => 'r',
1223612236
prorettype => 'record', proargtypes => '',
1223712237
proallargtypes => '{text,text,text,text,text,int4,int4,text,_text,_int8,_int8}',
12238-
proargnames => '{tablet_id,object_uuid,namespace,object_name,type,start_hash_code,end_hash_code,leader,replicas,active_ssts_size,wals_size}',
12238+
proargnames => '{tablet_id,object_uuid,namespace,object_name,type,start_hash_code,end_hash_code,leader,replicas,active_sst_sizes,wal_sizes}',
1223912239
proargmodes => '{o,o,o,o,o,o,o,o,o,o,o}',
1224012240
prosrc => 'yb_get_tablet_metadata'},
1224112241

src/postgres/src/test/regress/expected/yb.orig.tablet_metadata.out

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,45 @@ ORDER BY start_hash_code NULLS FIRST;
1515
test_table_1 | yugabyte | 32768 | 65536
1616
(3 rows)
1717

18+
-- Test that active_sst_sizes and wal_sizes columns are present and aligned with replicas
19+
SELECT
20+
relname,
21+
pg_typeof(active_sst_sizes) AS sst_type,
22+
pg_typeof(wal_sizes) AS wal_type,
23+
array_length(active_sst_sizes, 1) = array_length(replicas, 1) AS sst_match,
24+
array_length(wal_sizes, 1) = array_length(replicas, 1) AS wal_match
25+
FROM yb_tablet_metadata
26+
WHERE relname = 'test_table_1'
27+
ORDER BY start_hash_code NULLS FIRST
28+
LIMIT 1;
29+
relname | sst_type | wal_type | sst_match | wal_match
30+
--------------+----------+----------+-----------+-----------
31+
test_table_1 | bigint[] | bigint[] | t | t
32+
(1 row)
33+
34+
-- Test that all size values are non-negative for each replica
35+
SELECT r.val AS replica, s.val AS sst_size, w.val AS wal_size
36+
FROM yb_tablet_metadata tm,
37+
unnest(tm.replicas) WITH ORDINALITY AS r(val, ord),
38+
unnest(tm.active_sst_sizes) WITH ORDINALITY AS s(val, ord),
39+
unnest(tm.wal_sizes) WITH ORDINALITY AS w(val, ord)
40+
WHERE tm.relname = 'test_table_1'
41+
AND r.ord = s.ord AND r.ord = w.ord
42+
AND (s.val < 0 OR w.val < 0);
43+
replica | sst_size | wal_size
44+
---------+----------+----------
45+
(0 rows)
46+
47+
-- Test that every replica address corresponds to a live tserver
48+
SELECT unnest(replicas) AS orphan_replica
49+
FROM yb_tablet_metadata
50+
WHERE relname = 'test_table_1'
51+
EXCEPT
52+
SELECT host || ':' || port FROM yb_servers();
53+
orphan_replica
54+
----------------
55+
(0 rows)
56+
1857
-- Test that we are able to join with yb_servers()
1958
SELECT
2059
ytm.relname,

src/postgres/src/test/regress/sql/yb.orig.tablet_metadata.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@ SELECT
1010
FROM yb_tablet_metadata WHERE relname IN ('test_table_1', 'test_table_2')
1111
ORDER BY start_hash_code NULLS FIRST;
1212

13+
-- Test that active_sst_sizes and wal_sizes columns are present and aligned with replicas
14+
SELECT
15+
relname,
16+
pg_typeof(active_sst_sizes) AS sst_type,
17+
pg_typeof(wal_sizes) AS wal_type,
18+
array_length(active_sst_sizes, 1) = array_length(replicas, 1) AS sst_match,
19+
array_length(wal_sizes, 1) = array_length(replicas, 1) AS wal_match
20+
FROM yb_tablet_metadata
21+
WHERE relname = 'test_table_1'
22+
ORDER BY start_hash_code NULLS FIRST
23+
LIMIT 1;
24+
25+
-- Test that all size values are non-negative for each replica
26+
SELECT r.val AS replica, s.val AS sst_size, w.val AS wal_size
27+
FROM yb_tablet_metadata tm,
28+
unnest(tm.replicas) WITH ORDINALITY AS r(val, ord),
29+
unnest(tm.active_sst_sizes) WITH ORDINALITY AS s(val, ord),
30+
unnest(tm.wal_sizes) WITH ORDINALITY AS w(val, ord)
31+
WHERE tm.relname = 'test_table_1'
32+
AND r.ord = s.ord AND r.ord = w.ord
33+
AND (s.val < 0 OR w.val < 0);
34+
35+
-- Test that every replica address corresponds to a live tserver
36+
SELECT unnest(replicas) AS orphan_replica
37+
FROM yb_tablet_metadata
38+
WHERE relname = 'test_table_1'
39+
EXCEPT
40+
SELECT host || ':' || port FROM yb_servers();
41+
1342
-- Test that we are able to join with yb_servers()
1443
SELECT
1544
ytm.relname,

src/yb/master/catalog_manager.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14301,17 +14301,17 @@ Status CatalogManager::GetTabletsMetadata(const GetTabletsMetadataRequestPB* req
1430114301
leader_wal_files_size = replica.drive_info.wal_files_size;
1430214302
} else {
1430314303
tablet_metadata->add_replicas(server_address);
14304-
tablet_metadata->add_replicas_sst_files_size(replica.drive_info.sst_files_size);
14305-
tablet_metadata->add_replicas_wal_files_size(replica.drive_info.wal_files_size);
14304+
tablet_metadata->add_replica_sst_sizes(replica.drive_info.sst_files_size);
14305+
tablet_metadata->add_replica_wal_sizes(replica.drive_info.wal_files_size);
1430614306
}
1430714307
}
1430814308
}
1430914309

1431014310
// Add leader as the last replica
1431114311
if (!leader_address.empty()) {
1431214312
tablet_metadata->add_replicas(leader_address);
14313-
tablet_metadata->add_replicas_sst_files_size(leader_sst_files_size);
14314-
tablet_metadata->add_replicas_wal_files_size(leader_wal_files_size);
14313+
tablet_metadata->add_replica_sst_sizes(leader_sst_files_size);
14314+
tablet_metadata->add_replica_wal_sizes(leader_wal_files_size);
1431514315
}
1431614316

1431714317
// last_status is a required field in the PB

src/yb/tablet/tablet.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ message TabletStatusPB {
7777
repeated string replicas = 24;
7878
optional bool is_hash_partitioned = 25;
7979
// Per-replica SST and WAL sizes in bytes, parallel to the replicas array.
80-
repeated uint64 replicas_sst_files_size = 26;
81-
repeated uint64 replicas_wal_files_size = 27;
80+
repeated uint64 replica_sst_sizes = 26;
81+
repeated uint64 replica_wal_sizes = 27;
8282
}
8383

8484
// Used to present the maintenance manager's internal state.

src/yb/yql/pggate/ybc_pg_typedefs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ typedef struct {
854854
const char** replicas;
855855
size_t replicas_count;
856856
bool is_hash_partitioned;
857-
uint64_t* replicas_sst_files_size;
858-
uint64_t* replicas_wal_files_size;
857+
const uint64_t* replica_sst_sizes;
858+
const uint64_t* replica_wal_sizes;
859859
} YbcPgGlobalTabletsDescriptor;
860860

861861
typedef struct {

src/yb/yql/pggate/ybc_pggate.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,36 +2994,36 @@ YbcStatus YBCTabletsMetadata(YbcPgGlobalTabletsDescriptor** tablets, size_t* cou
29942994
const char** replicas_array = nullptr;
29952995
uint64_t* sst_sizes_array = nullptr;
29962996
uint64_t* wal_sizes_array = nullptr;
2997-
const auto replicas_size = tablet_metadata.replicas().size();
2997+
const auto replicas_count = tablet_metadata.replicas().size();
29982998

2999-
if (replicas_size > 0) {
2999+
if (replicas_count > 0) {
30003000
replicas_array = static_cast<const char**>(
3001-
YBCPAlloc(replicas_size * sizeof(const char*)));
3001+
YBCPAlloc(replicas_count * sizeof(const char*)));
30023002

3003-
for (int i = 0; i < static_cast<int>(replicas_size); ++i) {
3003+
for (int i = 0; i < static_cast<int>(replicas_count); ++i) {
30043004
replicas_array[i] = YBCPAllocStdString(tablet_metadata.replicas(i));
30053005
}
30063006

30073007
sst_sizes_array = static_cast<uint64_t*>(
3008-
YBCPAlloc(replicas_size * sizeof(uint64_t)));
3008+
YBCPAlloc(replicas_count * sizeof(uint64_t)));
30093009
wal_sizes_array = static_cast<uint64_t*>(
3010-
YBCPAlloc(replicas_size * sizeof(uint64_t)));
3010+
YBCPAlloc(replicas_count * sizeof(uint64_t)));
30113011

3012-
for (int i = 0; i < static_cast<int>(replicas_size); ++i) {
3013-
sst_sizes_array[i] = i < tablet_metadata.replicas_sst_files_size_size()
3014-
? tablet_metadata.replicas_sst_files_size(i) : 0;
3015-
wal_sizes_array[i] = i < tablet_metadata.replicas_wal_files_size_size()
3016-
? tablet_metadata.replicas_wal_files_size(i) : 0;
3012+
for (int i = 0; i < static_cast<int>(replicas_count); ++i) {
3013+
sst_sizes_array[i] = i < tablet_metadata.replica_sst_sizes_size()
3014+
? tablet_metadata.replica_sst_sizes(i) : 0;
3015+
wal_sizes_array[i] = i < tablet_metadata.replica_wal_sizes_size()
3016+
? tablet_metadata.replica_wal_sizes(i) : 0;
30173017
}
30183018
}
30193019

30203020
new (dest) YbcPgGlobalTabletsDescriptor {
30213021
.tablet_descriptor = MakeYbcPgTabletsDescriptor(tablet_metadata),
30223022
.replicas = replicas_array,
3023-
.replicas_count = static_cast<size_t>(replicas_size),
3023+
.replicas_count = static_cast<size_t>(replicas_count),
30243024
.is_hash_partitioned = tablet_metadata.is_hash_partitioned(),
3025-
.replicas_sst_files_size = sst_sizes_array,
3026-
.replicas_wal_files_size = wal_sizes_array
3025+
.replica_sst_sizes = sst_sizes_array,
3026+
.replica_wal_sizes = wal_sizes_array
30273027
};
30283028
++dest;
30293029
}

0 commit comments

Comments
 (0)