PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
worker_internal.h File Reference
Include dependency graph for worker_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  LogicalRepWorker
 

Typedefs

typedef struct LogicalRepWorker LogicalRepWorker
 

Functions

void logicalrep_worker_attach (int slot)
 
LogicalRepWorkerlogicalrep_worker_find (Oid subid, Oid relid, bool only_running)
 
void logicalrep_worker_launch (Oid dbid, Oid subid, const char *subname, Oid userid, Oid relid)
 
void logicalrep_worker_stop (Oid subid, Oid relid)
 
void logicalrep_worker_wakeup (Oid subid, Oid relid)
 
void logicalrep_worker_wakeup_ptr (LogicalRepWorker *worker)
 
int logicalrep_sync_worker_count (Oid subid)
 
void logicalrep_worker_sigterm (SIGNAL_ARGS)
 
char * LogicalRepSyncTableStart (XLogRecPtr *origin_startpos)
 
void process_syncing_tables (XLogRecPtr current_lsn)
 
void invalidate_syncing_table_states (Datum arg, int cacheid, uint32 hashvalue)
 
static bool am_tablesync_worker (void)
 

Variables

MemoryContext ApplyCacheContext
 
struct WalReceiverConnwrconn
 
SubscriptionMySubscription
 
LogicalRepWorkerMyLogicalRepWorker
 
bool in_remote_transaction
 
bool got_SIGTERM
 

Typedef Documentation

Function Documentation

static bool am_tablesync_worker ( void  )
inlinestatic

Definition at line 79 of file worker_internal.h.

References OidIsValid, and LogicalRepWorker::relid.

Referenced by apply_handle_commit(), apply_handle_origin(), ApplyWorkerMain(), process_syncing_tables(), and should_apply_changes_for_rel().

80 {
82 }
#define OidIsValid(objectId)
Definition: c.h:538
LogicalRepWorker * MyLogicalRepWorker
Definition: launcher.c:62
void invalidate_syncing_table_states ( Datum  arg,
int  cacheid,
uint32  hashvalue 
)

Definition at line 185 of file tablesync.c.

References table_states_valid.

Referenced by ApplyWorkerMain().

186 {
187  table_states_valid = false;
188 }
static bool table_states_valid
Definition: tablesync.c:107
int logicalrep_sync_worker_count ( Oid  subid)

Definition at line 508 of file launcher.c.

References Assert, i, LWLockHeldByMe(), max_logical_replication_workers, OidIsValid, LogicalRepWorker::relid, LogicalRepWorker::subid, and LogicalRepCtxStruct::workers.

Referenced by process_syncing_tables_for_apply().

509 {
510  int i;
511  int res = 0;
512 
513  Assert(LWLockHeldByMe(LogicalRepWorkerLock));
514 
515  /* Search for attached worker for a given subscription id. */
516  for (i = 0; i < max_logical_replication_workers; i++)
517  {
519  if (w->subid == subid && OidIsValid(w->relid))
520  res++;
521  }
522 
523  return res;
524 }
bool LWLockHeldByMe(LWLock *l)
Definition: lwlock.c:1831
LogicalRepWorker workers[FLEXIBLE_ARRAY_MEMBER]
Definition: launcher.c:70
#define OidIsValid(objectId)
Definition: c.h:538
#define Assert(condition)
Definition: c.h:675
int max_logical_replication_workers
Definition: launcher.c:59
LogicalRepCtxStruct * LogicalRepCtx
Definition: launcher.c:73
int i
void logicalrep_worker_attach ( int  slot)

Definition at line 445 of file launcher.c.

