Skip to content

Commit cca57c1

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 structure rather than multiple parameters. Reported-by: Andres Freund Author: Vignesh C Reviewed-by: Sawada Masahiko, Amit Kapila Discussion: https://postgr.es/m/[email protected]
1 parent 20661c1 commit cca57c1

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
lines changed

src/backend/postmaster/pgstat.c

+15-17
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(const char *slotname, PgStat_Counter spilltxns,
1816-
PgStat_Counter spillcount, PgStat_Counter spillbytes,
1817-
PgStat_Counter streamtxns, PgStat_Counter streamcount,
1818-
PgStat_Counter streambytes)
1816+
pgstat_report_replslot(const PgStat_ReplSlotStats *repSlotStat)
18191817
{
18201818
PgStat_MsgReplSlot msg;
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_MsgReplSlot msg;
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
return i; /* 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
return nReplSlotStats++;
57825780
}

src/backend/replication/logical/logical.c

+10-3
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_ReplSlotStats repSlotStat;
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

+6-1
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_ReplSlotStats repSlotStat;
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

+1-1
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

+4-7
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ typedef struct PgStat_MsgResetslrucounter
393393
typedef struct PgStat_MsgResetreplslotcounter
394394
{
395395
PgStat_MsgHdr m_hdr;
396-
char m_slotname[NAMEDATALEN];
396+
NameData m_slotname;
397397
bool clearall;
398398
} PgStat_MsgResetreplslotcounter;
399399

@@ -540,7 +540,7 @@ typedef struct PgStat_MsgSLRU
540540
typedef struct PgStat_MsgReplSlot
541541
{
542542
PgStat_MsgHdr m_hdr;
543-
char m_slotname[NAMEDATALEN];
543+
NameData m_slotname;
544544
bool m_drop;
545545
PgStat_Counter m_spill_txns;
546546
PgStat_Counter m_spill_count;
@@ -917,7 +917,7 @@ typedef struct PgStat_SLRUStats
917917
*/
918918
typedef struct PgStat_ReplSlotStats
919919
{
920-
char slotname[NAMEDATALEN];
920+
NameData slotname;
921921
PgStat_Counter spill_txns;
922922
PgStat_Counter spill_count;
923923
PgStat_Counter spill_bytes;
@@ -1027,10 +1027,7 @@ extern void pgstat_report_recovery_conflict(int reason);
10271027
extern void pgstat_report_deadlock(void);
10281028
extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
10291029
extern void pgstat_report_checksum_failure(void);
1030-
extern void pgstat_report_replslot(const char *slotname, PgStat_Counter spilltxns,
1031-
PgStat_Counter spillcount, PgStat_Counter spillbytes,
1032-
PgStat_Counter streamtxns, PgStat_Counter streamcount,
1033-
PgStat_Counter streambytes);
1030+
extern void pgstat_report_replslot(const PgStat_ReplSlotStats *repSlotStat);
10341031
extern void pgstat_report_replslot_drop(const char *slotname);
10351032

10361033
extern void pgstat_initialize(void);

0 commit comments

Comments
 (0)