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

Commit7e57208

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 parent7b03d3a commit7e57208

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
@@ -335,6 +335,17 @@ SnapBuildStartNextPhaseAt(SnapBuild *builder, TransactionId at)
335335
builder->was_running.was_xmax=at;
336336
}
337337

338+
/*
339+
* Memory context reset callback for clearing the array of running transactions
340+
* and subtransactions.
341+
*/
342+
staticvoid
343+
SnapBuildResetRunningXactsCallback(void*arg)
344+
{
345+
NInitialRunningXacts=0;
346+
InitialRunningXacts=NULL;
347+
}
348+
338349
/*
339350
* Allocate a new snapshot builder.
340351
*
@@ -350,6 +361,7 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
350361
MemoryContextcontext;
351362
MemoryContextoldcontext;
352363
SnapBuild*builder;
364+
MemoryContextCallback*mcallback;
353365

354366
/* allocate memory in own context, to have better accountability */
355367
context=AllocSetContextCreate(CurrentMemoryContext,
@@ -374,6 +386,10 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
374386
builder->start_decoding_at=start_lsn;
375387
builder->building_full_snapshot=need_full_snapshot;
376388

389+
mcallback=palloc0(sizeof(MemoryContextCallback));
390+
mcallback->func=SnapBuildResetRunningXactsCallback;
391+
MemoryContextRegisterResetCallback(CurrentMemoryContext,mcallback);
392+
377393
MemoryContextSwitchTo(oldcontext);
378394

379395
/* The initial running transactions array must be empty. */
@@ -399,10 +415,6 @@ FreeSnapshotBuilder(SnapBuild *builder)
399415

400416
/* other resources are deallocated via memory context reset */
401417
MemoryContextDelete(context);
402-
403-
/* InitialRunningXacts is freed along with the context */
404-
NInitialRunningXacts=0;
405-
InitialRunningXacts=NULL;
406418
}
407419

408420
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp