Commit 80afb62d authored by Teodor Sigaev's avatar Teodor Sigaev

Fixes in bloom contrib module

Looking at result of buildfarm member jaguarundi it seems to me that
BloomOptions isn't inited sometime, but I don't see yet how it's possible.
Nevertheless, check of signature length's is missed, so, add
a limit of it. Also add missed GenericXLogAbort() in case of already
deleted page in vacuum + minor code refactoring.
parent c22650cd
...@@ -63,6 +63,12 @@ typedef BloomPageOpaqueData *BloomPageOpaque; ...@@ -63,6 +63,12 @@ typedef BloomPageOpaqueData *BloomPageOpaque;
#define BLOOM_METAPAGE_BLKNO (0) #define BLOOM_METAPAGE_BLKNO (0)
#define BLOOM_HEAD_BLKNO (1) /* first data page */ #define BLOOM_HEAD_BLKNO (1) /* first data page */
/*
* Maximum of bloom signature length in uint16. Actual value
* is 512 bytes
*/
#define MAX_BLOOM_LENGTH (256)
/* Bloom index options */ /* Bloom index options */
typedef struct BloomOptions typedef struct BloomOptions
{ {
......
...@@ -370,8 +370,11 @@ adjustBloomOptions(BloomOptions *opts) ...@@ -370,8 +370,11 @@ adjustBloomOptions(BloomOptions *opts)
/* Default length of bloom filter is 5 of 16-bit integers */ /* Default length of bloom filter is 5 of 16-bit integers */
if (opts->bloomLength <= 0) if (opts->bloomLength <= 0)
opts->bloomLength = 5; opts->bloomLength = 5;
else else if (opts->bloomLength > MAX_BLOOM_LENGTH)
opts->bloomLength = opts->bloomLength; ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("length of bloom signature (%d) is greater than maximum %d",
opts->bloomLength, MAX_BLOOM_LENGTH)));
/* Check singnature length */ /* Check singnature length */
for (i = 0; i < INDEX_MAX_KEYS; i++) for (i = 0; i < INDEX_MAX_KEYS; i++)
...@@ -382,7 +385,7 @@ adjustBloomOptions(BloomOptions *opts) ...@@ -382,7 +385,7 @@ adjustBloomOptions(BloomOptions *opts)
* with 2 bits default. * with 2 bits default.
*/ */
if (opts->bitSize[i] <= 0 if (opts->bitSize[i] <= 0
|| opts->bitSize[i] >= opts->bloomLength * sizeof(SignType)) || opts->bitSize[i] >= opts->bloomLength * sizeof(SignType) * BITS_PER_BYTE)
opts->bitSize[i] = 2; opts->bitSize[i] = 2;
} }
} }
......
...@@ -70,14 +70,15 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, ...@@ -70,14 +70,15 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
if (BloomPageIsDeleted(page)) if (BloomPageIsDeleted(page))
{ {
UnlockReleaseBuffer(buffer); UnlockReleaseBuffer(buffer);
GenericXLogAbort(gxlogState);
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
continue; continue;
} }
/* Iterate over the tuples */ /* Iterate over the tuples */
itup = BloomPageGetTuple(&state, page, 1); itup = itupPtr = BloomPageGetTuple(&state, page, FirstOffsetNumber);
itupPtr = BloomPageGetTuple(&state, page, 1); itupEnd = BloomPageGetTuple(&state, page,
itupEnd = BloomPageGetTuple(&state, page, BloomPageGetMaxOffset(page) + 1); OffsetNumberNext(BloomPageGetMaxOffset(page)));
while (itup < itupEnd) while (itup < itupEnd)
{ {
/* Do we have to delete this tuple? */ /* Do we have to delete this tuple? */
...@@ -104,10 +105,10 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, ...@@ -104,10 +105,10 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
itup = BloomPageGetNextTuple(&state, itup); itup = BloomPageGetNextTuple(&state, itup);
} }
Assert(itupPtr == BloomPageGetTuple(&state, page, BloomPageGetMaxOffset(page) + 1)); Assert(itupPtr == BloomPageGetTuple(&state, page,
OffsetNumberNext(BloomPageGetMaxOffset(page))));
if (!BloomPageIsDeleted(page) && if (BloomPageGetFreeSpace(&state, page) > state.sizeOfBloomTuple &&
BloomPageGetFreeSpace(&state, page) > state.sizeOfBloomTuple &&
countPage < BloomMetaBlockN) countPage < BloomMetaBlockN)
notFullPage[countPage++] = blkno; notFullPage[countPage++] = blkno;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment