8000 Remove erroneous cast to size_t in BID_HASH_FUNC by funny-falcon · Pull Request #10 · postgrespro/ptrack · GitHub
[go: up one dir, main page]

Skip to content

Remove erroneous cast to size_t in BID_HASH_FUNC #10

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

Merged
merged 1 commit into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
ForkNumber forknum, BlockNumber blocknum)
{
PtBlockId bid;
size_t hash;
uint64 hash;
size_t slot1;
size_t slot2;
XLogRecPtr new_lsn;
Expand All @@ -676,8 +676,8 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
bid.blocknum = blocknum;

hash = BID_HASH_FUNC(bid);
slot1 = hash % PtrackContentNblocks;
slot2 = ((hash << 32) | (hash >> 32)) % PtrackContentNblocks;
slot1 = (size_t)(hash % PtrackContentNblocks);
slot2 = (size_t)(((hash << 32) | (hash >> 32)) % PtrackContentNblocks);

if (RecoveryInProgress())
new_lsn = GetXLogReplayRecPtr(NULL);
Expand Down
2 changes: 1 addition & 1 deletion engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ typedef PtrackMapHdr * PtrackMap;
/* Block address 'bid' to hash. To get slot position in map should be divided
* with '% PtrackContentNblocks' */
#define BID_HASH_FUNC(bid) \
(size_t)(DatumGetUInt64(hash_any_extended((unsigned char *)&bid, sizeof(bid), 0)))
(DatumGetUInt64(hash_any_extended((unsigned char *)&bid, sizeof(bid), 0)))
Copy link
Contributor
@ololobus ololobus May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this size_t seems to be not correct, since it is 32 bit wide on 32 bit systems, which is not what we want here. However, next we assign this value to hash variable, which again has a size_t type, so this change alone does not has much sense, doesn't it? Probably we should change all appearances of size_t used for hash map reference to uint64 for portability?

Copy link
Contributor Author
@funny-falcon funny-falcon May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I recognize hash variable as well. I've just push-forced branch.


/*
* Per process pointer to shared ptrack_map
Expand Down
6 changes: 3 additions & 3 deletions ptrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)

while (true)
{
size_t hash;
uint64 hash;
size_t slot1;
size_t slot2;
XLogRecPtr update_lsn1;
Expand Down Expand Up @@ -535,7 +535,7 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
}

hash = BID_HASH_FUNC(ctx->bid);
slot1 = hash % PtrackContentNblocks;
slot1 = (size_t)(hash % PtrackContentNblocks);

update_lsn1 = pg_atomic_read_u64(&ptrack_map->entries[slot1]);

Expand All @@ -547,7 +547,7 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
/* Only probe the second slot if the first one is marked */
if (update_lsn1 >= ctx->lsn)
{
slot2 = ((hash << 32) | (hash >> 32)) % PtrackContentNblocks;
slot2 = (size_t)(((hash << 32) | (hash >> 32)) % PtrackContentNblocks);
update_lsn2 = pg_atomic_read_u64(&ptrack_map->entries[slot2]);

if (update_lsn2 != InvalidXLogRecPtr)
Expand Down
0