Commit d9b0767b authored by Amit Kapila's avatar Amit Kapila

Fix the warnings introduced in commit ce0fdbfe.

Author: Amit Kapila
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/1610789.1613170207@sss.pgh.pa.us
parent 637668fb
...@@ -715,7 +715,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data) ...@@ -715,7 +715,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
* the origin might be already removed. For these reasons, * the origin might be already removed. For these reasons,
* passing missing_ok = true. * passing missing_ok = true.
*/ */
ReplicationOriginNameForTablesync(sub->oid, relid, originname); ReplicationOriginNameForTablesync(sub->oid, relid, originname,
sizeof(originname));
replorigin_drop_by_name(originname, true, false); replorigin_drop_by_name(originname, true, false);
} }
...@@ -749,7 +750,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data) ...@@ -749,7 +750,8 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
* dropped slots and fail. For these reasons, we allow * dropped slots and fail. For these reasons, we allow
* missing_ok = true for the drop. * missing_ok = true for the drop.
*/ */
ReplicationSlotNameForTablesync(sub->oid, sub_remove_rels[off].relid, syncslotname); ReplicationSlotNameForTablesync(sub->oid, sub_remove_rels[off].relid,
syncslotname, sizeof(syncslotname));
ReplicationSlotDropAtPubNode(wrconn, syncslotname, true); ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
} }
} }
...@@ -1174,7 +1176,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) ...@@ -1174,7 +1176,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
* worker so passing missing_ok = true. This can happen for the states * worker so passing missing_ok = true. This can happen for the states
* before SUBREL_STATE_FINISHEDCOPY. * before SUBREL_STATE_FINISHEDCOPY.
*/ */
ReplicationOriginNameForTablesync(subid, relid, originname); ReplicationOriginNameForTablesync(subid, relid, originname,
sizeof(originname));
replorigin_drop_by_name(originname, true, false); replorigin_drop_by_name(originname, true, false);
} }
...@@ -1254,7 +1257,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) ...@@ -1254,7 +1257,8 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
{ {
char syncslotname[NAMEDATALEN] = {0}; char syncslotname[NAMEDATALEN] = {0};
ReplicationSlotNameForTablesync(subid, relid, syncslotname); ReplicationSlotNameForTablesync(subid, relid, syncslotname,
sizeof(syncslotname));
ReplicationSlotDropAtPubNode(wrconn, syncslotname, true); ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
} }
} }
...@@ -1532,7 +1536,8 @@ ReportSlotConnectionError(List *rstates, Oid subid, char *slotname, char *err) ...@@ -1532,7 +1536,8 @@ ReportSlotConnectionError(List *rstates, Oid subid, char *slotname, char *err)
{ {
char syncslotname[NAMEDATALEN] = {0}; char syncslotname[NAMEDATALEN] = {0};
ReplicationSlotNameForTablesync(subid, relid, syncslotname); ReplicationSlotNameForTablesync(subid, relid, syncslotname,
sizeof(syncslotname));
elog(WARNING, "could not drop tablesync replication slot \"%s\"", elog(WARNING, "could not drop tablesync replication slot \"%s\"",
syncslotname); syncslotname);
} }
......
...@@ -314,7 +314,8 @@ process_syncing_tables_for_sync(XLogRecPtr current_lsn) ...@@ -314,7 +314,8 @@ process_syncing_tables_for_sync(XLogRecPtr current_lsn)
*/ */
ReplicationSlotNameForTablesync(MyLogicalRepWorker->subid, ReplicationSlotNameForTablesync(MyLogicalRepWorker->subid,
MyLogicalRepWorker->relid, MyLogicalRepWorker->relid,
syncslotname); syncslotname,
sizeof(syncslotname));
/* /*
* It is important to give an error if we are unable to drop the slot, * 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) ...@@ -462,7 +463,8 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
*/ */
ReplicationOriginNameForTablesync(MyLogicalRepWorker->subid, ReplicationOriginNameForTablesync(MyLogicalRepWorker->subid,
rstate->relid, rstate->relid,
originname); originname,
sizeof(originname));
replorigin_drop_by_name(originname, true, false); replorigin_drop_by_name(originname, true, false);
/* /*
...@@ -871,27 +873,20 @@ copy_table(Relation rel) ...@@ -871,27 +873,20 @@ copy_table(Relation rel)
* pg_%u_sync_%u_UINT64_FORMAT (3 + 10 + 6 + 10 + 20 + '\0'), the maximum * pg_%u_sync_%u_UINT64_FORMAT (3 + 10 + 6 + 10 + 20 + '\0'), the maximum
* length of slot_name will be 50. * length of slot_name will be 50.
* *
* The returned slot name is either: * The returned slot name is stored in the supplied buffer (syncslotname) with
* - stored in the supplied buffer (syncslotname), or * the given size.
* - palloc'ed in current memory context (if syncslotname = NULL).
* *
* Note: We don't use the subscription slot name as part of tablesync slot name * Note: We don't use the subscription slot name as part of tablesync slot name
* because we are responsible for cleaning up these slots and it could become * because we are responsible for cleaning up these slots and it could become
* impossible to recalculate what name to cleanup if the subscription slot name * impossible to recalculate what name to cleanup if the subscription slot name
* had changed. * had changed.
*/ */
char * void
ReplicationSlotNameForTablesync(Oid suboid, Oid relid, ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
char syncslotname[NAMEDATALEN]) char *syncslotname, int szslot)
{ {
if (syncslotname) snprintf(syncslotname, szslot, "pg_%u_sync_%u_" UINT64_FORMAT, suboid,
sprintf(syncslotname, "pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid, relid, GetSystemIdentifier());
GetSystemIdentifier());
else
syncslotname = psprintf("pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid,
GetSystemIdentifier());
return syncslotname;
} }
/* /*
...@@ -901,9 +896,9 @@ ReplicationSlotNameForTablesync(Oid suboid, Oid relid, ...@@ -901,9 +896,9 @@ ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
*/ */
void void
ReplicationOriginNameForTablesync(Oid suboid, Oid relid, ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
char originname[NAMEDATALEN]) char *originname, int szorgname)
{ {
snprintf(originname, NAMEDATALEN, "pg_%u_%u", suboid, relid); snprintf(originname, szorgname, "pg_%u_%u", suboid, relid);
} }
/* /*
...@@ -951,9 +946,11 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos) ...@@ -951,9 +946,11 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
} }
/* Calculate the name of the tablesync slot. */ /* Calculate the name of the tablesync slot. */
slotname = ReplicationSlotNameForTablesync(MySubscription->oid, slotname = (char *) palloc(NAMEDATALEN);
MyLogicalRepWorker->relid, ReplicationSlotNameForTablesync(MySubscription->oid,
NULL /* use palloc */ ); MyLogicalRepWorker->relid,
slotname,
NAMEDATALEN);
/* /*
* Here we use the slot name instead of the subscription name as the * Here we use the slot name instead of the subscription name as the
...@@ -972,7 +969,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos) ...@@ -972,7 +969,8 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
/* Assign the origin tracking record name. */ /* Assign the origin tracking record name. */
ReplicationOriginNameForTablesync(MySubscription->oid, ReplicationOriginNameForTablesync(MySubscription->oid,
MyLogicalRepWorker->relid, MyLogicalRepWorker->relid,
originname); originname,
sizeof(originname));
if (MyLogicalRepWorker->relstate == SUBREL_STATE_DATASYNC) if (MyLogicalRepWorker->relstate == SUBREL_STATE_DATASYNC)
{ {
......
...@@ -212,7 +212,7 @@ extern bool ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive); ...@@ -212,7 +212,7 @@ extern bool ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive);
extern void ReplicationSlotsDropDBSlots(Oid dboid); extern void ReplicationSlotsDropDBSlots(Oid dboid);
extern void InvalidateObsoleteReplicationSlots(XLogSegNo oldestSegno); extern void InvalidateObsoleteReplicationSlots(XLogSegNo oldestSegno);
extern ReplicationSlot *SearchNamedReplicationSlot(const char *name); extern ReplicationSlot *SearchNamedReplicationSlot(const char *name);
extern char *ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname); extern void ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname, int szslot);
extern void ReplicationSlotDropAtPubNode(WalReceiverConn *wrconn, char *slotname, bool missing_ok); extern void ReplicationSlotDropAtPubNode(WalReceiverConn *wrconn, char *slotname, bool missing_ok);
extern void StartupReplicationSlots(void); extern void StartupReplicationSlots(void);
......
...@@ -82,7 +82,8 @@ extern void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker); ...@@ -82,7 +82,8 @@ extern void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker);
extern int logicalrep_sync_worker_count(Oid subid); extern int logicalrep_sync_worker_count(Oid subid);
extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname); extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
char *originname, int szorgname);
extern char *LogicalRepSyncTableStart(XLogRecPtr *origin_startpos); extern char *LogicalRepSyncTableStart(XLogRecPtr *origin_startpos);
void process_syncing_tables(XLogRecPtr current_lsn); void process_syncing_tables(XLogRecPtr current_lsn);
......
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