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

Appearance settings

Commit d9b0767

Browse filesBrowse files
author
Amit Kapila
committed
Fix the warnings introduced in commit ce0fdbf.
Author: Amit Kapila Reviewed-by: Tom Lane Discussion: https://postgr.es/m/1610789.1613170207@sss.pgh.pa.us
1 parent 637668f commit d9b0767
Copy full SHA for d9b0767

File tree

Expand file treeCollapse file tree

4 files changed

+32
-28
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+32
-28
lines changed

‎src/backend/commands/subscriptioncmds.c

Copy file name to clipboardExpand all lines: src/backend/commands/subscriptioncmds.c
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
715715
* the origin might be already removed. For these reasons,
716716
* passing missing_ok = true.
717717
*/
718-
ReplicationOriginNameForTablesync(sub->oid, relid, originname);
718+
ReplicationOriginNameForTablesync(sub->oid, relid, originname,
719+
sizeof(originname));
719720
replorigin_drop_by_name(originname, true, false);
720721
}
721722

@@ -749,7 +750,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
749750
* dropped slots and fail. For these reasons, we allow
750751
* missing_ok = true for the drop.
751752
*/
752-
ReplicationSlotNameForTablesync(sub->oid, sub_remove_rels[off].relid, syncslotname);
753+
ReplicationSlotNameForTablesync(sub->oid, sub_remove_rels[off].relid,
754+
syncslotname, sizeof(syncslotname));
753755
ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
754756
}
755757
}
@@ -1174,7 +1176,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
11741176
* worker so passing missing_ok = true. This can happen for the states
11751177
* before SUBREL_STATE_FINISHEDCOPY.
11761178
*/
1177-
ReplicationOriginNameForTablesync(subid, relid, originname);
1179+
ReplicationOriginNameForTablesync(subid, relid, originname,
1180+
sizeof(originname));
11781181
replorigin_drop_by_name(originname, true, false);
11791182
}
11801183

@@ -1254,7 +1257,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
12541257
{
12551258
char syncslotname[NAMEDATALEN] = {0};
12561259

1257-
ReplicationSlotNameForTablesync(subid, relid, syncslotname);
1260+
ReplicationSlotNameForTablesync(subid, relid, syncslotname,
1261+
sizeof(syncslotname));
12581262
ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
12591263
}
12601264
}
@@ -1532,7 +1536,8 @@ ReportSlotConnectionError(List *rstates, Oid subid, char *slotname, char *err)
15321536
{
15331537
char syncslotname[NAMEDATALEN] = {0};
15341538

1535-
ReplicationSlotNameForTablesync(subid, relid, syncslotname);
1539+
ReplicationSlotNameForTablesync(subid, relid, syncslotname,
1540+
sizeof(syncslotname));
15361541
elog(WARNING, "could not drop tablesync replication slot \"%s\"",
15371542
syncslotname);
15381543
}

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

Copy file name to clipboardExpand all lines: src/backend/replication/logical/tablesync.c
+19-21Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ process_syncing_tables_for_sync(XLogRecPtr current_lsn)
314314
*/
315315
ReplicationSlotNameForTablesync(MyLogicalRepWorker->subid,
316316
MyLogicalRepWorker->relid,
317-
syncslotname);
317+
syncslotname,
318+
sizeof(syncslotname));
318319

319320
/*
320321
* It is important to give an error if we are unable to drop the slot,
@@ -462,7 +463,8 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
462463
*/
463464
ReplicationOriginNameForTablesync(MyLogicalRepWorker->subid,
464465
rstate->relid,
465-
originname);
466+
originname,
467+
sizeof(originname));
466468
replorigin_drop_by_name(originname, true, false);
467469

468470
/*
@@ -871,27 +873,20 @@ copy_table(Relation rel)
871873
* pg_%u_sync_%u_UINT64_FORMAT (3 + 10 + 6 + 10 + 20 + '\0'), the maximum
872874
* length of slot_name will be 50.
873875
*
874-
* The returned slot name is either:
875-
* - stored in the supplied buffer (syncslotname), or
876-
* - palloc'ed in current memory context (if syncslotname = NULL).
876+
* The returned slot name is stored in the supplied buffer (syncslotname) with
877+
* the given size.
877878
*
878879
* Note: We don't use the subscription slot name as part of tablesync slot name
879880
* because we are responsible for cleaning up these slots and it could become
880881
* impossible to recalculate what name to cleanup if the subscription slot name
881882
* had changed.
882883
*/
883-
char *
884+
void
884885
ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
885-
char syncslotname[NAMEDATALEN])
886+
char *syncslotname, int szslot)
886887
{
887-
if (syncslotname)
888-
sprintf(syncslotname, "pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid,
889-
GetSystemIdentifier());
890-
else
891-
syncslotname = psprintf("pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid,
892-
GetSystemIdentifier());
893-
894-
return syncslotname;
888+
snprintf(syncslotname, szslot, "pg_%u_sync_%u_" UINT64_FORMAT, suboid,
889+
relid, GetSystemIdentifier());
895890
}
896891

897892
/*
@@ -901,9 +896,9 @@ ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
901896
*/
902897
void
903898
ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
904-
char originname[NAMEDATALEN])
899+
char *originname, int szorgname)
905900
{
906-
snprintf(originname, NAMEDATALEN, "pg_%u_%u", suboid, relid);
901+
snprintf(originname, szorgname, "pg_%u_%u", suboid, relid);
907902
}
908903

909904
/*
@@ -951,9 +946,11 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
951946
}
952947

953948
/* Calculate the name of the tablesync slot. */
954-
slotname = ReplicationSlotNameForTablesync(MySubscription->oid,
955-
MyLogicalRepWorker->relid,
956-
NULL /* use palloc */ );
949+
slotname = (char *) palloc(NAMEDATALEN);
950+
ReplicationSlotNameForTablesync(MySubscription->oid,
951+
MyLogicalRepWorker->relid,
952+
slotname,
953+
NAMEDATALEN);
957954

958955
/*
959956
* Here we use the slot name instead of the subscription name as the
@@ -972,7 +969,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
972969
/* Assign the origin tracking record name. */
973970
ReplicationOriginNameForTablesync(MySubscription->oid,
974971
MyLogicalRepWorker->relid,
975-
originname);
972+
originname,
973+
sizeof(originname));
976974

977975
if (MyLogicalRepWorker->relstate == SUBREL_STATE_DATASYNC)
978976
{

‎src/include/replication/slot.h

Copy file name to clipboardExpand all lines: src/include/replication/slot.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ extern bool ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive);
212212
extern void ReplicationSlotsDropDBSlots(Oid dboid);
213213
extern void InvalidateObsoleteReplicationSlots(XLogSegNo oldestSegno);
214214
extern ReplicationSlot *SearchNamedReplicationSlot(const char *name);
215-
extern char *ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname);
215+
extern void ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname, int szslot);
216216
extern void ReplicationSlotDropAtPubNode(WalReceiverConn *wrconn, char *slotname, bool missing_ok);
217217

218218
extern void StartupReplicationSlots(void);

‎src/include/replication/worker_internal.h

Copy file name to clipboardExpand all lines: src/include/replication/worker_internal.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ extern void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker);
8282

8383
extern int logicalrep_sync_worker_count(Oid subid);
8484

85-
extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname);
85+
extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
86+
char *originname, int szorgname);
8687
extern char *LogicalRepSyncTableStart(XLogRecPtr *origin_startpos);
8788

8889
void process_syncing_tables(XLogRecPtr current_lsn);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.