From 7e469d610bef6c205320cde18b6901d7ae275381 Mon Sep 17 00:00:00 2001 From: Alex Chi Z Date: Thu, 10 Jul 2025 17:18:27 -0400 Subject: [PATCH] fix(libpagestore): only update pageserver connstring when stripe size is available Signed-off-by: Alex Chi Z --- pgxn/neon/libpagestore.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/pgxn/neon/libpagestore.c b/pgxn/neon/libpagestore.c index 3b6c4247c3..0036dd933e 100644 --- a/pgxn/neon/libpagestore.c +++ b/pgxn/neon/libpagestore.c @@ -249,6 +249,19 @@ CheckPageserverConnstring(char **newval, void **extra, GucSource source) static void AssignPageserverConnstring(const char *newval, void *extra) +{ + UpdatePageserverShardMap(newval, stripe_size); +} + +static void +AssignPageserverStripeSize(const int newval, void *extra) +{ + UpdatePageserverShardMap(page_server_connstring, newval); +} + + +static void +UpdatePageserverShardMap(const char *connstring, int stripe_size) { ShardMap shard_map; @@ -258,13 +271,20 @@ AssignPageserverConnstring(const char *newval, void *extra) if (!PagestoreShmemIsValid() || IsUnderPostmaster) return; - if (!ParseShardMap(newval, &shard_map)) + if (!ParseShardMap(connstring, &shard_map)) { /* * shouldn't happen, because we already checked the value in * CheckPageserverConnstring */ elog(ERROR, "could not parse shard map"); + return; + } + + if (shard_map.num_shards > 1 && stripe_size == 0) + { + elog(ERROR, "stripe_size not available yet, not updating the shard map"); + return; } if (memcmp(&pagestore_shared->shard_map, &shard_map, sizeof(ShardMap)) != 0) @@ -1407,13 +1427,13 @@ pg_init_libpagestore(void) NULL, NULL, NULL); DefineCustomIntVariable("neon.stripe_size", - "sharding stripe size", + "sharding stripe size, 0 or unset if not sharded", NULL, &stripe_size, - 32768, 1, INT_MAX, + 0, 0, INT_MAX, PGC_SIGHUP, GUC_UNIT_BLOCKS, - NULL, NULL, NULL); + NULL, AssignPageserverStripeSize, NULL); DefineCustomIntVariable("neon.max_cluster_size", "cluster size limit",