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/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 |
typedef struct ReplicationState ReplicationState |
typedef struct ReplicationStateCtl ReplicationStateCtl |
typedef struct ReplicationStateOnDisk ReplicationStateOnDisk |
void CheckPointReplicationOrigin | ( | void | ) |
Definition at line 577 of file origin.c.
References CloseTransientFile(), COMP_CRC32C, crc, durable_rename(), ereport, errcode_for_file_access(), errmsg(), FIN_CRC32C, i, INIT_CRC32C, InvalidRepOriginId, ReplicationState::local_lsn, ReplicationState::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, OpenTransientFile(), PANIC, PG_BINARY, PG_REPLORIGIN_CHECKPOINT_FILENAME, PG_REPLORIGIN_CHECKPOINT_TMPFILE, ReplicationState::remote_lsn, ReplicationStateOnDisk::remote_lsn, REPLICATION_STATE_MAGIC, replication_states, ReplicationState::roident, ReplicationStateOnDisk::roident, write, and XLogFlush().
Referenced by CheckPointGuts().
|
static |
Definition at line 208 of file origin.c.
References name, and pg_strcasecmp().
Referenced by pg_replication_origin_create().
Datum pg_replication_origin_advance | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1460 of file origin.c.
References 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 1273 of file origin.c.
References DatumGetPointer(), elog, ereport, errcode(), errdetail(), errmsg(), ERROR, 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 1314 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 1333 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 1495 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(), and text_to_cstring().
Datum pg_replication_origin_session_is_setup | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1393 of file origin.c.
References InvalidRepOriginId, PG_RETURN_BOOL, replorigin_check_prerequisites(), and replorigin_session_origin.
Datum pg_replication_origin_session_progress | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1409 of file origin.c.
References ereport, errcode(), errmsg(), ERROR, InvalidXLogRecPtr, PG_GETARG_BOOL, PG_RETURN_LSN, PG_RETURN_NULL, replorigin_check_prerequisites(), replorigin_session_get_progress(), and session_replication_state.
Datum pg_replication_origin_session_reset | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1376 of file origin.c.
References InvalidRepOriginId, InvalidXLogRecPtr, PG_RETURN_VOID, replorigin_check_prerequisites(), replorigin_session_origin, replorigin_session_origin_lsn, replorigin_session_origin_timestamp, and replorigin_session_reset().
Datum pg_replication_origin_session_setup | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1354 of file origin.c.
References DatumGetPointer(), name, pfree(), PG_GETARG_DATUM, PG_RETURN_VOID, replorigin_by_name(), replorigin_check_prerequisites(), replorigin_session_origin, replorigin_session_setup(), and text_to_cstring().
Datum pg_replication_origin_xact_reset | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1448 of file origin.c.
References InvalidXLogRecPtr, PG_RETURN_VOID, replorigin_check_prerequisites(), replorigin_session_origin_lsn, and replorigin_session_origin_timestamp.
Datum pg_replication_origin_xact_setup | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1430 of file origin.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_LSN, PG_GETARG_TIMESTAMPTZ, PG_RETURN_VOID, replorigin_check_prerequisites(), replorigin_session_origin_lsn, replorigin_session_origin_timestamp, and session_replication_state.
Datum pg_show_replication_origin_status | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1520 of file origin.c.
References CStringGetTextDatum, i, InitMaterializedSRF(), InvalidRepOriginId, LSNGetDatum(), LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ObjectIdGetDatum(), REPLICATION_ORIGIN_PROGRESS_COLS, replication_states, replorigin_by_oid(), replorigin_check_prerequisites(), ReturnSetInfo::setDesc, ReturnSetInfo::setResult, tuplestore_putvalues(), and values.
|
static |
Definition at line 1059 of file origin.c.
References ReplicationState::acquired_by, ConditionVariableBroadcast(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProcPid, ReplicationState::origin_cv, and session_replication_state.
Referenced by replorigin_session_setup().
void ReplicationOriginShmemInit | ( | void | ) |
Definition at line 530 of file origin.c.
References ConditionVariableInit(), i, LWLockInitialize(), LWTRANCHE_REPLICATION_ORIGIN_STATE, max_replication_slots, MemSet, replication_states, replication_states_ctl, ReplicationOriginShmemSize(), ShmemInitStruct(), ReplicationStateCtl::states, and ReplicationStateCtl::tranche_id.
Referenced by CreateOrAttachShmemStructs().
Size ReplicationOriginShmemSize | ( | void | ) |
Definition at line 510 of file origin.c.
References add_size(), max_replication_slots, mul_size(), and size.
Referenced by CalculateShmemSize(), and ReplicationOriginShmemInit().
void replorigin_advance | ( | RepOriginId | node, |
XLogRecPtr | remote_commit, | ||
XLogRecPtr | local_commit, | ||
bool | go_backward, | ||
bool | wal_log | ||
) |
Definition at line 892 of file origin.c.
References ReplicationState::acquired_by, Assert, DoNotReplicateId, ereport, errcode(), errhint(), errmsg(), ERROR, xl_replorigin_set::force, i, InvalidRepOriginId, InvalidXLogRecPtr, ReplicationState::local_lsn, ReplicationState::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_replication_slots, xl_replorigin_set::node_id, ReplicationState::remote_lsn, xl_replorigin_set::remote_lsn, replication_states, ReplicationState::roident, XLOG_REPLORIGIN_SET, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().
Referenced by binary_upgrade_replorigin_advance(), LogicalRepSyncTableStart(), pg_replication_origin_advance(), PrepareRedoAdd(), replorigin_redo(), xact_redo_abort(), and xact_redo_commit().
RepOriginId replorigin_by_name | ( | const char * | roname, |
bool | missing_ok | ||
) |
Definition at line 225 of file origin.c.
References CStringGetTextDatum, ereport, errcode(), errmsg(), ERROR, 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 | ( | RepOriginId | roident, |
bool | missing_ok, | ||
char ** | roname | ||
) |
Definition at line 469 of file origin.c.
References Assert, DoNotReplicateId, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, HeapTupleIsValid, InvalidRepOriginId, ObjectIdGetDatum(), OidIsValid, ReleaseSysCache(), SearchSysCache1(), and text_to_cstring().
Referenced by errdetail_apply_conflict(), pg_show_replication_origin_status(), and send_repl_origin().
|
static |
Definition at line 189 of file origin.c.
References ereport, errcode(), errmsg(), ERROR, max_replication_slots, 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().
RepOriginId replorigin_create | ( | const char * | roname | ) |
Definition at line 256 of file origin.c.
References Assert, BTEqualStrategyNumber, CatalogTupleInsert(), CHECK_FOR_INTERRUPTS, CommandCounterIncrement(), CStringGetTextDatum, ereport, errcode(), errmsg(), ERROR, ExclusiveLock, heap_form_tuple(), heap_freetuple(), HeapTupleIsValid, InitDirtySnapshot, InvalidOid, IsTransactionState(), sort-test::key, ObjectIdGetDatum(), PG_UINT16_MAX, 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().
void replorigin_drop_by_name | ( | const char * | name, |
bool | missing_ok, | ||
bool | nowait | ||
) |
Definition at line 415 of file origin.c.
References AccessExclusiveLock, Assert, CatalogTupleDelete(), CommandCounterIncrement(), elog, ERROR, 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(), process_syncing_tables_for_apply(), and process_syncing_tables_for_sync().
XLogRecPtr replorigin_get_progress | ( | RepOriginId | node, |
bool | flush | ||
) |
Definition at line 1018 of file origin.c.
References i, InvalidXLogRecPtr, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, replication_states, and XLogFlush().
Referenced by AlterSubscription(), and pg_replication_origin_progress().
void replorigin_redo | ( | XLogReaderState * | record | ) |
Definition at line 831 of file origin.c.
References elog, XLogReaderState::EndRecPtr, xl_replorigin_set::force, i, InvalidRepOriginId, InvalidXLogRecPtr, max_replication_slots, xl_replorigin_set::node_id, xl_replorigin_drop::node_id, PANIC, xl_replorigin_set::remote_lsn, replication_states, replorigin_advance(), XLOG_REPLORIGIN_DROP, XLOG_REPLORIGIN_SET, XLogRecGetData, XLogRecGetInfo, and XLR_INFO_MASK.
void replorigin_session_advance | ( | XLogRecPtr | remote_commit, |
XLogRecPtr | local_commit | ||
) |
Definition at line 1223 of file origin.c.
References Assert, InvalidRepOriginId, 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 1241 of file origin.c.
References Assert, InvalidXLogRecPtr, ReplicationState::local_lsn, ReplicationState::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), ReplicationState::remote_lsn, session_replication_state, and XLogFlush().
Referenced by LogicalRepSyncTableStart(), pg_replication_origin_session_progress(), and run_apply_worker().
void replorigin_session_reset | ( | void | ) |
Definition at line 1194 of file origin.c.
References ReplicationState::acquired_by, Assert, ConditionVariableBroadcast(), ereport, errcode(), errmsg(), ERROR, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationState::origin_cv, and session_replication_state.
Referenced by pg_replication_origin_session_reset(), and process_syncing_tables_for_sync().
void replorigin_session_setup | ( | RepOriginId | node, |
int | acquired_by | ||
) |
Definition at line 1101 of file origin.c.
References ReplicationState::acquired_by, Assert, ConditionVariableBroadcast(), elog, ereport, errcode(), errhint(), errmsg(), ERROR, i, InvalidRepOriginId, InvalidXLogRecPtr, ReplicationState::local_lsn, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_replication_slots, MyProcPid, on_shmem_exit(), ReplicationState::origin_cv, ReplicationState::remote_lsn, replication_states, ReplicationOriginExitCleanup(), ReplicationState::roident, and session_replication_state.
Referenced by LogicalRepSyncTableStart(), ParallelApplyWorkerMain(), pg_replication_origin_session_setup(), and run_apply_worker().
|
static |
Definition at line 345 of file origin.c.
References ConditionVariableCancelSleep(), ConditionVariableSleep(), ereport, errcode(), errmsg(), ERROR, i, InvalidRepOriginId, InvalidXLogRecPtr, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_replication_slots, xl_replorigin_drop::node_id, replication_states, XLOG_REPLORIGIN_DROP, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().
Referenced by replorigin_drop_by_name().
void StartupReplicationOrigin | ( | void | ) |
Definition at line 703 of file origin.c.
References Assert, CloseTransientFile(), COMP_CRC32C, crc, DEBUG2, elog, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg(), fd(), FIN_CRC32C, INIT_CRC32C, LOG, LSN_FORMAT_ARGS, max_replication_slots, OpenTransientFile(), PANIC, PG_BINARY, PG_REPLORIGIN_CHECKPOINT_FILENAME, read, ReplicationState::remote_lsn, ReplicationStateOnDisk::remote_lsn, REPLICATION_STATE_MAGIC, replication_states, ReplicationState::roident, and ReplicationStateOnDisk::roident.
Referenced by StartupXLOG().
|
static |
Definition at line 170 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 175 of file origin.c.
Referenced by ReplicationOriginShmemInit().
RepOriginId replorigin_session_origin = InvalidRepOriginId |
Definition at line 159 of file origin.c.
Referenced by apply_handle_delete_internal(), apply_handle_tuple_routing(), apply_handle_update_internal(), EndPrepare(), LogicalRepSyncTableStart(), ParallelApplyWorkerMain(), pg_replication_origin_session_is_setup(), pg_replication_origin_session_reset(), pg_replication_origin_session_setup(), process_syncing_tables_for_sync(), RecordTransactionAbort(), RecordTransactionAbortPrepared(), RecordTransactionCommit(), RecordTransactionCommitPrepared(), replorigin_reset(), run_apply_worker(), XactLogAbortRecord(), XactLogCommitRecord(), and XLogRecordAssemble().
XLogRecPtr replorigin_session_origin_lsn = InvalidXLogRecPtr |
Definition at line 160 of file origin.c.
Referenced by apply_handle_commit_internal(), apply_handle_commit_prepared(), apply_handle_prepare_internal(), apply_handle_rollback_prepared(), EndPrepare(), pa_stream_abort(), pg_replication_origin_session_reset(), pg_replication_origin_xact_reset(), pg_replication_origin_xact_setup(), process_syncing_tables_for_sync(), RecordTransactionAbort(), RecordTransactionAbortPrepared(), RecordTransactionCommit(), RecordTransactionCommitPrepared(), replorigin_reset(), XactLogAbortRecord(), and XactLogCommitRecord().
TimestampTz replorigin_session_origin_timestamp = 0 |
Definition at line 161 of file origin.c.
Referenced by apply_handle_commit_internal(), apply_handle_commit_prepared(), apply_handle_prepare_internal(), apply_handle_rollback_prepared(), EndPrepare(), pa_stream_abort(), pg_replication_origin_session_reset(), pg_replication_origin_xact_reset(), pg_replication_origin_xact_setup(), process_syncing_tables_for_sync(), RecordTransactionCommit(), RecordTransactionCommitPrepared(), replorigin_reset(), XactLogAbortRecord(), and XactLogCommitRecord().
|
static |
Definition at line 183 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(), and replorigin_session_setup().