Improve consistency checks in tbm_prepare_shared_iterate

Started by Daniil Davydovalmost 2 years ago1 messageshackers

Thread notes

1 note#refactor
hackorum-bot#refactor
hackorum-bot
1 day ago

@global #refactor

#refactor
Jump to latest
#1Daniil Davydov
3danissimo@gmail.com

Hi,
Currently, iterating through TIDBitmap contains this code (REL_16_STABLE) :
***
while ((page = pagetable_iterate(tbm->pagetable, &i)) != NULL)
{
idx = page - ptbase->ptentry;
if (page->ischunk)
ptchunks->index[nchunks++] = idx;
else
ptpages->index[npages++] = idx;
}

Assert(npages == tbm->npages);
Assert(nchunks == tbm->nchunks);
***

Two asserts in the end seem to be overdue to me, because if (for
example) nchunks > tbm->nchunks (due to another error),
we have already accessed to invalid memory chunk and overwritten it.
If we want to monitor the correctness of these variables, it might be
better to add a few checks, as in the attached patch.

I'm not sure if the comment in the error message is written correctly,
but first I would like to hear your opinion.

--
Best regards,
Daniil Davydov

Attachments:

t50818_1
0001-Add-new-checks-for-tidbitmap-scan.patchtext/x-patch; charset=US-ASCII; name=0001-Add-new-checks-for-tidbitmap-scan.patchDownload+9-3