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

Commite41aed6

Browse files
committed
pgstat: revise replication slot API in preparation for shared memory stats.
Previously the pgstat <-> replication slots API was done with on the basis ofnames. However, the upcoming move to storing stats in shared memory makes itmore convenient to use a integer as key.Change the replication slot functions to take the slot rather than the slotname, and expose ReplicationSlotIndex() to compute the index of an replicationslot. Special handling will be required for restarts, as the index is notstable across restarts. For now pgstat internally still uses names.Rename pgstat_report_replslot_{create,drop}() topgstat_{create,drop}_replslot() to match the functions for other kinds ofstats.Reviewed-By: Kyotaro Horiguchi <horikyota.ntt@gmail.com>Discussion:https://postgr.es/m/20220404041516.cctrvpadhuriawlq@alap3.anarazel.de
1 parent8b1dccd commite41aed6

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,15 @@ pgstat_vacuum_stat(void)
862862
CHECK_FOR_INTERRUPTS();
863863

864864
if (SearchNamedReplicationSlot(NameStr(slotentry->slotname), true)==NULL)
865-
pgstat_report_replslot_drop(NameStr(slotentry->slotname));
865+
{
866+
PgStat_MsgReplSlotmsg;
867+
868+
pgstat_setheader(&msg.m_hdr,PGSTAT_MTYPE_REPLSLOT);
869+
namestrcpy(&msg.m_slotname,NameStr(slotentry->slotname));
870+
msg.m_create= false;
871+
msg.m_drop= true;
872+
pgstat_send(&msg,sizeof(PgStat_MsgReplSlot));
873+
}
866874
}
867875
}
868876

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
19211921
repSlotStat.total_txns=rb->totalTxns;
19221922
repSlotStat.total_bytes=rb->totalBytes;
19231923

1924-
pgstat_report_replslot(&repSlotStat);
1924+
pgstat_report_replslot(ctx->slot,&repSlotStat);
19251925

19261926
rb->spillTxns=0;
19271927
rb->spillCount=0;

‎src/backend/replication/slot.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ ReplicationSlotCreate(const char *name, bool db_specific,
356356
* ReplicationSlotAllocationLock.
357357
*/
358358
if (SlotIsLogical(slot))
359-
pgstat_report_replslot_create(NameStr(slot->data.name));
359+
pgstat_create_replslot(slot);
360360

361361
/*
362362
* Now that the slot has been marked as in_use and active, it's safe to
@@ -399,6 +399,22 @@ SearchNamedReplicationSlot(const char *name, bool need_lock)
399399
returnslot;
400400
}
401401

402+
/*
403+
* Return the index of the replication slot in
404+
* ReplicationSlotCtl->replication_slots.
405+
*
406+
* This is mainly useful to have an efficient key for storing replication slot
407+
* stats.
408+
*/
409+
int
410+
ReplicationSlotIndex(ReplicationSlot*slot)
411+
{
412+
Assert(slot >=ReplicationSlotCtl->replication_slots&&
413+
slot<ReplicationSlotCtl->replication_slots+max_replication_slots);
414+
415+
returnslot-ReplicationSlotCtl->replication_slots;
416+
}
417+
402418
/*
403419
* Find a previously created slot and mark it as used by this process.
404420
*
@@ -746,7 +762,7 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
746762
* doesn't seem worth doing as in practice this won't happen frequently.
747763
*/
748764
if (SlotIsLogical(slot))
749-
pgstat_report_replslot_drop(NameStr(slot->data.name));
765+
pgstat_drop_replslot(slot);
750766

751767
/*
752768
* We release this at the very end, so that nobody starts trying to create

‎src/backend/utils/activity/pgstat_replslot.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pgstat_reset_replslot(const char *name)
6969
* Report replication slot statistics.
7070
*/
7171
void
72-
pgstat_report_replslot(constPgStat_StatReplSlotEntry*repSlotStat)
72+
pgstat_report_replslot(ReplicationSlot*slot,constPgStat_StatReplSlotEntry*repSlotStat)
7373
{
7474
PgStat_MsgReplSlotmsg;
7575

@@ -93,14 +93,17 @@ pgstat_report_replslot(const PgStat_StatReplSlotEntry *repSlotStat)
9393

9494
/*
9595
* Report replication slot creation.
96+
*
97+
* NB: This gets called with ReplicationSlotAllocationLock already held, be
98+
* careful about calling back into slot.c.
9699
*/
97100
void
98-
pgstat_report_replslot_create(constchar*slotname)
101+
pgstat_create_replslot(ReplicationSlot*slot)
99102
{
100103
PgStat_MsgReplSlotmsg;
101104

102105
pgstat_setheader(&msg.m_hdr,PGSTAT_MTYPE_REPLSLOT);
103-
namestrcpy(&msg.m_slotname,slotname);
106+
namestrcpy(&msg.m_slotname,NameStr(slot->data.name));
104107
msg.m_create= true;
105108
msg.m_drop= false;
106109
pgstat_send(&msg,sizeof(PgStat_MsgReplSlot));
@@ -110,12 +113,12 @@ pgstat_report_replslot_create(const char *slotname)
110113
* Report replication slot drop.
111114
*/
112115
void
113-
pgstat_report_replslot_drop(constchar*slotname)
116+
pgstat_drop_replslot(ReplicationSlot*slot)
114117
{
115118
PgStat_MsgReplSlotmsg;
116119

117120
pgstat_setheader(&msg.m_hdr,PGSTAT_MTYPE_REPLSLOT);
118-
namestrcpy(&msg.m_slotname,slotname);
121+
namestrcpy(&msg.m_slotname,NameStr(slot->data.name));
119122
msg.m_create= false;
120123
msg.m_drop= true;
121124
pgstat_send(&msg,sizeof(PgStat_MsgReplSlot));

‎src/include/pgstat.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,10 @@ extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
11371137
*/
11381138

11391139
externvoidpgstat_reset_replslot(constchar*name);
1140-
externvoidpgstat_report_replslot(constPgStat_StatReplSlotEntry*repSlotStat);
1141-
externvoidpgstat_report_replslot_create(constchar*slotname);
1142-
externvoidpgstat_report_replslot_drop(constchar*slotname);
1140+
structReplicationSlot;
1141+
externvoidpgstat_report_replslot(structReplicationSlot*slot,constPgStat_StatReplSlotEntry*repSlotStat);
1142+
externvoidpgstat_create_replslot(structReplicationSlot*slot);
1143+
externvoidpgstat_drop_replslot(structReplicationSlot*slot);
11431144

11441145

11451146
/*

‎src/include/replication/slot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ extern bool ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive);
216216
externvoidReplicationSlotsDropDBSlots(Oiddboid);
217217
externboolInvalidateObsoleteReplicationSlots(XLogSegNooldestSegno);
218218
externReplicationSlot*SearchNamedReplicationSlot(constchar*name,boolneed_lock);
219+
externintReplicationSlotIndex(ReplicationSlot*slot);
219220
externvoidReplicationSlotNameForTablesync(Oidsuboid,Oidrelid,char*syncslotname,intszslot);
220221
externvoidReplicationSlotDropAtPubNode(WalReceiverConn*wrconn,char*slotname,boolmissing_ok);
221222

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp