Commit cca57c1d authored by Amit Kapila's avatar Amit Kapila

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/20210319185247.ldebgpdaxsowiflw@alap3.anarazel.de
parent 20661c15
......@@ -64,6 +64,7 @@
#include "storage/pg_shmem.h"
#include "storage/proc.h"
#include "storage/procsignal.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
......@@ -1539,7 +1540,7 @@ pgstat_reset_replslot_counter(const char *name)
if (SlotIsPhysical(slot))
return;
strlcpy(msg.m_slotname, name, NAMEDATALEN);
namestrcpy(&msg.m_slotname, name);
msg.clearall = false;
}
else
......@@ -1812,10 +1813,7 @@ pgstat_report_tempfile(size_t filesize)
* ----------
*/
void
pgstat_report_replslot(const char *slotname, PgStat_Counter spilltxns,
PgStat_Counter spillcount, PgStat_Counter spillbytes,
PgStat_Counter streamtxns, PgStat_Counter streamcount,
PgStat_Counter streambytes)
pgstat_report_replslot(const PgStat_ReplSlotStats *repSlotStat)
{
PgStat_MsgReplSlot msg;
......@@ -1823,14 +1821,14 @@ pgstat_report_replslot(const char *slotname, PgStat_Counter spilltxns,
* Prepare and send the message
*/
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
strlcpy(msg.m_slotname, slotname, NAMEDATALEN);
namestrcpy(&msg.m_slotname, NameStr(repSlotStat->slotname));
msg.m_drop = false;
msg.m_spill_txns = spilltxns;
msg.m_spill_count = spillcount;
msg.m_spill_bytes = spillbytes;
msg.m_stream_txns = streamtxns;
msg.m_stream_count = streamcount;
msg.m_stream_bytes = streambytes;
msg.m_spill_txns = repSlotStat->spill_txns;
msg.m_spill_count = repSlotStat->spill_count;
msg.m_spill_bytes = repSlotStat->spill_bytes;
msg.m_stream_txns = repSlotStat->stream_txns;
msg.m_stream_count = repSlotStat->stream_count;
msg.m_stream_bytes = repSlotStat->stream_bytes;
pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
}
......@@ -1846,7 +1844,7 @@ pgstat_report_replslot_drop(const char *slotname)
PgStat_MsgReplSlot msg;
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
strlcpy(msg.m_slotname, slotname, NAMEDATALEN);
namestrcpy(&msg.m_slotname, slotname);
msg.m_drop = true;
pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
}
......@@ -5202,7 +5200,7 @@ pgstat_recv_resetreplslotcounter(PgStat_MsgResetreplslotcounter *msg,
else
{
/* Get the index of replication slot statistics to reset */
idx = pgstat_replslot_index(msg->m_slotname, false);
idx = pgstat_replslot_index(NameStr(msg->m_slotname), false);
/*
* 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)
* Get the index of replication slot statistics. On dropping, we don't
* create the new statistics.
*/
idx = pgstat_replslot_index(msg->m_slotname, !msg->m_drop);
idx = pgstat_replslot_index(NameStr(msg->m_slotname), !msg->m_drop);
/*
* 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)
Assert(nReplSlotStats <= max_replication_slots);
for (i = 0; i < nReplSlotStats; i++)
{
if (strcmp(replSlotStats[i].slotname, name) == 0)
if (namestrcmp(&replSlotStats[i].slotname, name) == 0)
return i; /* found */
}
......@@ -5776,7 +5774,7 @@ pgstat_replslot_index(const char *name, bool create_it)
/* Register new slot */
memset(&replSlotStats[nReplSlotStats], 0, sizeof(PgStat_ReplSlotStats));
strlcpy(replSlotStats[nReplSlotStats].slotname, name, NAMEDATALEN);
namestrcpy(&replSlotStats[nReplSlotStats].slotname, name);
return nReplSlotStats++;
}
......
......@@ -1773,6 +1773,7 @@ void
UpdateDecodingStats(LogicalDecodingContext *ctx)
{
ReorderBuffer *rb = ctx->reorder;
PgStat_ReplSlotStats repSlotStat;
/*
* Nothing to do if we haven't spilled or streamed anything since the last
......@@ -1790,9 +1791,15 @@ UpdateDecodingStats(LogicalDecodingContext *ctx)
(long long) rb->streamCount,
(long long) rb->streamBytes);
pgstat_report_replslot(NameStr(ctx->slot->data.name),
rb->spillTxns, rb->spillCount, rb->spillBytes,
rb->streamTxns, rb->streamCount, rb->streamBytes);
namestrcpy(&repSlotStat.slotname, NameStr(ctx->slot->data.name));
repSlotStat.spill_txns = rb->spillTxns;
repSlotStat.spill_count = rb->spillCount;
repSlotStat.spill_bytes = rb->spillBytes;
repSlotStat.stream_txns = rb->streamTxns;
repSlotStat.stream_count = rb->streamCount;
repSlotStat.stream_bytes = rb->streamBytes;
pgstat_report_replslot(&repSlotStat);
rb->spillTxns = 0;
rb->spillCount = 0;
rb->spillBytes = 0;
......
......@@ -328,7 +328,12 @@ ReplicationSlotCreate(const char *name, bool db_specific,
* ReplicationSlotAllocationLock.
*/
if (SlotIsLogical(slot))
pgstat_report_replslot(NameStr(slot->data.name), 0, 0, 0, 0, 0, 0);
{
PgStat_ReplSlotStats repSlotStat;
MemSet(&repSlotStat, 0, sizeof(PgStat_ReplSlotStats));
namestrcpy(&repSlotStat.slotname, NameStr(slot->data.name));
pgstat_report_replslot(&repSlotStat);
}
/*
* Now that the slot has been marked as in_use and active, it's safe to
......
......@@ -2328,7 +2328,7 @@ pg_stat_get_replication_slots(PG_FUNCTION_ARGS)
MemSet(values, 0, sizeof(values));
MemSet(nulls, 0, sizeof(nulls));
values[0] = PointerGetDatum(cstring_to_text(s->slotname));
values[0] = CStringGetTextDatum(NameStr(s->slotname));
values[1] = Int64GetDatum(s->spill_txns);
values[2] = Int64GetDatum(s->spill_count);
values[3] = Int64GetDatum(s->spill_bytes);
......
......@@ -393,7 +393,7 @@ typedef struct PgStat_MsgResetslrucounter
typedef struct PgStat_MsgResetreplslotcounter
{
PgStat_MsgHdr m_hdr;
char m_slotname[NAMEDATALEN];
NameData m_slotname;
bool clearall;
} PgStat_MsgResetreplslotcounter;
......@@ -540,7 +540,7 @@ typedef struct PgStat_MsgSLRU
typedef struct PgStat_MsgReplSlot
{
PgStat_MsgHdr m_hdr;
char m_slotname[NAMEDATALEN];
NameData m_slotname;
bool m_drop;
PgStat_Counter m_spill_txns;
PgStat_Counter m_spill_count;
......@@ -917,7 +917,7 @@ typedef struct PgStat_SLRUStats
*/
typedef struct PgStat_ReplSlotStats
{
char slotname[NAMEDATALEN];
NameData slotname;
PgStat_Counter spill_txns;
PgStat_Counter spill_count;
PgStat_Counter spill_bytes;
......@@ -1027,10 +1027,7 @@ extern void pgstat_report_recovery_conflict(int reason);
extern void pgstat_report_deadlock(void);
extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
extern void pgstat_report_checksum_failure(void);
extern void pgstat_report_replslot(const char *slotname, PgStat_Counter spilltxns,
PgStat_Counter spillcount, PgStat_Counter spillbytes,
PgStat_Counter streamtxns, PgStat_Counter streamcount,
PgStat_Counter streambytes);
extern void pgstat_report_replslot(const PgStat_ReplSlotStats *repSlotStat);
extern void pgstat_report_replslot_drop(const char *slotname);
extern void pgstat_initialize(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment