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

Commitee39a4b

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 parent37b5c5f commitee39a4b

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
@@ -147,7 +147,9 @@ typedef struct ReplicationStateOnDisk
147147

148148
typedefstructReplicationStateCtl
149149
{
150+
/* Tranche to use for per-origin LWLocks */
150151
inttranche_id;
152+
/* Array of length max_replication_slots */
151153
ReplicationStatestates[FLEXIBLE_ARRAY_MEMBER];
152154
}ReplicationStateCtl;
153155

@@ -164,6 +166,10 @@ TimestampTz replorigin_session_origin_timestamp = 0;
164166
* max_replication_slots?
165167
*/
166168
staticReplicationState*replication_states;
169+
170+
/*
171+
* Actual shared memory block (replication_states[] is now part of this).
172+
*/
167173
staticReplicationStateCtl*replication_states_ctl;
168174

169175
/*
@@ -479,7 +485,7 @@ ReplicationOriginShmemSize(void)
479485
/*
480486
* XXX: max_replication_slots is arguably the wrong thing to use, as here
481487
* we keep the replay state of *remote* transactions. But for now it seems
482-
* sufficient to reuse it,lest we introduce a separate GUC.
488+
* sufficient to reuse it,rather than introduce a separate GUC.
483489
*/
484490
if (max_replication_slots==0)
485491
returnsize;
@@ -509,9 +515,9 @@ ReplicationOriginShmemInit(void)
509515
{
510516
inti;
511517

512-
replication_states_ctl->tranche_id=LWTRANCHE_REPLICATION_ORIGIN;
518+
MemSet(replication_states_ctl,0,ReplicationOriginShmemSize());
513519

514-
MemSet(replication_states,0,ReplicationOriginShmemSize());
520+
replication_states_ctl->tranche_id=LWTRANCHE_REPLICATION_ORIGIN;
515521

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp