Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc570bb4

Browse files
author
Amit Kapila
committed
Fix uninitialized access to InitialRunningXacts during decoding after ERROR.
The transactions and subtransactions array that was allocated undersnapshot builder memory context and recorded during decoding was notcleared in case of errors. This can result in an assertion failure if weattempt to retry logical decoding within the same session. To address thisissue, we register a callback function under the snapshot builder memorycontext to clear the recorded transactions and subtransactions array alongwith the context.This problem doesn't exist in PG16 and HEAD as instead of usingInitialRunningXacts, we added the list of transaction IDs andsub-transaction IDs, that have modified catalogs and are running duringsnapshot serialization, to the serialized snapshot (see commit7f13ac8).Author: Hou ZhijieReviewed-by: Amit KapilaBackpatch-through: 11Discussion:http://postgr.es/m/18055-ab3beed9f4b7b7d6@postgresql.org
1 parent5dc093e commitc570bb4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

‎src/backend/replication/logical/snapbuild.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ SnapBuildStartNextPhaseAt(SnapBuild *builder, TransactionId at)
330330
builder->was_running.was_xmax=at;
331331
}
332332

333+
/*
334+
* Memory context reset callback for clearing the array of running transactions
335+
* and subtransactions.
336+
*/
337+
staticvoid
338+
SnapBuildResetRunningXactsCallback(void*arg)
339+
{
340+
NInitialRunningXacts=0;
341+
InitialRunningXacts=NULL;
342+
}
343+
333344
/*
334345
* Allocate a new snapshot builder.
335346
*
@@ -345,6 +356,7 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
345356
MemoryContextcontext;
346357
MemoryContextoldcontext;
347358
SnapBuild*builder;
359+
MemoryContextCallback*mcallback;
348360

349361
/* allocate memory in own context, to have better accountability */
350362
context=AllocSetContextCreate(CurrentMemoryContext,
@@ -369,6 +381,10 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
369381
builder->start_decoding_at=start_lsn;
370382
builder->building_full_snapshot=need_full_snapshot;
371383

384+
mcallback=palloc0(sizeof(MemoryContextCallback));
385+
mcallback->func=SnapBuildResetRunningXactsCallback;
386+
MemoryContextRegisterResetCallback(CurrentMemoryContext,mcallback);
387+
372388
MemoryContextSwitchTo(oldcontext);
373389

374390
/* The initial running transactions array must be empty. */
@@ -394,10 +410,6 @@ FreeSnapshotBuilder(SnapBuild *builder)
394410

395411
/* other resources are deallocated via memory context reset */
396412
MemoryContextDelete(context);
397-
398-
/* InitialRunningXacts is freed along with the context */
399-
NInitialRunningXacts=0;
400-
InitialRunningXacts=NULL;
401413
}
402414

403415
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp