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

Commite73ca79

Browse files
committed
Move the replication lag tracker into heap memory.
Andres Freund complained about the 128KB of .bss occupied by LagTracker.It's only needed in the walsender process, so allocate it in heapmemory there.Author: Thomas MunroDiscussion:https://postgr.es/m/20181015200754.7y7zfuzsoux2c4ya%40alap3.anarazel.de
1 parentd48da36 commite73ca79

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

‎src/backend/replication/walsender.c

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ typedef struct
211211
#defineLAG_TRACKER_BUFFER_SIZE 8192
212212

213213
/* A mechanism for tracking replication lag. */
214-
staticstruct
214+
typedefstruct
215215
{
216216
XLogRecPtrlast_lsn;
217217
WalTimeSamplebuffer[LAG_TRACKER_BUFFER_SIZE];
@@ -220,6 +220,8 @@ static struct
220220
WalTimeSamplelast_read[NUM_SYNC_REP_WAIT_MODE];
221221
}LagTracker;
222222

223+
staticLagTracker*lag_tracker;
224+
223225
/* Signal handlers */
224226
staticvoidWalSndLastCycleHandler(SIGNAL_ARGS);
225227

@@ -282,7 +284,7 @@ InitWalSender(void)
282284
SendPostmasterSignal(PMSIGNAL_ADVANCE_STATE_MACHINE);
283285

284286
/* Initialize empty timestamp buffer for lag tracking. */
285-
memset(&LagTracker,0,sizeof(LagTracker));
287+
lag_tracker=MemoryContextAllocZero(TopMemoryContext,sizeof(LagTracker));
286288
}
287289

288290
/*
@@ -3439,21 +3441,21 @@ LagTrackerWrite(XLogRecPtr lsn, TimestampTz local_flush_time)
34393441
* If the lsn hasn't advanced since last time, then do nothing. This way
34403442
* we only record a new sample when new WAL has been written.
34413443
*/
3442-
if (LagTracker.last_lsn==lsn)
3444+
if (lag_tracker->last_lsn==lsn)
34433445
return;
3444-
LagTracker.last_lsn=lsn;
3446+
lag_tracker->last_lsn=lsn;
34453447

34463448
/*
34473449
* If advancing the write head of the circular buffer would crash into any
34483450
* of the read heads, then the buffer is full. In other words, the
34493451
* slowest reader (presumably apply) is the one that controls the release
34503452
* of space.
34513453
*/
3452-
new_write_head= (LagTracker.write_head+1) %LAG_TRACKER_BUFFER_SIZE;
3454+
new_write_head= (lag_tracker->write_head+1) %LAG_TRACKER_BUFFER_SIZE;
34533455
buffer_full= false;
34543456
for (i=0;i<NUM_SYNC_REP_WAIT_MODE;++i)
34553457
{
3456-
if (new_write_head==LagTracker.read_heads[i])
3458+
if (new_write_head==lag_tracker->read_heads[i])
34573459
buffer_full= true;
34583460
}
34593461

@@ -3464,17 +3466,17 @@ LagTrackerWrite(XLogRecPtr lsn, TimestampTz local_flush_time)
34643466
*/
34653467
if (buffer_full)
34663468
{
3467-
new_write_head=LagTracker.write_head;
3468-
if (LagTracker.write_head>0)
3469-
LagTracker.write_head--;
3469+
new_write_head=lag_tracker->write_head;
3470+
if (lag_tracker->write_head>0)
3471+
lag_tracker->write_head--;
34703472
else
3471-
LagTracker.write_head=LAG_TRACKER_BUFFER_SIZE-1;
3473+
lag_tracker->write_head=LAG_TRACKER_BUFFER_SIZE-1;
34723474
}
34733475

