From 3cbd2df0b3009e51802a0d1b9be0d673baf34d3c Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Thu, 9 Nov 2023 22:19:58 +0200 Subject: [PATCH] Add neon.stripe_size --- pgxn/neon/libpagestore.c | 15 +++++++++++++-- pgxn/neon/pagestore_client.h | 1 - 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pgxn/neon/libpagestore.c b/pgxn/neon/libpagestore.c index fcf69f7c7c..3cc2c7df45 100644 --- a/pgxn/neon/libpagestore.c +++ b/pgxn/neon/libpagestore.c @@ -55,6 +55,7 @@ int flush_every_n_requests = 8; int n_reconnect_attempts = 0; int max_reconnect_attempts = 60; +int stripe_size; bool (*old_redo_read_buffer_filter) (XLogReaderState *record, uint8 block_id) = NULL; @@ -197,6 +198,7 @@ load_shard_map(shardno_t shard_no, char* connstr) return n_shards; } +#define MB (1024*1024) shardno_t get_shard_number(BufferTag* tag) { @@ -207,12 +209,12 @@ get_shard_number(BufferTag* tag) hash = murmurhash32(tag->rnode.spcNode); hash_combine(hash, murmurhash32(tag->rnode.dbNode)); hash_combine(hash, murmurhash32(tag->rnode.relNode)); - hash_combine(hash, murmurhash32(tag->blockNum/STRIPE_SIZE)); + hash_combine(hash, murmurhash32(tag->blockNum/(MB/BLCKSZ)/stripe_size)); #else hash = murmurhash32(tag->spcOid); hash_combine(hash, murmurhash32(tag->dbOid)); hash_combine(hash, murmurhash32(tag->relNumber)); - hash_combine(hash, murmurhash32(tag->blockNum/STRIPE_SIZE)); + hash_combine(hash, murmurhash32(tag->blockNum/(MB/BLCKSZ)/stripe_size)); #endif return hash % n_shards; @@ -587,6 +589,15 @@ pg_init_libpagestore(void) 0, /* no flags required */ check_neon_id, NULL, NULL); + DefineCustomIntVariable("neon.stripe_size", + "sharding sripe size", + NULL, + &stripe_size, + 256, 1, INT_MAX, + PGC_SIGHUP, + GUC_UNIT_MB, + NULL, NULL, NULL); + DefineCustomIntVariable("neon.max_cluster_size", "cluster size limit", NULL, diff --git a/pgxn/neon/pagestore_client.h b/pgxn/neon/pagestore_client.h index c9c758c61d..a8b5a3399f 100644 --- a/pgxn/neon/pagestore_client.h +++ b/pgxn/neon/pagestore_client.h @@ -28,7 +28,6 @@ #include "pg_config.h" #define MAX_SHARDS 128 -#define STRIPE_SIZE (256 * 1024 / 8) /* TODO: should in betaken from control plane? */ #define MAX_PS_CONNSTR_LEN 128 typedef enum