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

Commitf7d2511

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 parent2f13e8d commitf7d2511

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
@@ -300,6 +300,17 @@ static void SnapBuildWaitSnapshot(xl_running_xacts *running, TransactionId cutof
300300
staticvoidSnapBuildSerialize(SnapBuild*builder,XLogRecPtrlsn);
301301
staticboolSnapBuildRestore(SnapBuild*builder,XLogRecPtrlsn);
302302

303+
/*
304+
* Memory context reset callback for clearing the array of running transactions
305+
* and subtransactions.
306+
*/
307+
staticvoid
308+
SnapBuildResetRunningXactsCallback(void*arg)
309+
{
310+
NInitialRunningXacts=0;
311+
InitialRunningXacts=NULL;
312+
}
313+
303314
/*
304315
* Allocate a new snapshot builder.
305316
*
@@ -316,6 +327,7 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
316327
MemoryContextcontext;
317328
MemoryContextoldcontext;
318329
SnapBuild*builder;
330+
MemoryContextCallback*mcallback;
319331

320332
/* allocate memory in own context, to have better accountability */
321333
context=AllocSetContextCreate(CurrentMemoryContext,
@@ -341,6 +353,10 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
341353
builder->building_full_snapshot=need_full_snapshot;
342354
builder->initial_consistent_point=initial_consistent_point;
343355

356+
mcallback=palloc0(sizeof(MemoryContextCallback));
357+
mcallback->func=SnapBuildResetRunningXactsCallback;
358+
MemoryContextRegisterResetCallback(CurrentMemoryContext,mcallback);
359+
344360
MemoryContextSwitchTo(oldcontext);
345361

346362
/* The initial running transactions array must be empty. */
@@ -366,10 +382,6 @@ FreeSnapshotBuilder(SnapBuild *builder)
366382

367383
/* other resources are deallocated via memory context reset */
368384
MemoryContextDelete(context);
369-
370-
/* InitialRunningXacts is freed along with the context */
371-
NInitialRunningXacts=0;
372-
InitialRunningXacts=NULL;
373385
}
374386

375387
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp