Re: Logical replication 'invalid memory alloc request size 1585837200' after upgrading to 17.5
vignesh C <vignesh21@gmail.com>
From: vignesh C <vignesh21@gmail.com>
To: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>, "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>,
Duncan Sands <duncan.sands@deepbluecap.com>, "pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>
Date: 2025-06-03T07:07:14Z
Lists: pgsql-bugs
Attachments
- v9-master-0001-Fix-exponential-memory-allocation-issue-in.patch (text/x-patch) patch v9-0001
On Mon, 2 Jun 2025 at 22:49, Masahiko Sawada <sawada.mshk@gmail.com> wrote: > > Thank you for updating the patch. Here are some review comments: > > + req_mem_size = sizeof(SharedInvalidationMessage) * > (txn->ninvalidations_distr + nmsgs); > + > + /* > + * If the number of invalidation messages is larger than 8MB, it's more > + * efficient to invalidate the entire cache rather than processing each > + * message individually. > + */ > + if (req_mem_size > (8 * 1024 * 1024) || rbtxn_inval_all_cache(txn)) > > It's better to define the maximum number of distributed inval messages > per transaction as a macro instead of calculating the memory size > every time. Modified > --- > +static void > +ReorderBufferAddInvalidationsCommon(ReorderBuffer *rb, TransactionId xid, > + XLogRecPtr lsn, Size nmsgs, > + SharedInvalidationMessage *msgs, > + ReorderBufferTXN *txn, > + bool for_inval) > > This function is quite confusing to me. For instance, > ReorderBufferAddDistributedInvalidations() needs to call this function > with for_inval=false in spite of adding inval messages actually. Also, > the following condition seems not intuisive but there is no comment: > > if (!for_inval || (for_inval && !rbtxn_inval_all_cache(txn))) > > Instead of having ReorderBufferAddInvalidationsCommon(), I think we > can have a function say ReorderBufferQueueInvalidations() where we > enqueue the given inval messages as a > REORDER_BUFFER_CHANGE_INVALIDATION change. > ReorderBufferAddInvalidations() adds inval messages to > txn->invalidations and calls that function, while > ReorderBufferQueueInvalidations() adds inval messages to > txn->distributed_ivnalidations and calls that function if the array is > not full. Modified > BTW if we need to invalidate all accumulated caches at the end of > transaction replay anyway, we don't need to add inval messages to > txn->invalidations once txn->distributed_invalidations gets full? yes, no need to add invalidation messages to txn->invalidation once RBTXN_INVAL_ALL_CACHE is set. This is handled now. The attached v9 version patch has the changes for the same. Regards, Vignesh
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix cache-dependent test failures in logical decoding.
- 87819f766f37 13.22 landed
-
Fix re-distributing previously distributed invalidation messages during logical decoding.
- d87d07b7ad3b 18.0 landed
- 45c357e0e85d 17.6 landed
- b2ae077205e1 16.10 landed
- fc0fb77c550f 15.14 landed
- 983b3636259b 14.19 landed
- 1230be12f086 13.22 landed
-
Fix data loss in logical replication.
- 247ee94150b6 13.21 cited
- 4909b38af034 18.0 cited