Fix invalid alloc size when invalidating caches
In AddInvalidationMessage() a new chunk always has double size of last
chunk, but once the size exceeds 1GB, the max allowed alloc size, an
error like "invalid memory alloc request size 1,342,177,300" will be
thrown.
Fixed by limiting the chunk size.
@@ -248,6 +248,14 @@ AddInvalidationMessage(InvalidationChunk **listHdr,
/* Need another chunk; double size of last chunk */
int chunksize = 2 * chunk->maxitems;
+ /*
+ * Keep in mind: the max allowed alloc size is about 1GB, for
+ * simplification we set the upper limit to half of that.
+ */
+#define MAXCHUNKSIZE (MaxAllocSize / 2 / sizeof(SharedInvalidationMessage))
+ if (chunksize > MAXCHUNKSIZE)
+ chunksize >>= 1;
+
chunk = (InvalidationChunk *)
MemoryContextAlloc(CurTransactionContext,
offsetof(InvalidationChunk, msgs) +
