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

Commit8048404

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 parent36ac359 commit8048404

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
@@ -144,7 +144,9 @@ typedef struct ReplicationStateOnDisk
144144

145145
typedefstructReplicationStateCtl
146146
{
147+
/* Tranche to use for per-origin LWLocks */
147148
inttranche_id;
149+
/* Array of length max_replication_slots */
148150
ReplicationStatestates[FLEXIBLE_ARRAY_MEMBER];
149151
}ReplicationStateCtl;
150152

@@ -161,6 +163,10 @@ TimestampTz replorigin_session_origin_timestamp = 0;
161163
* max_replication_slots?
162164
*/
163165
staticReplicationState*replication_states;
166+
167+
/*
168+
* Actual shared memory block (replication_states[] is now part of this).
169+
*/
164170
staticReplicationStateCtl*replication_states_ctl;
165171

166172
/*
@@ -476,7 +482,7 @@ ReplicationOriginShmemSize(void)
476482
/*
477483
* XXX: max_replication_slots is arguably the wrong thing to use, as here
478484
* we keep the replay state of *remote* transactions. But for now it seems
479-
* sufficient to reuse it,lest we introduce a separate GUC.
485+
* sufficient to reuse it,rather than introduce a separate GUC.
480486
*/
481487
if (max_replication_slots==0)
482488
returnsize;
@@ -506,9 +512,9 @@ ReplicationOriginShmemInit(void)
506512
{
507513
inti;
508514

509-
replication_states_ctl->tranche_id=LWTRANCHE_REPLICATION_ORIGIN_STATE;
515+
MemSet(replication_states_ctl,0,ReplicationOriginShmemSize());
510516

511-
MemSet(replication_states,0,ReplicationOriginShmemSize());
517+
replication_states_ctl->tranche_id=LWTRANCHE_REPLICATION_ORIGIN_STATE;
512518

513519
for (i=0;i<max_replication_slots;i++)
514520
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp