Skip to content

Commit 0f592a0

Browse files
author
Antonin Houska
committed
Store the snapshot for the initial load in the correct memory context.
Although the correct context (TopMemoryContext) is set explicitly, it appears that DecodingContextFindStartpoint() (PG core) can change it to TopTransactionContext. This can happen if cache invalidations are processed at certain stage of the setup of the logical decoding system. In practice, cache invalidations take place when DDL commands are executed. If the wrong memory context is used, the snapshot for the initial load can get corrupted, which in turn can cause ERROR (i.e. failure complete the squeezing, in which case all the work done by the extension gets rolled back). Unfortunately, at specific circumstances, data loss might probably take place instead, although I haven't heard about such a case so far. This bug only affects "manual" processing of tables, i.e. cases where the squeeze.squeeze_table() function is used. It does not affect cases where the scheduler worker is involved (shared memory is used then).
1 parent 9da6307 commit 0f592a0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

worker.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,8 @@ create_replication_slots(int nslots, MemoryContext mcxt)
15601560
* transactions to finish, so it should not be done by the workers.
15611561
*/
15621562
DecodingContextFindStartpoint(ctx);
1563+
/* The call above could have changed the memory context.*/
1564+
MemoryContextSwitchTo(mcxt);
15631565

15641566
/* Get the values the caller is interested int. */
15651567
res_ptr->confirmed_flush = slot->data.confirmed_flush;
@@ -1588,7 +1590,8 @@ create_replication_slots(int nslots, MemoryContext mcxt)
15881590
{
15891591
res_ptr->snap_seg = NULL;
15901592
res_ptr->snap_handle = DSM_HANDLE_INVALID;
1591-
snap_dst = res_ptr->snap_private = (char *) palloc(snap_size);
1593+
snap_dst = (char *) MemoryContextAlloc(mcxt, snap_size);
1594+
res_ptr->snap_private = snap_dst;
15921595
}
15931596
/*
15941597
* XXX Should we care about alignment? The function doesn't seem to

0 commit comments

Comments
 (0)