|
PostgreSQL Source Code git master
|
#include "postgres.h"#include <unistd.h>#include <sys/stat.h>#include "access/genam.h"#include "access/htup_details.h"#include "access/table.h"#include "access/xact.h"#include "access/xloginsert.h"#include "catalog/catalog.h"#include "catalog/indexing.h"#include "catalog/pg_subscription.h"#include "funcapi.h"#include "miscadmin.h"#include "nodes/execnodes.h"#include "pgstat.h"#include "replication/origin.h"#include "replication/slot.h"#include "storage/condition_variable.h"#include "storage/fd.h"#include "storage/ipc.h"#include "storage/lmgr.h"#include "utils/builtins.h"#include "utils/fmgroids.h"#include "utils/guc.h"#include "utils/pg_lsn.h"#include "utils/rel.h"#include "utils/snapmgr.h"#include "utils/syscache.h"
Go to the source code of this file.
Data Structures | |
| struct | ReplicationState |
| struct | ReplicationStateOnDisk |
| struct | ReplicationStateCtl |
Macros | |
| #define | PG_REPLORIGIN_CHECKPOINT_FILENAME PG_LOGICAL_DIR "/replorigin_checkpoint" |
| #define | PG_REPLORIGIN_CHECKPOINT_TMPFILE PG_REPLORIGIN_CHECKPOINT_FILENAME ".tmp" |
| #define | REPLICATION_STATE_MAGIC ((uint32) 0x1257DADE) |
| #define | REPLICATION_ORIGIN_PROGRESS_COLS 4 |
Typedefs | |
| typedef struct ReplicationState | ReplicationState |
| typedef struct ReplicationStateOnDisk | ReplicationStateOnDisk |
| typedef struct ReplicationStateCtl | ReplicationStateCtl |
| #define PG_REPLORIGIN_CHECKPOINT_FILENAME PG_LOGICAL_DIR "/replorigin_checkpoint" |
| #define PG_REPLORIGIN_CHECKPOINT_TMPFILE PG_REPLORIGIN_CHECKPOINT_FILENAME ".tmp" |
| #define REPLICATION_ORIGIN_PROGRESS_COLS 4 |
Definition at line 604 of file origin.c.
References CloseTransientFile(), COMP_CRC32C, crc, durable_rename(), ereport, errcode_for_file_access(), errmsg(), fb(), FIN_CRC32C, i, INIT_CRC32C, InvalidReplOriginId, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_active_replication_origins, OpenTransientFile(), PANIC, PG_BINARY, PG_REPLORIGIN_CHECKPOINT_FILENAME, PG_REPLORIGIN_CHECKPOINT_TMPFILE, REPLICATION_STATE_MAGIC, replication_states, write, and XLogFlush().
Referenced by CheckPointGuts().
Definition at line 214 of file origin.c.
References fb(), name, and pg_strcasecmp().
Referenced by pg_replication_origin_create().
| Datum pg_replication_origin_advance | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1560 of file origin.c.
References fb(), InvalidXLogRecPtr, LockRelationOid(), name, PG_GETARG_LSN, PG_GETARG_TEXT_PP, PG_RETURN_VOID, replorigin_advance(), replorigin_by_name(), replorigin_check_prerequisites(), RowExclusiveLock, text_to_cstring(), and UnlockRelationOid().
| Datum pg_replication_origin_create | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1373 of file origin.c.
References DatumGetPointer(), elog, ereport, errcode(), errdetail(), errmsg(), ERROR, fb(), IsReservedName(), IsReservedOriginName(), name, pfree(), PG_GETARG_DATUM, PG_RETURN_OID, replorigin_check_prerequisites(), replorigin_create(), text_to_cstring(), and WARNING.
| Datum pg_replication_origin_drop | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1414 of file origin.c.
References DatumGetPointer(), name, pfree(), PG_GETARG_DATUM, PG_RETURN_VOID, replorigin_check_prerequisites(), replorigin_drop_by_name(), and text_to_cstring().
| Datum pg_replication_origin_oid | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1433 of file origin.c.
References DatumGetPointer(), name, OidIsValid, pfree(), PG_GETARG_DATUM, PG_RETURN_NULL, PG_RETURN_OID, replorigin_by_name(), replorigin_check_prerequisites(), and text_to_cstring().
| Datum pg_replication_origin_progress | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1595 of file origin.c.
References Assert, DatumGetPointer(), InvalidXLogRecPtr, name, OidIsValid, PG_GETARG_BOOL, PG_GETARG_DATUM, PG_RETURN_LSN, PG_RETURN_NULL, replorigin_by_name(), replorigin_check_prerequisites(), replorigin_get_progress(), text_to_cstring(), and XLogRecPtrIsValid.
| Datum pg_replication_origin_session_is_setup | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1493 of file origin.c.
References InvalidReplOriginId, ReplOriginXactState::origin, PG_RETURN_BOOL, replorigin_check_prerequisites(), and replorigin_xact_state.
| Datum pg_replication_origin_session_progress | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1509 of file origin.c.
References ereport, errcode(), errmsg(), ERROR, fb(), InvalidXLogRecPtr, PG_GETARG_BOOL, PG_RETURN_LSN, PG_RETURN_NULL, replorigin_check_prerequisites(), replorigin_session_get_progress(), session_replication_state, and XLogRecPtrIsValid.
| Datum pg_replication_origin_session_reset | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1478 of file origin.c.
References PG_RETURN_VOID, replorigin_check_prerequisites(), replorigin_session_reset(), and replorigin_xact_clear().
| Datum pg_replication_origin_session_setup | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1454 of file origin.c.
References DatumGetPointer(), name, ReplOriginXactState::origin, pfree(), PG_GETARG_DATUM, PG_GETARG_INT32, PG_RETURN_VOID, replorigin_by_name(), replorigin_check_prerequisites(), replorigin_session_setup(), replorigin_xact_state, and text_to_cstring().
| Datum pg_replication_origin_xact_reset | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1548 of file origin.c.
References PG_RETURN_VOID, replorigin_check_prerequisites(), and replorigin_xact_clear().
| Datum pg_replication_origin_xact_setup | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1530 of file origin.c.
References ereport, errcode(), errmsg(), ERROR, fb(), ReplOriginXactState::origin_lsn, ReplOriginXactState::origin_timestamp, PG_GETARG_LSN, PG_GETARG_TIMESTAMPTZ, PG_RETURN_VOID, replorigin_check_prerequisites(), replorigin_xact_state, and session_replication_state.
| Datum pg_show_replication_origin_status | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1620 of file origin.c.
References CStringGetTextDatum, fb(), i, InitMaterializedSRF(), InvalidReplOriginId, LSNGetDatum(), LW_SHARED, LWLockAcquire(), LWLockRelease(), max_active_replication_origins, ObjectIdGetDatum(), REPLICATION_ORIGIN_PROGRESS_COLS, replication_states, replorigin_by_oid(), replorigin_check_prerequisites(), tuplestore_putvalues(), and values.
Definition at line 1119 of file origin.c.
References fb(), replorigin_session_reset_internal(), and session_replication_state.
Referenced by replorigin_session_setup().
Definition at line 557 of file origin.c.
References ConditionVariableInit(), fb(), i, LWLockInitialize(), max_active_replication_origins, MemSet, replication_states, replication_states_ctl, ReplicationOriginShmemSize(), ShmemInitStruct(), ReplicationStateCtl::states, and ReplicationStateCtl::tranche_id.
Referenced by CreateOrAttachShmemStructs().
Definition at line 542 of file origin.c.
References add_size(), fb(), max_active_replication_origins, and mul_size().
Referenced by CalculateShmemSize(), and ReplicationOriginShmemInit().
| void replorigin_advance | ( | ReplOriginId | node, |
| XLogRecPtr | remote_commit, | ||
| XLogRecPtr | local_commit, | ||
| bool | go_backward, | ||
| bool | wal_log | ||
| ) |
Definition at line 918 of file origin.c.
References Assert, DoNotReplicateId, ereport, errcode(), errhint(), errmsg(), ERROR, fb(), i, InvalidReplOriginId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_active_replication_origins, xl_replorigin_set::remote_lsn, replication_states, XLOG_REPLORIGIN_SET, XLogBeginInsert(), XLogInsert(), XLogRecPtrIsValid, and XLogRegisterData().
Referenced by binary_upgrade_replorigin_advance(), LogicalRepSyncTableStart(), pg_replication_origin_advance(), PrepareRedoAdd(), replorigin_redo(), xact_redo_abort(), and xact_redo_commit().
| ReplOriginId replorigin_by_name | ( | const char * | roname, |
| bool | missing_ok | ||
| ) |
Definition at line 231 of file origin.c.
References CStringGetTextDatum, ereport, errcode(), errmsg(), ERROR, fb(), GETSTRUCT(), HeapTupleIsValid, ident, InvalidOid, ReleaseSysCache(), and SearchSysCache1().
Referenced by AlterSubscription(), binary_upgrade_replorigin_advance(), LogicalRepSyncTableStart(), ParallelApplyWorkerMain(), pg_replication_origin_advance(), pg_replication_origin_oid(), pg_replication_origin_progress(), pg_replication_origin_session_setup(), replorigin_drop_by_name(), and run_apply_worker().
| bool replorigin_by_oid | ( | ReplOriginId | roident, |
| bool | missing_ok, | ||
| char ** | roname | ||
| ) |
Definition at line 501 of file origin.c.
References Assert, DoNotReplicateId, ereport, errcode(), errmsg(), ERROR, fb(), GETSTRUCT(), HeapTupleIsValid, InvalidReplOriginId, ObjectIdGetDatum(), OidIsValid, ReleaseSysCache(), SearchSysCache1(), and text_to_cstring().
Referenced by errdetail_apply_conflict(), pg_show_replication_origin_status(), and send_repl_origin().
Definition at line 195 of file origin.c.
References ereport, errcode(), errmsg(), ERROR, fb(), max_active_replication_origins, and RecoveryInProgress().
Referenced by pg_replication_origin_advance(), pg_replication_origin_create(), pg_replication_origin_drop(), pg_replication_origin_oid(), pg_replication_origin_progress(), pg_replication_origin_session_is_setup(), pg_replication_origin_session_progress(), pg_replication_origin_session_reset(), pg_replication_origin_session_setup(), pg_replication_origin_xact_reset(), pg_replication_origin_xact_setup(), and pg_show_replication_origin_status().
| ReplOriginId replorigin_create | ( | const char * | roname | ) |
Definition at line 262 of file origin.c.
References Assert, BTEqualStrategyNumber, CatalogTupleInsert(), CHECK_FOR_INTERRUPTS, CommandCounterIncrement(), CStringGetTextDatum, ereport, errcode(), errdetail(), errmsg(), ERROR, ExclusiveLock, fb(), heap_form_tuple(), heap_freetuple(), HeapTupleIsValid, InitDirtySnapshot, InvalidOid, IsTransactionState(), MAX_RONAME_LEN, ObjectIdGetDatum(), OidIsValid, PG_UINT16_MAX, RelationData::rd_rel, RelationGetDescr, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), and values.
Referenced by CreateSubscription(), LogicalRepSyncTableStart(), pg_replication_origin_create(), and run_apply_worker().
Definition at line 447 of file origin.c.
References AccessExclusiveLock, Assert, CatalogTupleDelete(), CommandCounterIncrement(), elog, ERROR, fb(), HeapTupleIsValid, IsTransactionState(), LockSharedObject(), name, NoLock, ObjectIdGetDatum(), ReleaseSysCache(), replorigin_by_name(), replorigin_state_clear(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), table_open(), and UnlockSharedObject().
Referenced by AlterSubscription_refresh(), DropSubscription(), pg_replication_origin_drop(), ProcessSyncingTablesForApply(), and ProcessSyncingTablesForSync().
| XLogRecPtr replorigin_get_progress | ( | ReplOriginId | node, |
| bool | flush | ||
| ) |
Definition at line 1047 of file origin.c.
References fb(), i, InvalidXLogRecPtr, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_active_replication_origins, replication_states, XLogFlush(), and XLogRecPtrIsValid.
Referenced by AlterSubscription(), and pg_replication_origin_progress().
| void replorigin_redo | ( | XLogReaderState * | record | ) |
Definition at line 857 of file origin.c.
References elog, XLogReaderState::EndRecPtr, fb(), i, InvalidReplOriginId, InvalidXLogRecPtr, max_active_replication_origins, PANIC, replication_states, replorigin_advance(), XLOG_REPLORIGIN_DROP, XLOG_REPLORIGIN_SET, XLogRecGetData, and XLogRecGetInfo.
| void replorigin_session_advance | ( | XLogRecPtr | remote_commit, |
| XLogRecPtr | local_commit | ||
| ) |
Definition at line 1310 of file origin.c.
References Assert, fb(), InvalidReplOriginId, ReplicationState::local_lsn, ReplicationState::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), ReplicationState::remote_lsn, ReplicationState::roident, and session_replication_state.
Referenced by EndPrepare(), RecordTransactionAbort(), RecordTransactionAbortPrepared(), RecordTransactionCommit(), and RecordTransactionCommitPrepared().
| XLogRecPtr replorigin_session_get_progress | ( | bool | flush | ) |
Definition at line 1328 of file origin.c.
References Assert, fb(), ReplicationState::local_lsn, ReplicationState::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), ReplicationState::remote_lsn, session_replication_state, XLogFlush(), and XLogRecPtrIsValid.
Referenced by LogicalRepSyncTableStart(), pg_replication_origin_session_progress(), and run_apply_worker().
Definition at line 1276 of file origin.c.
References ReplicationState::acquired_by, Assert, ereport, errcode(), errdetail(), errhint(), errmsg(), ERROR, fb(), max_active_replication_origins, MyProcPid, ReplicationState::refcount, replorigin_session_reset_internal(), ReplicationState::roident, and session_replication_state.
Referenced by pg_replication_origin_session_reset(), and ProcessSyncingTablesForSync().
Definition at line 1085 of file origin.c.
References ReplicationState::acquired_by, Assert, ConditionVariableBroadcast(), fb(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProcPid, ReplicationState::origin_cv, ReplicationState::refcount, and session_replication_state.
Referenced by ReplicationOriginExitCleanup(), and replorigin_session_reset().
| void replorigin_session_setup | ( | ReplOriginId | node, |
| int | acquired_by | ||
| ) |
Definition at line 1146 of file origin.c.
References ReplicationState::acquired_by, Assert, ConditionVariableBroadcast(), ereport, errcode(), errhint(), errmsg(), ERROR, fb(), i, InvalidReplOriginId, ReplicationState::local_lsn, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_active_replication_origins, MyProcPid, on_shmem_exit(), ReplicationState::origin_cv, ReplicationState::refcount, ReplicationState::remote_lsn, replication_states, ReplicationOriginExitCleanup(), ReplicationState::roident, session_replication_state, and XLogRecPtrIsValid.
Referenced by LogicalRepSyncTableStart(), ParallelApplyWorkerMain(), pg_replication_origin_session_setup(), and run_apply_worker().
|
static |
Definition at line 374 of file origin.c.
References ConditionVariableCancelSleep(), ConditionVariableSleep(), ereport, errcode(), errmsg(), ERROR, fb(), i, InvalidReplOriginId, InvalidXLogRecPtr, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_active_replication_origins, xl_replorigin_drop::node_id, replication_states, XLOG_REPLORIGIN_DROP, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().
Referenced by replorigin_drop_by_name().
Definition at line 1352 of file origin.c.
References fb(), InvalidReplOriginId, InvalidXLogRecPtr, ReplOriginXactState::origin, ReplOriginXactState::origin_lsn, ReplOriginXactState::origin_timestamp, and replorigin_xact_state.
Referenced by on_exit_clear_xact_state(), pg_replication_origin_session_reset(), pg_replication_origin_xact_reset(), ProcessSyncingTablesForSync(), and start_apply().
Definition at line 730 of file origin.c.
References Assert, CloseTransientFile(), COMP_CRC32C, crc, DEBUG2, elog, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg(), fb(), fd(), FIN_CRC32C, INIT_CRC32C, LOG, LSN_FORMAT_ARGS, max_active_replication_origins, OpenTransientFile(), PANIC, PG_BINARY, PG_REPLORIGIN_CHECKPOINT_FILENAME, read, ReplicationState::remote_lsn, REPLICATION_STATE_MAGIC, replication_states, and ReplicationState::roident.
Referenced by StartupXLOG().
| int max_active_replication_origins = 10 |
Definition at line 104 of file origin.c.
Referenced by check_new_cluster_subscription_configuration(), CheckPointReplicationOrigin(), logicalrep_worker_launch(), pg_show_replication_origin_status(), ReplicationOriginShmemInit(), ReplicationOriginShmemSize(), replorigin_advance(), replorigin_check_prerequisites(), replorigin_get_progress(), replorigin_redo(), replorigin_session_reset(), replorigin_session_setup(), replorigin_state_clear(), and StartupReplicationOrigin().
|
static |
Definition at line 176 of file origin.c.
Referenced by CheckPointReplicationOrigin(), pg_show_replication_origin_status(), ReplicationOriginShmemInit(), replorigin_advance(), replorigin_get_progress(), replorigin_redo(), replorigin_session_setup(), replorigin_state_clear(), and StartupReplicationOrigin().
|
static |
Definition at line 181 of file origin.c.
Referenced by ReplicationOriginShmemInit().
| ReplOriginXactState replorigin_xact_state |
Definition at line 166 of file origin.c.
Referenced by apply_handle_commit_internal(), apply_handle_commit_prepared(), apply_handle_delete_internal(), apply_handle_prepare_internal(), apply_handle_rollback_prepared(), apply_handle_tuple_routing(), apply_handle_update_internal(), EndPrepare(), LogicalRepSyncTableStart(), pa_stream_abort(), ParallelApplyWorkerMain(), pg_replication_origin_session_is_setup(), pg_replication_origin_session_setup(), pg_replication_origin_xact_setup(), RecordTransactionAbort(), RecordTransactionAbortPrepared(), RecordTransactionCommit(), RecordTransactionCommitPrepared(), replorigin_xact_clear(), run_apply_worker(), XactLogAbortRecord(), XactLogCommitRecord(), and XLogRecordAssemble().
|
static |
Definition at line 189 of file origin.c.
Referenced by pg_replication_origin_session_progress(), pg_replication_origin_xact_setup(), ReplicationOriginExitCleanup(), replorigin_session_advance(), replorigin_session_get_progress(), replorigin_session_reset(), replorigin_session_reset_internal(), and replorigin_session_setup().