34743476
/* Store a sample at the current write head position. */
3475-
LagTracker.buffer[LagTracker.write_head].lsn=lsn;
3476-
LagTracker.buffer[LagTracker.write_head].time=local_flush_time;
3477-
LagTracker.write_head=new_write_head;
3477+
lag_tracker->buffer[lag_tracker->write_head].lsn=lsn;
3478+
lag_tracker->buffer[lag_tracker->write_head].time=local_flush_time;
3479+
lag_tracker->write_head=new_write_head;
34783480
}
34793481

34803482
/*
@@ -3496,14 +3498,14 @@ LagTrackerRead(int head, XLogRecPtr lsn, TimestampTz now)
34963498
TimestampTztime=0;
34973499

34983500
/* Read all unread samples up to this LSN or end of buffer. */
3499-
while (LagTracker.read_heads[head]!=LagTracker.write_head&&
3500-
LagTracker.buffer[LagTracker.read_heads[head]].lsn <=lsn)
3501+
while (lag_tracker->read_heads[head]!=lag_tracker->write_head&&
3502+
lag_tracker->buffer[lag_tracker->read_heads[head]].lsn <=lsn)
35013503
{
3502-
time=LagTracker.buffer[LagTracker.read_heads[head]].time;
3503-
LagTracker.last_read[head]=
3504-
LagTracker.buffer[LagTracker.read_heads[head]];
3505-
LagTracker.read_heads[head]=
3506-
(LagTracker.read_heads[head]+1) %LAG_TRACKER_BUFFER_SIZE;
3504+
time=lag_tracker->buffer[lag_tracker->read_heads[head]].time;
3505+
lag_tracker->last_read[head]=
3506+
lag_tracker->buffer[lag_tracker->read_heads[head]];
3507+
lag_tracker->read_heads[head]=
3508+
(lag_tracker->read_heads[head]+1) %LAG_TRACKER_BUFFER_SIZE;
35073509
}
35083510

35093511
/*
@@ -3513,8 +3515,8 @@ LagTrackerRead(int head, XLogRecPtr lsn, TimestampTz now)
35133515
* interpolation at the beginning of the next burst of WAL after a period
35143516
* of idleness.
35153517
*/
3516-
if (LagTracker.read_heads[head]==LagTracker.write_head)
3517-
LagTracker.last_read[head].time=0;
3518+
if (lag_tracker->read_heads[head]==lag_tracker->write_head)
3519+
lag_tracker->last_read[head].time=0;
35183520

35193521
if (time>now)
35203522
{
@@ -3532,17 +3534,17 @@ LagTrackerRead(int head, XLogRecPtr lsn, TimestampTz now)
35323534
* eventually start moving again and cross one of our samples before
35333535
* we can show the lag increasing.
35343536
*/
3535-
if (LagTracker.read_heads[head]==LagTracker.write_head)
3537+
if (lag_tracker->read_heads[head]==lag_tracker->write_head)
35363538
{
35373539
/* There are no future samples, so we can't interpolate. */
35383540
return-1;
35393541
}
3540-
elseif (LagTracker.last_read[head].time!=0)
3542+
elseif (lag_tracker->last_read[head].time!=0)
35413543
{
35423544
/* We can interpolate between last_read and the next sample. */
35433545
doublefraction;
3544-
WalTimeSampleprev=LagTracker.last_read[head];
3545-
WalTimeSamplenext=LagTracker.buffer[LagTracker.read_heads[head]];
3546+
WalTimeSampleprev=lag_tracker->last_read[head];
3547+
WalTimeSamplenext=lag_tracker->buffer[lag_tracker->read_heads[head]];
35463548

35473549
if (lsn<prev.lsn)
35483550
{
@@ -3579,7 +3581,7 @@ LagTrackerRead(int head, XLogRecPtr lsn, TimestampTz now)
35793581
* standby reaches the future sample the best we can do is report
35803582
* the hypothetical lag if that sample were to be replayed now.
35813583
*/
3582-
time=LagTracker.buffer[LagTracker.read_heads[head]].time;
3584+
time=lag_tracker->buffer[lag_tracker->read_heads[head]].time;
35833585
}
35843586
}
35853587

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp