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

Commitc8b1c95

Browse files
committed
Fix bogus initialization of replication origin shared memory state.
The previous coding zeroed out offsetof(ReplicationStateCtl, states)more bytes than it was entitled to, as a consequence of starting thezeroing from the wrong pointer (or, if you prefer, using the wrongcalculation of how much to zero).It's unsurprising that this has not caused any reported problems,since it can be expected that the newly-allocated block is at the endof what we've used in shared memory, and we always make the shmemblock substantially bigger than minimally necessary. Nonetheless,this is wrong and it could bite us someday; plus it's a dangerousmodel for somebody to copy.This dates back to the introduction of this code (commit5aa2350),so back-patch to all supported branches.
1 parent1d84751 commitc8b1c95

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ typedef struct ReplicationStateOnDisk
148148

149149
typedefstructReplicationStateCtl
150150
{
151+
/* Tranche to use for per-origin LWLocks */
151152
inttranche_id;
153+
/* Array of length max_replication_slots */
152154
ReplicationStatestates[FLEXIBLE_ARRAY_MEMBER];
153155
}ReplicationStateCtl;
154156

@@ -165,6 +167,10 @@ TimestampTz replorigin_session_origin_timestamp = 0;
165167
* max_replication_slots?
166168
*/
167169
staticReplicationState*replication_states;
170+
171+
/*
172+
* Actual shared memory block (replication_states[] is now part of this).
173+
*/
168174
staticReplicationStateCtl*replication_states_ctl;
169175

170176
/*
@@ -480,7 +486,7 @@ ReplicationOriginShmemSize(void)
480486
/*
481487
* XXX: max_replication_slots is arguably the wrong thing to use, as here
482488
* we keep the replay state of *remote* transactions. But for now it seems
483-
* sufficient to reuse it,lest we introduce a separate GUC.
489+
* sufficient to reuse it,rather than introduce a separate GUC.
484490
*/
485491
if (max_replication_slots==0)
486492
returnsize;
@@ -510,9 +516,9 @@ ReplicationOriginShmemInit(void)
510516
{
511517
inti;
512518

513-
replication_states_ctl->tranche_id=LWTRANCHE_REPLICATION_ORIGIN;
519+
MemSet(replication_states_ctl,0,ReplicationOriginShmemSize());
514520

515-
MemSet(replication_states,0,ReplicationOriginShmemSize());
521+
replication_states_ctl->tranche_id=LWTRANCHE_REPLICATION_ORIGIN;
516522

517523
for (i=0;i<max_replication_slots;i++)
518524
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp