* the origin might be already removed. For these reasons,
* passing missing_ok = true.
*/
- ReplicationOriginNameForTablesync(sub->oid, relid, originname);
+ ReplicationOriginNameForTablesync(sub->oid, relid, originname,
+ sizeof(originname));
replorigin_drop_by_name(originname, true, false);
}
* dropped slots and fail. For these reasons, we allow
* 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);
}
}
* worker so passing missing_ok = true. This can happen for the states
* before SUBREL_STATE_FINISHEDCOPY.
*/
- ReplicationOriginNameForTablesync(subid, relid, originname);
+ ReplicationOriginNameForTablesync(subid, relid, originname,
+ sizeof(originname));
replorigin_drop_by_name(originname, true, false);
}
{
char syncslotname[NAMEDATALEN] = {0};
- ReplicationSlotNameForTablesync(subid, relid, syncslotname);
+ ReplicationSlotNameForTablesync(subid, relid, syncslotname,
+ sizeof(syncslotname));
ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
}
}
{
char syncslotname[NAMEDATALEN] = {0};
- ReplicationSlotNameForTablesync(subid, relid, syncslotname);
+ ReplicationSlotNameForTablesync(subid, relid, syncslotname,
+ sizeof(syncslotname));
elog(WARNING, "could not drop tablesync replication slot \"%s\"",
syncslotname);
}
*/
ReplicationSlotNameForTablesync(MyLogicalRepWorker->subid,
MyLogicalRepWorker->relid,
- syncslotname);
+ syncslotname,
+ sizeof(syncslotname));
/*
* It is important to give an error if we are unable to drop the slot,
*/
ReplicationOriginNameForTablesync(MyLogicalRepWorker->subid,
rstate->relid,
- originname);
+ originname,
+ sizeof(originname));
replorigin_drop_by_name(originname, true, false);
/*
* pg_%u_sync_%u_UINT64_FORMAT (3 + 10 + 6 + 10 + 20 + '\0'), the maximum
* length of slot_name will be 50.
*
- * The returned slot name is either:
- * - stored in the supplied buffer (syncslotname), or
- * - palloc'ed in current memory context (if syncslotname = NULL).
+ * The returned slot name is stored in the supplied buffer (syncslotname) with
+ * the given size.
*
* 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
* impossible to recalculate what name to cleanup if the subscription slot name
* had changed.
*/
-char *
+void
ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
- char syncslotname[NAMEDATALEN])
+ char *syncslotname, int szslot)
{
- if (syncslotname)
- sprintf(syncslotname, "pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid,
- GetSystemIdentifier());
- else
- syncslotname = psprintf("pg_%u_sync_%u_" UINT64_FORMAT, suboid, relid,
- GetSystemIdentifier());
-
- return syncslotname;
+ snprintf(syncslotname, szslot, "pg_%u_sync_%u_" UINT64_FORMAT, suboid,
+ relid, GetSystemIdentifier());
}
/*
*/
void
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);
}
/*
}
/* Calculate the name of the tablesync slot. */
- slotname = ReplicationSlotNameForTablesync(MySubscription->oid,
- MyLogicalRepWorker->relid,
- NULL /* use palloc */ );
+ slotname = (char *) palloc(NAMEDATALEN);
+ ReplicationSlotNameForTablesync(MySubscription->oid,
+ MyLogicalRepWorker->relid,
+ slotname,
+ NAMEDATALEN);
/*
* Here we use the slot name instead of the subscription name as the
/* Assign the origin tracking record name. */
ReplicationOriginNameForTablesync(MySubscription->oid,
MyLogicalRepWorker->relid,
- originname);
+ originname,
+ sizeof(originname));
if (MyLogicalRepWorker->relstate == SUBREL_STATE_DATASYNC)
{