-
Notifications
You must be signed in to change notification settings - Fork 1.2k
YSQL: Add attributes (jsonb) to yb_tablet_metadata
#30294
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
Open
keisku
wants to merge
7
commits into
yugabyte:master
Choose a base branch
from
keisku:issue-29665
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
23b6d2f
YSQL: Add `{active_ssts,wals}_size` to `yb_tablet_metadata`
keisku 99d02db
Rename and fix tablet metadata size columns
keisku e3e742f
Expose tablet replica attributes as JSONB
keisku 65c6a25
Use v100
keisku 1e2ff4a
Simplify replica sorting in yb_get_tablet_metadata
keisku 2eb26ed
Bump tablet metadata migration to V101
keisku 79d4847
Fix values[] assignment order in yb_tablet_metadata_sizes
keisku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,7 @@ | |
| #endif | ||
| #include "storage/procarray.h" | ||
| #include "tcop/utility.h" | ||
| #include "utils/array.h" | ||
| #include "utils/builtins.h" | ||
| #include "utils/datum.h" | ||
| #include "utils/fmgroids.h" | ||
|
|
@@ -8482,10 +8483,13 @@ string_list_compare(const ListCell *a, const ListCell *b) | |
| * - end_hash_code: int32 | ||
| * - leader: text | ||
| * - replicas: text[] | ||
| * - attributes: jsonb (nested structure with per-replica data) | ||
| * | ||
| * The start_hash_code and end_hash_code are the hash codes of the start and end | ||
| * keys of the tablet for hash sharded tables. Leader is provided as a separate | ||
| * column for simpler querying and self-explanatory access. | ||
| * column for simpler querying and self-explanatory access. The attributes column | ||
| * contains a JSONB object with a "replicas" key mapping each replica address to | ||
| * its metrics (active_sst_sizes, wal_sizes). | ||
| */ | ||
| Datum | ||
| yb_get_tablet_metadata(PG_FUNCTION_ARGS) | ||
|
|
@@ -8495,7 +8499,7 @@ yb_get_tablet_metadata(PG_FUNCTION_ARGS) | |
| Tuplestorestate *tupstore; | ||
| MemoryContext per_query_ctx; | ||
| MemoryContext oldcontext; | ||
| static int ncols = 9; | ||
| static int ncols = 10; | ||
|
|
||
| /* check to see if caller supports us returning a tuplestore */ | ||
| if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo)) | ||
|
|
@@ -8564,31 +8568,100 @@ yb_get_tablet_metadata(PG_FUNCTION_ARGS) | |
| nulls[6] = true; | ||
| } | ||
|
|
||
| /* Convert replicas array to PostgreSQL text array */ | ||
| /* Convert replicas to PostgreSQL text array and build JSONB attributes */ | ||
| if (tablet->replicas_count > 0) | ||
| { | ||
| size_t nreplicas = tablet->replicas_count; | ||
|
|
||
| Assert(tablet->replicas != NULL); | ||
|
|
||
| /* The last replica is the leader. */ | ||
| values[7] = CStringGetTextDatum(tablet->replicas[tablet->replicas_count - 1]); | ||
| values[7] = CStringGetTextDatum(tablet->replicas[nreplicas - 1]); | ||
|
|
||
| /* Convert char ** to List * */ | ||
| List *replicas_list = NIL; | ||
| { | ||
| List *replicas_list = NIL; | ||
|
|
||
| for (size_t idx = 0; idx < tablet->replicas_count; idx++) | ||
| replicas_list = lappend(replicas_list, (char *) tablet->replicas[idx]); | ||
| for (size_t idx = 0; idx < nreplicas; idx++) | ||
| replicas_list = lappend(replicas_list, | ||
| (char *) tablet->replicas[idx]); | ||
|
|
||
| /* | ||
| * Sort the list lexicographically for consistency, so that all rows | ||
| * with same replicas have same entries. | ||
| */ | ||
| list_sort(replicas_list, string_list_compare); | ||
| values[8] = PointerGetDatum(strlist_to_textarray(replicas_list)); | ||
| /* | ||
| * Sort the list lexicographically for consistency, so that | ||
| * all rows with same replicas have same entries. | ||
| */ | ||
| list_sort(replicas_list, string_list_compare); | ||
| values[8] = PointerGetDatum(strlist_to_textarray(replicas_list)); | ||
| } | ||
|
|
||
| /* Build JSONB attributes with per-replica size metrics. */ | ||
| { | ||
| JsonbParseState *jb_state = NULL; | ||
| JsonbValue jb_result; | ||
| JsonbValue jb_key; | ||
| JsonbValue jb_val; | ||
|
|
||
| /* {"replicas": {"addr": {"active_sst_sizes": N, "wal_sizes": N}, ...}} */ | ||
| pushJsonbValue(&jb_state, WJB_BEGIN_OBJECT, NULL); | ||
|
|
||
| jb_key.type = jbvString; | ||
| jb_key.val.string.val = "replicas"; | ||
| jb_key.val.string.len = 8; | ||
| pushJsonbValue(&jb_state, WJB_KEY, &jb_key); | ||
|
|
||
| pushJsonbValue(&jb_state, WJB_BEGIN_OBJECT, NULL); | ||
|
|
||
| for (size_t idx = 0; idx < nreplicas; idx++) | ||
| { | ||
| int64 sst_size; | ||
| int64 wal_size; | ||
|
|
||
| sst_size = tablet->replica_sst_sizes | ||
| ? tablet->replica_sst_sizes[idx] : 0; | ||
| wal_size = tablet->replica_wal_sizes | ||
| ? tablet->replica_wal_sizes[idx] : 0; | ||
|
|
||
| /* Replica address as key */ | ||
| jb_key.type = jbvString; | ||
| jb_key.val.string.val = (char *) tablet->replicas[idx]; | ||
| jb_key.val.string.len = strlen(tablet->replicas[idx]); | ||
| pushJsonbValue(&jb_state, WJB_KEY, &jb_key); | ||
|
|
||
| /* Per-replica object */ | ||
| pushJsonbValue(&jb_state, WJB_BEGIN_OBJECT, NULL); | ||
|
|
||
| jb_key.type = jbvString; | ||
| jb_key.val.string.val = "active_sst_sizes"; | ||
| jb_key.val.string.len = 16; | ||
| pushJsonbValue(&jb_state, WJB_KEY, &jb_key); | ||
| jb_val.type = jbvNumeric; | ||
| jb_val.val.numeric = DatumGetNumeric( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error (S&RX) bad_opening_paren |
||
| DirectFunctionCall1(int8_numeric, Int64GetDatum(sst_size))); | ||
| pushJsonbValue(&jb_state, WJB_VALUE, &jb_val); | ||
|
|
||
| jb_key.type = jbvString; | ||
| jb_key.val.string.val = "wal_sizes"; | ||
| jb_key.val.string.len = 9; | ||
| pushJsonbValue(&jb_state, WJB_KEY, &jb_key); | ||
| jb_val.type = jbvNumeric; | ||
| jb_val.val.numeric = DatumGetNumeric( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error (S&RX) bad_opening_paren |
||
| DirectFunctionCall1(int8_numeric, Int64GetDatum(wal_size))); | ||
| pushJsonbValue(&jb_state, WJB_VALUE, &jb_val); | ||
|
|
||
| pushJsonbValue(&jb_state, WJB_END_OBJECT, NULL); | ||
| } | ||
|
|
||
| pushJsonbValue(&jb_state, WJB_END_OBJECT, NULL); /* end replicas */ | ||
| jb_result = *pushJsonbValue(&jb_state, WJB_END_OBJECT, NULL); /* end outer */ | ||
|
|
||
| values[9] = JsonbPGetDatum(JsonbValueToJsonb(&jb_result)); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| nulls[7] = true; | ||
| nulls[8] = true; | ||
| nulls[9] = true; | ||
| } | ||
|
|
||
| tuplestore_putvalues(tupstore, tupdesc, values, nulls); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.