References Assert, before_shmem_exit(), ereport, errcode(), errmsg(), ERROR, logicalrep_worker_onexit(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_logical_replication_workers, MyProc, LogicalRepWorker::proc, and LogicalRepCtxStruct::workers.

Referenced by ApplyWorkerMain().

446 {
447  /* Block concurrent access. */
448  LWLockAcquire(LogicalRepWorkerLock, LW_EXCLUSIVE);
449 
450  Assert(slot >= 0 && slot < max_logical_replication_workers);
452 
454  ereport(ERROR,
455  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
456  errmsg("logical replication worker slot %d already used by "
457  "another worker", slot)));
458 
461 
462  LWLockRelease(LogicalRepWorkerLock);
463 }
PGPROC * MyProc
Definition: proc.c:67
LogicalRepWorker workers[FLEXIBLE_ARRAY_MEMBER]
Definition: launcher.c:70
int errcode(int sqlerrcode)
Definition: elog.c:575
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
LogicalRepWorker * MyLogicalRepWorker
Definition: launcher.c:62
#define ERROR
Definition: elog.h:43
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:320
#define ereport(elevel, rest)
Definition: elog.h:122
static void logicalrep_worker_onexit(int code, Datum arg)
Definition: launcher.c:488
uintptr_t Datum
Definition: postgres.h:372
#define Assert(condition)
Definition: c.h:675
int max_logical_replication_workers
Definition: launcher.c:59
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
int errmsg(const char *fmt,...)
Definition: elog.c:797
LogicalRepCtxStruct * LogicalRepCtx
Definition: launcher.c:73
LogicalRepWorker* logicalrep_worker_find ( Oid  subid,
Oid  relid,
bool  only_running 
)

Definition at line 207 of file launcher.c.

References Assert, i, IsBackendPid(), LWLockHeldByMe(), max_logical_replication_workers, NULL, PGPROC::pid, LogicalRepWorker::proc, LogicalRepWorker::relid, LogicalRepWorker::subid, and LogicalRepCtxStruct::workers.

Referenced by ApplyLauncherMain(), logicalrep_worker_stop(), logicalrep_worker_wakeup(), process_syncing_tables_for_apply(), and wait_for_sync_status_change().

208 {
209  int i;
210  LogicalRepWorker *res = NULL;
211 
212  Assert(LWLockHeldByMe(LogicalRepWorkerLock));
213 
214  /* Search for attached worker for a given subscription id. */
215  for (i = 0; i < max_logical_replication_workers; i++)
216  {
218  if (w->subid == subid && w->relid == relid &&
219  (!only_running || (w->proc && IsBackendPid(w->proc->pid))))
220  {
221  res = w;
222  break;
223  }
224  }
225 
226  return res;
227 }
bool LWLockHeldByMe(LWLock *l)
Definition: lwlock.c:1831
LogicalRepWorker workers[FLEXIBLE_ARRAY_MEMBER]
Definition: launcher.c:70
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
int max_logical_replication_workers
Definition: launcher.c:59
LogicalRepCtxStruct * LogicalRepCtx
Definition: launcher.c:73
int i
bool IsBackendPid(int pid)
Definition: procarray.c:2425
int pid
Definition: proc.h:108
void logicalrep_worker_launch ( Oid  dbid,
Oid  subid,
const char *  subname,
Oid  userid,
Oid  relid 
)

Definition at line 233 of file launcher.c.

References ApplyWorkerMain(), BackgroundWorker::bgw_flags, BackgroundWorker::bgw_main, BackgroundWorker::bgw_main_arg, BGW_MAXLEN, BackgroundWorker::bgw_name, BGW_NEVER_RESTART, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_SHMEM_ACCESS, BgWorkerStart_RecoveryFinished, LogicalRepWorker::dbid, ereport, errcode(), errhint(), errmsg(), ERROR, InvalidXLogRecPtr, LogicalRepWorker::last_lsn, LogicalRepWorker::last_recv_time, LogicalRepWorker::last_send_time, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_logical_replication_workers, max_replication_slots, MyProcPid, NULL, OidIsValid, LogicalRepWorker::proc, RegisterDynamicBackgroundWorker(), LogicalRepWorker::relid, LogicalRepWorker::relstate, LogicalRepWorker::relstate_lsn, LogicalRepWorker::reply_lsn, LogicalRepWorker::reply_time, snprintf(), LogicalRepWorker::subid, SUBREL_STATE_UNKNOWN, TIMESTAMP_NOBEGIN, LogicalRepWorker::userid, WaitForReplicationWorkerAttach(), WARNING, and LogicalRepCtxStruct::workers.

Referenced by ApplyLauncherMain(), and process_syncing_tables_for_apply().

235 {
236  BackgroundWorker bgw;
237  BackgroundWorkerHandle *bgw_handle;
238  int slot;
239  LogicalRepWorker *worker = NULL;
240 
241  ereport(LOG,
242  (errmsg("starting logical replication worker for subscription \"%s\"",
243  subname)));
244 
245  /* Report this after the initial starting message for consistency. */
246  if (max_replication_slots == 0)
247  ereport(ERROR,
248  (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
249  errmsg("cannot start logical replication workers when max_replication_slots = 0")));
250 
251  /*
252  * We need to do the modification of the shared memory under lock so that
253  * we have consistent view.
254  */
255  LWLockAcquire(LogicalRepWorkerLock, LW_EXCLUSIVE);
256 
257  /* Find unused worker slot. */
258  for (slot = 0; slot < max_logical_replication_workers; slot++)
259  {
260  if (!LogicalRepCtx->workers[slot].proc)
261  {
262  worker = &LogicalRepCtx->workers[slot];
263  break;
264  }
265  }
266 
267  /* Bail if not found */
268  if (worker == NULL)
269  {
270  LWLockRelease(LogicalRepWorkerLock);
272  (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
273  errmsg("out of logical replication workers slots"),
274  errhint("You might need to increase max_logical_replication_workers.")));
275  return;
276  }
277 
278  /* Prepare the worker info. */
279  worker->proc = NULL;
280  worker->dbid = dbid;
281  worker->userid = userid;
282  worker->subid = subid;
283  worker->relid = relid;
284  worker->relstate = SUBREL_STATE_UNKNOWN;
286  worker->last_lsn = InvalidXLogRecPtr;
289  worker->reply_lsn = InvalidXLogRecPtr;
290  TIMESTAMP_NOBEGIN(worker->reply_time);
291 
292  LWLockRelease(LogicalRepWorkerLock);
293 
294  /* Register the new dynamic worker. */
299  if (OidIsValid(relid))
301  "logical replication worker for subscription %u sync %u", subid, relid);
302  else
304  "logical replication worker for subscription %u", subid);
305 
308  bgw.bgw_main_arg = slot;
309 
310  if (!RegisterDynamicBackgroundWorker(&bgw, &bgw_handle))
311  {
313  (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
314  errmsg("out of background workers slots"),
315  errhint("You might need to increase max_worker_processes.")));
316  return;
317  }
318 
319  /* Now wait until it attaches. */
320  WaitForReplicationWorkerAttach(worker, bgw_handle);
321 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
int MyProcPid
Definition: globals.c:38
int errhint(const char *fmt,...)
Definition: elog.c:987
LogicalRepWorker workers[FLEXIBLE_ARRAY_MEMBER]
Definition: launcher.c:70
TimestampTz last_send_time
XLogRecPtr last_lsn
int bgw_restart_time
Definition: bgworker.h:93
int errcode(int sqlerrcode)
Definition: elog.c:575
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define LOG
Definition: elog.h:26
#define BGWORKER_SHMEM_ACCESS
Definition: bgworker.h:52
#define OidIsValid(objectId)
Definition: c.h:538
XLogRecPtr relstate_lsn
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
Datum bgw_main_arg
Definition: bgworker.h:97
#define ERROR
Definition: elog.h:43
bgworker_main_type bgw_main
Definition: bgworker.h:94
XLogRecPtr reply_lsn
#define SUBREL_STATE_UNKNOWN
#define BGW_NEVER_RESTART
Definition: bgworker.h:84
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
int max_replication_slots
Definition: slot.c:99
TimestampTz last_recv_time
#define NULL
Definition: c.h:229
char bgw_name[BGW_MAXLEN]
Definition: bgworker.h:90
#define BGWORKER_BACKEND_DATABASE_CONNECTION
Definition: bgworker.h:59
int max_logical_replication_workers
Definition: launcher.c:59
#define BGW_MAXLEN
Definition: bgworker.h:85
BgWorkerStartTime bgw_start_time
Definition: bgworker.h:92
bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, BackgroundWorkerHandle **handle)
Definition: bgworker.c:899
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
int errmsg(const char *fmt,...)
Definition: elog.c:797
pid_t bgw_notify_pid
Definition: bgworker.h:99
LogicalRepCtxStruct * LogicalRepCtx
Definition: launcher.c:73
void ApplyWorkerMain(Datum main_arg)
Definition: worker.c:1416
static bool WaitForReplicationWorkerAttach(LogicalRepWorker *worker, BackgroundWorkerHandle *handle)
Definition: launcher.c:160
TimestampTz reply_time
void logicalrep_worker_sigterm ( SIGNAL_ARGS  )

Definition at line 495 of file launcher.c.

References got_SIGTERM, MyLatch, and SetLatch().

Referenced by ApplyLauncherMain(), and ApplyWorkerMain().

496 {
497  got_SIGTERM = true;
498 
499  /* Waken anything waiting on the process latch */
500  SetLatch(MyLatch);
501 }
void SetLatch(volatile Latch *latch)
Definition: latch.c:379
bool got_SIGTERM
Definition: launcher.c:78
struct Latch * MyLatch
Definition: globals.c:51
void logicalrep_worker_stop ( Oid  subid,
Oid  relid 
)

Definition at line 328 of file launcher.c.

References CHECK_FOR_INTERRUPTS, InvalidOid, logicalrep_worker_find(), LW_SHARED, LWLockAcquire(), LWLockRelease(), MyProc, PGPROC::pid, LogicalRepWorker::proc, proc_exit(), PGPROC::procLatch, ResetLatch(), LogicalRepWorker::subid, WAIT_EVENT_BGWORKER_SHUTDOWN, WAIT_EVENT_BGWORKER_STARTUP, WaitLatch(), WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_TIMEOUT.

Referenced by DropSubscription().

329 {
330  LogicalRepWorker *worker;
331 
332  LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
333 
334  worker = logicalrep_worker_find(subid, relid, false);
335 
336  /* No worker, nothing to do. */
337  if (!worker)
338  {
339  LWLockRelease(LogicalRepWorkerLock);
340  return;
341  }
342 
343  /*
344  * If we found worker but it does not have proc set it is starting up,
345  * wait for it to finish and then kill it.
346  */
347  while (worker && !worker->proc)
348  {
349  int rc;
350 
351  LWLockRelease(LogicalRepWorkerLock);
352 
354 
355  /* Wait for signal. */
356  rc = WaitLatch(&MyProc->procLatch,
359 
360  /* emergency bailout if postmaster has died */
361  if (rc & WL_POSTMASTER_DEATH)
362  proc_exit(1);
363 
365 
366  /* Check worker status. */
367  LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
368 
369  /*
370  * Worker is no longer associated with subscription. It must have
371  * exited, nothing more for us to do.
372  */
373  if (worker->subid == InvalidOid)
374  {
375  LWLockRelease(LogicalRepWorkerLock);
376  return;
377  }
378 
379  /* Worker has assigned proc, so it has started. */
380  if (worker->proc)
381  break;
382  }
383 
384  /* Now terminate the worker ... */
385  kill(worker->proc->pid, SIGTERM);
386  LWLockRelease(LogicalRepWorkerLock);
387 
388  /* ... and wait for it to die. */
389  for (;;)
390  {
391  int rc;
392 
393  LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
394  if (!worker->proc)
395  {
396  LWLockRelease(LogicalRepWorkerLock);
397  break;
398  }
399  LWLockRelease(LogicalRepWorkerLock);
400 
402 
403  /* Wait for more work. */
404  rc = WaitLatch(&MyProc->procLatch,
405  WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
407 
408  /* emergency bailout if postmaster has died */
409  if (rc & WL_POSTMASTER_DEATH)
410  proc_exit(1);
411 
413  }
414 }
#define WL_TIMEOUT
Definition: latch.h:127
PGPROC * MyProc
Definition: proc.c:67
void proc_exit(int code)
Definition: ipc.c:99
void ResetLatch(volatile Latch *latch)
Definition: latch.c:461
Latch procLatch
Definition: proc.h:103
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
int WaitLatch(volatile Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:300
#define WL_POSTMASTER_DEATH
Definition: latch.h:128
#define InvalidOid
Definition: postgres_ext.h:36
LogicalRepWorker * logicalrep_worker_find(Oid subid, Oid relid, bool only_running)
Definition: launcher.c:207
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
int pid
Definition: proc.h:108
#define WL_LATCH_SET
Definition: latch.h:124
void logicalrep_worker_wakeup ( Oid  subid,
Oid  relid 
)

Definition at line 420 of file launcher.c.

References logicalrep_worker_find(), logicalrep_worker_wakeup_ptr(), LW_SHARED, LWLockAcquire(), and LWLockRelease().

Referenced by pg_attribute_noreturn().

421 {
422  LogicalRepWorker *worker;
423 
424  LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
425  worker = logicalrep_worker_find(subid, relid, true);
426  LWLockRelease(LogicalRepWorkerLock);
427 
428  if (worker)
430 }
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker)
Definition: launcher.c:436
LogicalRepWorker * logicalrep_worker_find(Oid subid, Oid relid, bool only_running)
Definition: launcher.c:207
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
void logicalrep_worker_wakeup_ptr ( LogicalRepWorker worker)

Definition at line 436 of file launcher.c.

References LogicalRepWorker::proc, PGPROC::procLatch, and SetLatch().

Referenced by logicalrep_worker_wakeup(), and process_syncing_tables_for_apply().

437 {
438  SetLatch(&worker->proc->procLatch);
439 }
Latch procLatch
Definition: proc.h:103
void SetLatch(volatile Latch *latch)
Definition: latch.c:379
char* LogicalRepSyncTableStart ( XLogRecPtr origin_startpos)

Definition at line 693 of file tablesync.c.

References CommandCounterIncrement(), CommitTransactionCommand(), Subscription::conninfo, copy_table(), CRS_USE_SNAPSHOT, elog, ereport, WalRcvExecResult::err, errdetail(), errmsg(), ERROR, GetSubscriptionRelState(), heap_close, heap_open(), InvalidXLogRecPtr, MyLogicalRepWorker, MySubscription, NAMEDATALEN, NoLock, NULL, Subscription::oid, psprintf(), LogicalRepWorker::relid, LogicalRepWorker::relmutex, LogicalRepWorker::relstate, LogicalRepWorker::relstate_lsn, RowExclusiveLock, SetSubscriptionRelState(), Subscription::slotname, SpinLockAcquire, SpinLockRelease, StartTransactionCommand(), StaticAssertStmt, WalRcvExecResult::status, LogicalRepWorker::subid, SUBREL_STATE_CATCHUP, SUBREL_STATE_DATASYNC, SUBREL_STATE_INIT, SUBREL_STATE_READY, SUBREL_STATE_SYNCDONE, SUBREL_STATE_SYNCWAIT, wait_for_sync_status_change(), walrcv_clear_result(), walrcv_connect, walrcv_create_slot, walrcv_exec, WALRCV_OK_COMMAND, and wrconn.

Referenced by ApplyWorkerMain().

694 {
695  char *slotname;
696  char *err;
697 
698  /* Check the state of the table synchronization. */
705  false);
708 
709  /*
710  * To build a slot name for the sync work, we are limited to NAMEDATALEN -
711  * 1 characters. We cut the original slot name to NAMEDATALEN - 28 chars
712  * and append _%u_sync_%u (1 + 10 + 6 + 10 + '\0'). (It's actually the
713  * NAMEDATALEN on the remote that matters, but this scheme will also work
714  * reasonably if that is different.)
715  */
716  StaticAssertStmt(NAMEDATALEN >= 32, "NAMEDATALEN too small"); /* for sanity */
717  slotname = psprintf("%.*s_%u_sync_%u",
718  NAMEDATALEN - 28,
722 
723  wrconn = walrcv_connect(MySubscription->conninfo, true, slotname, &err);
724  if (wrconn == NULL)
725  ereport(ERROR,
726  (errmsg("could not connect to the publisher: %s", err)));
727 
728  switch (MyLogicalRepWorker->relstate)
729  {
730  case SUBREL_STATE_INIT:
732  {
733  Relation rel;
734  WalRcvExecResult *res;
735 
740 
741  /* Update the state and make it visible to others. */
748 
749  /*
750  * We want to do the table data sync in single
751  * transaction.
752  */
754 
755  /*
756  * Use standard write lock here. It might be better to
757  * disallow access to table while it's being synchronized.
758  * But we don't want to block the main apply process from
759  * working and it has to open relation in RowExclusiveLock
760  * when remapping remote relation id to local one.
761  */
763 
764  /*
765  * Create temporary slot for the sync process.
766  * We do this inside transaction so that we can use the
767  * snapshot made by the slot to get existing data.
768  */
769  res = walrcv_exec(wrconn,
770  "BEGIN READ ONLY ISOLATION LEVEL "
771  "REPEATABLE READ", 0, NULL);
772  if (res->status != WALRCV_OK_COMMAND)
773  ereport(ERROR,
774  (errmsg("table copy could not start transaction on publisher"),
775  errdetail("The error was: %s", res->err)));
776  walrcv_clear_result(res);
777 
778  /*
779  * Create new temporary logical decoding slot.
780  *
781  * We'll use slot for data copy so make sure the snapshot
782  * is used for the transaction, that way the COPY will get
783  * data that is consistent with the lsn used by the slot
784  * to start decoding.
785  */
786  walrcv_create_slot(wrconn, slotname, true,
787  CRS_USE_SNAPSHOT, origin_startpos);
788 
789  copy_table(rel);
790 
791  res = walrcv_exec(wrconn, "COMMIT", 0, NULL);
792  if (res->status != WALRCV_OK_COMMAND)
793  ereport(ERROR,
794  (errmsg("table copy could not finish transaction on publisher"),
795  errdetail("The error was: %s", res->err)));
796  walrcv_clear_result(res);
797 
798  heap_close(rel, NoLock);
799 
800  /* Make the copy visible. */
802 
803  /*
804  * We are done with the initial data synchronization,
805  * update the state.
806  */
809  MyLogicalRepWorker->relstate_lsn = *origin_startpos;
811 
812  /*
813  * Wait for main apply worker to either tell us to
814  * catchup or that we are done.
815  */
819  {
820  /* Update the new state. */
825  finish_sync_worker();
826  }
827  break;
828  }
830  case SUBREL_STATE_READY:
831  /* Nothing to do here but finish. */
832  finish_sync_worker();
833  break;
834  default:
835  elog(ERROR, "unknown relation state \"%c\"",
837  }
838 
839  return slotname;
840 }
Subscription * MySubscription
Definition: worker.c:109
#define SUBREL_STATE_INIT
WalReceiverConn * wrconn
Definition: worker.c:107
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define SUBREL_STATE_DATASYNC
void CommitTransactionCommand(void)
Definition: xact.c:2747
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static void copy_table(Relation rel)
Definition: tablesync.c:643
#define heap_close(r, l)
Definition: heapam.h:97
#define walrcv_create_slot(conn, slotname, temporary, snapshot_action, lsn)
Definition: walreceiver.h:260
#define SUBREL_STATE_SYNCWAIT
XLogRecPtr relstate_lsn
#define NAMEDATALEN
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:757
#define SpinLockAcquire(lock)
Definition: spin.h:62
static void walrcv_clear_result(WalRcvExecResult *walres)
Definition: walreceiver.h:268
LogicalRepWorker * MyLogicalRepWorker
Definition: launcher.c:62
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
int errdetail(const char *fmt,...)
Definition: elog.c:873
static bool wait_for_sync_status_change(Oid relid, char origstate)
Definition: tablesync.c:141
#define ereport(elevel, rest)
Definition: elog.h:122
#define SpinLockRelease(lock)
Definition: spin.h:64
#define SUBREL_STATE_SYNCDONE
void CommandCounterIncrement(void)
Definition: xact.c:922
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define NULL
Definition: c.h:229
WalRcvExecStatus status
Definition: walreceiver.h:187
void StartTransactionCommand(void)
Definition: xact.c:2677
char GetSubscriptionRelState(Oid subid, Oid relid, XLogRecPtr *sublsn, bool missing_ok)
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
Oid SetSubscriptionRelState(Oid subid, Oid relid, char state, XLogRecPtr sublsn)
#define SUBREL_STATE_READY
#define SUBREL_STATE_CATCHUP
#define walrcv_exec(conn, exec, nRetTypes, retTypes)
Definition: walreceiver.h:262
#define walrcv_connect(conninfo, logical, appname, err)
Definition: walreceiver.h:242
void process_syncing_tables ( XLogRecPtr  current_lsn)

Definition at line 412 of file tablesync.c.

References am_tablesync_worker(), process_syncing_tables_for_apply(), and process_syncing_tables_for_sync().

Referenced by apply_handle_commit(), and LogicalRepApplyLoop().

413 {
414  if (am_tablesync_worker())
415  process_syncing_tables_for_sync(current_lsn);
416  else
418 }
static void process_syncing_tables_for_apply(XLogRecPtr current_lsn)
Definition: tablesync.c:256
static bool am_tablesync_worker(void)
static void process_syncing_tables_for_sync(XLogRecPtr current_lsn)
Definition: tablesync.c:200

Variable Documentation

MemoryContext ApplyCacheContext

Definition at line 105 of file worker.c.

bool got_SIGTERM

Definition at line 78 of file launcher.c.

Referenced by ApplyLauncherMain(), and logicalrep_worker_sigterm().

bool in_remote_transaction
Subscription* MySubscription