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

Commitcca57c1

Browse files
author
Amit Kapila
committed
Use NameData datatype for slotname in stats.
This will make it consistent with the other usage of slotname in the code.In the passing, change pgstat_report_replslot signature to use a structurerather than multiple parameters.Reported-by: Andres FreundAuthor: Vignesh CReviewed-by: Sawada Masahiko, Amit KapilaDiscussion:https://postgr.es/m/20210319185247.ldebgpdaxsowiflw@alap3.anarazel.de
1 parent20661c1 commitcca57c1

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include"storage/pg_shmem.h"
6565
#include"storage/proc.h"
6666
#include"storage/procsignal.h"
67+
#include"utils/builtins.h"
6768
#include"utils/guc.h"
6869
#include"utils/memutils.h"
6970
#include"utils/ps_status.h"
@@ -1539,7 +1540,7 @@ pgstat_reset_replslot_counter(const char *name)
15391540
if (SlotIsPhysical(slot))
15401541
return;
15411542

1542-
strlcpy(msg.m_slotname,name,NAMEDATALEN);
1543+
namestrcpy(&msg.m_slotname,name);
15431544
msg.clearall= false;
15441545
}
15451546
else
@@ -1812,25 +1813,22 @@ pgstat_report_tempfile(size_t filesize)
18121813
* ----------
18131814
*/
18141815
void
1815-
pgstat_report_replslot(constchar*slotname,PgStat_Counterspilltxns,
1816-
PgStat_Counterspillcount,PgStat_Counterspillbytes,
1817-
PgStat_Counterstreamtxns,PgStat_Counterstreamcount,
1818-
PgStat_Counterstreambytes)
1816+
pgstat_report_replslot(constPgStat_ReplSlotStats*repSlotStat)
18191817
{
18201818
PgStat_MsgReplSlotmsg;
18211819

18221820
/*
18231821
* Prepare and send the message
18241822
*/
18251823
pgstat_setheader(&msg.m_hdr,PGSTAT_MTYPE_REPLSLOT);
1826-
strlcpy(msg.m_slotname,slotname,NAMEDATALEN);
1824+
namestrcpy(&msg.m_slotname,NameStr(repSlotStat->slotname));
18271825
msg.m_drop= false;
1828-
msg.m_spill_txns=spilltxns;
1829-
msg.m_spill_count=spillcount;
1830-
msg.m_spill_bytes=spillbytes;
1831-
msg.m_stream_txns=streamtxns;
1832-
msg.m_stream_count=streamcount;
1833-
msg.m_stream_bytes=streambytes;
1826+
msg.m_spill_txns=repSlotStat->spill_txns;
1827+
msg.m_spill_count=repSlotStat->spill_count;
1828+
msg.m_spill_bytes=repSlotStat->spill_bytes;
1829+
msg.m_stream_txns=repSlotStat->stream_txns;
1830+
msg.m_stream_count=repSlotStat->stream_count;
1831+
msg.m_stream_bytes=repSlotStat->stream_bytes;
18341832
pgstat_send(&msg,sizeof(PgStat_MsgReplSlot));
18351833
}
18361834

@@ -1846,7 +1844,7 @@ pgstat_report_replslot_drop(const char *slotname)
18461844
PgStat_MsgReplSlotmsg;
18471845

