-
Notifications
You must be signed in to change notification settings - Fork 488
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
Fix bugs in lfc_cache_containsv #10672
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,10 +220,8 @@ lfc_maybe_disabled(void) | |
static bool | ||
lfc_ensure_opened(void) | ||
{ | ||
bool enabled = !lfc_maybe_disabled(); | ||
|
||
/* Open cache file if not done yet */ | ||
if (lfc_desc <= 0 && enabled) | ||
if (lfc_desc <= 0) | ||
{ | ||
lfc_desc = BasicOpenFile(lfc_path, O_RDWR); | ||
|
||
|
@@ -233,7 +231,7 @@ lfc_ensure_opened(void) | |
return false; | ||
} | ||
} | ||
return enabled; | ||
return true; | ||
} | ||
|
||
static void | ||
|
@@ -338,10 +336,11 @@ lfc_change_limit_hook(int newval, void *extra) | |
{ | ||
uint32 new_size = SIZE_MB_TO_CHUNKS(newval); | ||
|
||
if (!is_normal_backend()) | ||
if (!lfc_ctl || !is_normal_backend()) | ||
return; | ||
|
||
if (!lfc_ensure_opened()) | ||
/* Open LFC file only if LFC was enabled or we are going to reenable it */ | ||
if ((newval > 0 || LFC_ENABLED()) && !lfc_ensure_opened()) | ||
return; | ||
|
||
LWLockAcquire(lfc_lock, LW_EXCLUSIVE); | ||
|
@@ -509,47 +508,44 @@ lfc_cache_containsv(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, | |
|
||
CriticalAssert(BufTagGetRelNumber(&tag) != InvalidRelFileNumber); | ||
|
||
tag.blockNum = (blkno + i) & ~(BLOCKS_PER_CHUNK - 1); | ||
tag.blockNum = blkno & ~(BLOCKS_PER_CHUNK - 1); | ||
hash = get_hash_value(lfc_hash, &tag); | ||
chunk_offs = (blkno + i) & (BLOCKS_PER_CHUNK - 1); | ||
chunk_offs = blkno & (BLOCKS_PER_CHUNK - 1); | ||
Comment on lines
-512
to
+513
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. Not really a bug getting fixed here, but alright. 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. It is certainly not a bug, just some code simplification. |
||
|
||
LWLockAcquire(lfc_lock, LW_SHARED); | ||
|
||
if (!LFC_ENABLED()) | ||
{ | ||
LWLockRelease(lfc_lock); | ||
return 0; | ||
} | ||
while (true) | ||
{ | ||
int this_chunk = Min(nblocks, BLOCKS_PER_CHUNK - chunk_offs); | ||
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. Yep, that's a bug indeed, when crossing chunk boundaries. I'm not sure though why all those other things needed changing, IIUC those worked just fine. |
||
if (LFC_ENABLED()) | ||
{ | ||
entry = hash_search_with_hash_value(lfc_hash, &tag, hash, HASH_FIND, NULL); | ||
int this_chunk = Min(nblocks - i, BLOCKS_PER_CHUNK - chunk_offs); | ||
entry = hash_search_with_hash_value(lfc_hash, &tag, hash, HASH_FIND, NULL); | ||
|
||
if (entry != NULL) | ||
if (entry != NULL) | ||
{ | ||
for (; chunk_offs < BLOCKS_PER_CHUNK && i < nblocks; chunk_offs++, i++) | ||
{ | ||
for (; chunk_offs < BLOCKS_PER_CHUNK && i < nblocks; chunk_offs++, i++) | ||
if ((entry->bitmap[chunk_offs >> 5] & | ||
((uint32)1 << (chunk_offs & 31))) != 0) | ||
{ | ||
if ((entry->bitmap[chunk_offs >> 5] & | ||
((uint32)1 << (chunk_offs & 31))) != 0) | ||
{ | ||
BITMAP_SET(bitmap, i); | ||
found++; | ||
} | ||
BITMAP_SET(bitmap, i); | ||
found++; | ||
} | ||
} | ||
else | ||
{ | ||
i += this_chunk; | ||
} | ||
} | ||
else | ||
{ | ||
LWLockRelease(lfc_lock); | ||
return found; | ||
i += this_chunk; | ||
} | ||
|
||
/* | ||
* Break out of the iteration before doing expensive stuff for | ||
* a next iteration | ||
*/ | ||
if (i + 1 >= nblocks) | ||
if (i >= nblocks) | ||
break; | ||
|
||
/* | ||
|
@@ -563,8 +559,8 @@ lfc_cache_containsv(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, | |
|
||
LWLockRelease(lfc_lock); | ||
|
||
#if USE_ASSERT_CHECKING | ||
do { | ||
#ifdef USE_ASSERT_CHECKING | ||
{ | ||
int count = 0; | ||
|
||
for (int j = 0; j < nblocks; j++) | ||
|
@@ -574,7 +570,7 @@ lfc_cache_containsv(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, | |
} | ||
|
||
Assert(count == found); | ||
} while (false); | ||
} | ||
#endif | ||
|
||
return found; | ||
|
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.
We shouldn't be opening the LFC file if we've disabled the LFC.
-1 on this change
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.
Well, I think we really need to be able to reenable LFC.
I have added the following check to make sure that we open LFC file only if LFC was enabled or we are going to reenable it: