mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Add a common function to generate the origin name.
Make a common replication origin name formatting function to replace multiple snprintf() expressions. This also includes logic previously done by ReplicationOriginNameForTablesync(). This makes the code to generate the origin name consistent among apply worker and tablesync worker. Author: Peter Smith Reviewed-By: Aleksander Alekseev Discussion: https://postgr.es/m/CAHut%2BPsa8hhfSE6ozUK-ih7GkQziAVAf4f3bqiXEj2nQiu-43g%40mail.gmail.com
This commit is contained in:
@@ -353,10 +353,10 @@ process_syncing_tables_for_sync(XLogRecPtr current_lsn)
|
||||
*/
|
||||
StartTransactionCommand();
|
||||
|
||||
ReplicationOriginNameForTablesync(MyLogicalRepWorker->subid,
|
||||
MyLogicalRepWorker->relid,
|
||||
originname,
|
||||
sizeof(originname));
|
||||
ReplicationOriginNameForLogicalRep(MyLogicalRepWorker->subid,
|
||||
MyLogicalRepWorker->relid,
|
||||
originname,
|
||||
sizeof(originname));
|
||||
|
||||
/*
|
||||
* Resetting the origin session removes the ownership of the slot.
|
||||
@@ -505,10 +505,10 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
|
||||
* error while dropping we won't restart it to drop the
|
||||
* origin. So passing missing_ok = true.
|
||||
*/
|
||||
ReplicationOriginNameForTablesync(MyLogicalRepWorker->subid,
|
||||
rstate->relid,
|
||||
originname,
|
||||
sizeof(originname));
|
||||
ReplicationOriginNameForLogicalRep(MyLogicalRepWorker->subid,
|
||||
rstate->relid,
|
||||
originname,
|
||||
sizeof(originname));
|
||||
replorigin_drop_by_name(originname, true, false);
|
||||
|
||||
/*
|
||||
@@ -1193,18 +1193,6 @@ ReplicationSlotNameForTablesync(Oid suboid, Oid relid,
|
||||
relid, GetSystemIdentifier());
|
||||
}
|
||||
|
||||
/*
|
||||
* Form the origin name for tablesync.
|
||||
*
|
||||
* Return the name in the supplied buffer.
|
||||
*/
|
||||
void
|
||||
ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
|
||||
char *originname, Size szorgname)
|
||||
{
|
||||
snprintf(originname, szorgname, "pg_%u_%u", suboid, relid);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start syncing the table in the sync worker.
|
||||
*
|
||||
@@ -1274,10 +1262,10 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
|
||||
MyLogicalRepWorker->relstate == SUBREL_STATE_FINISHEDCOPY);
|
||||
|
||||
/* Assign the origin tracking record name. */
|
||||
ReplicationOriginNameForTablesync(MySubscription->oid,
|
||||
MyLogicalRepWorker->relid,
|
||||
originname,
|
||||
sizeof(originname));
|
||||
ReplicationOriginNameForLogicalRep(MySubscription->oid,
|
||||
MyLogicalRepWorker->relid,
|
||||
originname,
|
||||
sizeof(originname));
|
||||
|
||||
if (MyLogicalRepWorker->relstate == SUBREL_STATE_DATASYNC)
|
||||
{
|
||||
|
||||
@@ -364,6 +364,30 @@ static void apply_error_callback(void *arg);
|
||||
static inline void set_apply_error_context_xact(TransactionId xid, XLogRecPtr lsn);
|
||||
static inline void reset_apply_error_context_info(void);
|
||||
|
||||
/*
|
||||
* Form the origin name for the subscription.
|
||||
*
|
||||
* This is a common function for tablesync and other workers. Tablesync workers
|
||||
* must pass a valid relid. Other callers must pass relid = InvalidOid.
|
||||
*
|
||||
* Return the name in the supplied buffer.
|
||||
*/
|
||||
void
|
||||
ReplicationOriginNameForLogicalRep(Oid suboid, Oid relid,
|
||||
char *originname, Size szoriginname)
|
||||
{
|
||||
if (OidIsValid(relid))
|
||||
{
|
||||
/* Replication origin name for tablesync workers. */
|
||||
snprintf(originname, szoriginname, "pg_%u_%u", suboid, relid);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Replication origin name for non-tablesync workers. */
|
||||
snprintf(originname, szoriginname, "pg_%u", suboid);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Should this worker apply changes for given relation.
|
||||
*
|
||||
@@ -3679,10 +3703,10 @@ ApplyWorkerMain(Datum main_arg)
|
||||
* Allocate the origin name in long-lived context for error context
|
||||
* message.
|
||||
*/
|
||||
ReplicationOriginNameForTablesync(MySubscription->oid,
|
||||
MyLogicalRepWorker->relid,
|
||||
originname,
|
||||
sizeof(originname));
|
||||
ReplicationOriginNameForLogicalRep(MySubscription->oid,
|
||||
MyLogicalRepWorker->relid,
|
||||
originname,
|
||||
sizeof(originname));
|
||||
apply_error_callback_arg.origin_name = MemoryContextStrdup(ApplyContext,
|
||||
originname);
|
||||
}
|
||||
@@ -3707,7 +3731,8 @@ ApplyWorkerMain(Datum main_arg)
|
||||
|
||||
/* Setup replication origin tracking. */
|
||||
StartTransactionCommand();
|
||||
snprintf(originname, sizeof(originname), "pg_%u", MySubscription->oid);
|
||||
ReplicationOriginNameForLogicalRep(MySubscription->oid, InvalidOid,
|
||||
originname, sizeof(originname));
|
||||
originid = replorigin_by_name(originname, true);
|
||||
if (!OidIsValid(originid))
|
||||
originid = replorigin_create(originname);
|
||||
|
||||
Reference in New Issue
Block a user