18481846
pgstat_setheader(&msg.m_hdr,PGSTAT_MTYPE_REPLSLOT);
1849-
strlcpy(msg.m_slotname,slotname,NAMEDATALEN);
1847+
namestrcpy(&msg.m_slotname,slotname);
18501848
msg.m_drop= true;
18511849
pgstat_send(&msg,sizeof(PgStat_MsgReplSlot));
18521850
}
@@ -5202,7 +5200,7 @@ pgstat_recv_resetreplslotcounter(PgStat_MsgResetreplslotcounter *msg,
52025200
else
52035201
{
52045202
/* Get the index of replication slot statistics to reset */
5205-
idx=pgstat_replslot_index(msg->m_slotname, false);
5203+
idx=pgstat_replslot_index(NameStr(msg->m_slotname), false);
52065204

52075205
/*
52085206
* Nothing to do if the given slot entry is not found. This could
@@ -5538,7 +5536,7 @@ pgstat_recv_replslot(PgStat_MsgReplSlot *msg, int len)
55385536
* Get the index of replication slot statistics. On dropping, we don't
55395537
* create the new statistics.
55405538
*/
5541-
idx=pgstat_replslot_index(msg->m_slotname, !msg->m_drop);
5539+
idx=pgstat_replslot_index(NameStr(msg->m_slotname), !msg->m_drop);
55425540

55435541
/*
55445542
* The slot entry is not found or there is no space to accommodate the new
@@ -5763,7 +5761,7 @@ pgstat_replslot_index(const char *name, bool create_it)
57635761
Assert(nReplSlotStats <=max_replication_slots);
57645762
for (i=0;i<nReplSlotStats;i++)
57655763
{
5766-
if (strcmp(replSlotStats[i].slotname,name)==0)
5764+
if (namestrcmp(&replSlotStats[i].slotname,name)==0)
57675765
returni;/* found */
57685766
}
57695767

@@ -5776,7 +5774,7 @@ pgstat_replslot_index(const char *name, bool create_it)
57765774

57775775
/* Register new slot */
57785776
memset(&replSlotStats[nReplSlotStats],0,sizeof(PgStat_ReplSlotStats));
5779-
strlcpy(replSlotStats[nReplSlotStats].slotname,name,NAMEDATALEN);
5777+
namestrcpy(&replSlotStats[nReplSlotStats].slotname,name);
57805778

57815779
returnnReplSlotStats++;
57825780
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,7 @@ void
17731773
UpdateDecodingStats(LogicalDecodingContext*ctx)
17741774
{
17751775
ReorderBuffer*rb=ctx->reorder;
1776+
PgStat_ReplSlotStatsrepSlotStat;
17761777

17771778
/*
17781779
* Nothing to do if we haven't spilled or streamed anything since the last
@@ -1790,9 +1791,15 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
17901791
(long long)rb->streamCount,
17911792
(long long)rb->streamBytes);
17921793

1793-
pgstat_report_replslot(NameStr(ctx->slot->data.name),
1794-
rb->spillTxns,rb->spillCount,rb->spillBytes,
1795-
rb->streamTxns,rb->streamCount,rb->streamBytes);
1794+
namestrcpy(&repSlotStat.slotname,NameStr(ctx->slot->data.name));
1795+
repSlotStat.spill_txns=rb->spillTxns;
1796+
repSlotStat.spill_count=rb->spillCount;
1797+
repSlotStat.spill_bytes=rb->spillBytes;
1798+
repSlotStat.stream_txns=rb->streamTxns;
1799+
repSlotStat.stream_count=rb->streamCount;
1800+
repSlotStat.stream_bytes=rb->streamBytes;
1801+
1802+
pgstat_report_replslot(&repSlotStat);
17961803
rb->spillTxns=0;
17971804
rb->spillCount=0;
17981805
rb->spillBytes=0;

‎src/backend/replication/slot.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,12 @@ ReplicationSlotCreate(const char *name, bool db_specific,
328328
* ReplicationSlotAllocationLock.
329329
*/
330330
if (SlotIsLogical(slot))
331-
pgstat_report_replslot(NameStr(slot->data.name),0,0,0,0,0,0);
331+
{
332+
PgStat_ReplSlotStatsrepSlotStat;
333+
MemSet(&repSlotStat,0,sizeof(PgStat_ReplSlotStats));
334+
namestrcpy(&repSlotStat.slotname,NameStr(slot->data.name));
335+
pgstat_report_replslot(&repSlotStat);
336+
}
332337

333338
/*
334339
* Now that the slot has been marked as in_use and active, it's safe to

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ pg_stat_get_replication_slots(PG_FUNCTION_ARGS)
23282328
MemSet(values,0,sizeof(values));
23292329
MemSet(nulls,0,sizeof(nulls));
23302330

2331-
values[0]=PointerGetDatum(cstring_to_text(s->slotname));
2331+
values[0]=CStringGetTextDatum(NameStr(s->slotname));
23322332
values[1]=Int64GetDatum(s->spill_txns);
23332333
values[2]=Int64GetDatum(s->spill_count);
23342334
values[3]=Int64GetDatum(s->spill_bytes);

‎src/include/pgstat.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ typedef struct PgStat_MsgResetslrucounter
393393
typedefstructPgStat_MsgResetreplslotcounter
394394
{
395395
PgStat_MsgHdrm_hdr;
396-
charm_slotname[NAMEDATALEN];
396+
NameDatam_slotname;
397397
boolclearall;
398398
}PgStat_MsgResetreplslotcounter;
399399

@@ -540,7 +540,7 @@ typedef struct PgStat_MsgSLRU
540540
typedefstructPgStat_MsgReplSlot
541541
{
542542
PgStat_MsgHdrm_hdr;
543-
charm_slotname[NAMEDATALEN];
543+
NameDatam_slotname;
544544
boolm_drop;
545545
PgStat_Counterm_spill_txns;
546546
PgStat_Counterm_spill_count;
@@ -917,7 +917,7 @@ typedef struct PgStat_SLRUStats
917917
*/
918918
typedefstructPgStat_ReplSlotStats
919919
{
920-
charslotname[NAMEDATALEN];
920+
NameDataslotname;
921921
PgStat_Counterspill_txns;
922922
PgStat_Counterspill_count;
923923
PgStat_Counterspill_bytes;
@@ -1027,10 +1027,7 @@ extern void pgstat_report_recovery_conflict(int reason);
10271027
externvoidpgstat_report_deadlock(void);
10281028
externvoidpgstat_report_checksum_failures_in_db(Oiddboid,intfailurecount);
10291029
externvoidpgstat_report_checksum_failure(void);
1030-
externvoidpgstat_report_replslot(constchar*slotname,PgStat_Counterspilltxns,
1031-
PgStat_Counterspillcount,PgStat_Counterspillbytes,
1032-
PgStat_Counterstreamtxns,PgStat_Counterstreamcount,
1033-
PgStat_Counterstreambytes);
1030+
externvoidpgstat_report_replslot(constPgStat_ReplSlotStats*repSlotStat);
10341031
externvoidpgstat_report_replslot_drop(constchar*slotname);
10351032

10361033
externvoidpgstat_initialize(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp