Skip to content

Commit

Permalink
Fix shard hash caclulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Knizhnik committed Nov 29, 2023
1 parent d858557 commit a6e6cb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pgxn/neon/libpagestore.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ get_shard_number(BufferTag* tag)

#if PG_MAJORVERSION_NUM < 16
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/(MB/BLCKSZ)/stripe_size));
hash = hash_combine(hash, murmurhash32(tag->rnode.dbNode));
hash = hash_combine(hash, murmurhash32(tag->rnode.relNode));
hash = 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/(MB/BLCKSZ)/stripe_size));
hash = hash_combine(hash, murmurhash32(tag->dbOid));
hash = hash_combine(hash, murmurhash32(tag->relNumber));
hash = hash_combine(hash, murmurhash32(tag->blockNum/(MB/BLCKSZ)/stripe_size));
#endif

return hash % n_shards;
Expand Down
9 changes: 9 additions & 0 deletions pgxn/neon/pagestore_smgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,15 @@ page_server_request(void const *req)
}
shard_no = get_shard_number(&tag);

/*
* TODO: temporary workarround - we stream all WAL only to shard 0 so metadata and forks other than main
* should be requested from shard 0. We still need to call get_shard_no() to check if shard map is up-to-date
*/
if (((NeonRequest *) req)->tag != T_NeonGetPageRequest || ((NeonGetPageRequest *) req)->forknum != MAIN_FORKNUM)
{
shard_no = 0;
}

do {
while (!page_server->send(shard_no, (NeonRequest *) req) || !page_server->flush(shard_no));
MyPState->ring_flush = MyPState->ring_unused;
Expand Down

0 comments on commit a6e6cb0

Please sign in to comment.