diff options
author | Amit Kapila | 2024-08-20 03:05:11 +0000 |
---|---|---|
committer | Amit Kapila | 2024-08-20 03:05:11 +0000 |
commit | 9758174e2e5cd278cf37e0980da76b51890e0011 (patch) | |
tree | 9ca019972be8f6b4b20acd98cdeb12a9475851e9 /src/include | |
parent | adf97c1562380e02acd60dc859c289ed3a8352ee (diff) |
Log the conflicts while applying changes in logical replication.
This patch provides the additional logging information in the following
conflict scenarios while applying changes:
insert_exists: Inserting a row that violates a NOT DEFERRABLE unique constraint.
update_differ: Updating a row that was previously modified by another origin.
update_exists: The updated row value violates a NOT DEFERRABLE unique constraint.
update_missing: The tuple to be updated is missing.
delete_differ: Deleting a row that was previously modified by another origin.
delete_missing: The tuple to be deleted is missing.
For insert_exists and update_exists conflicts, the log can include the origin
and commit timestamp details of the conflicting key with track_commit_timestamp
enabled.
update_differ and delete_differ conflicts can only be detected when
track_commit_timestamp is enabled on the subscriber.
We do not offer additional logging for exclusion constraint violations because
these constraints can specify rules that are more complex than simple equality
checks. Resolving such conflicts won't be straightforward. This area can be
further enhanced if required.
Author: Hou Zhijie
Reviewed-by: Shveta Malik, Amit Kapila, Nisha Moond, Hayato Kuroda, Dilip Kumar
Discussion: https://postgr.es/m/OS0PR01MB5716352552DFADB8E9AD1D8994C92@OS0PR01MB5716.jpnprd01.prod.outlook.com
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/executor/executor.h | 5 | ||||
-rw-r--r-- | src/include/replication/conflict.h | 58 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index 046a7fb69b0..69c3ebff00a 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -228,6 +228,10 @@ extern void ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate); extern void ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate); +extern char *ExecBuildSlotValueDescription(Oid reloid, TupleTableSlot *slot, + TupleDesc tupdesc, + Bitmapset *modifiedCols, + int maxfieldlen); extern LockTupleMode ExecUpdateLockMode(EState *estate, ResultRelInfo *relinfo); extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti, bool missing_ok); extern ExecAuxRowMark *ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist); @@ -643,6 +647,7 @@ extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo, extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, ItemPointer conflictTid, + ItemPointer tupleid, List *arbiterIndexes); extern void check_exclusion_constraint(Relation heap, Relation index, IndexInfo *indexInfo, diff --git a/src/include/replication/conflict.h b/src/include/replication/conflict.h new file mode 100644 index 00000000000..02cb84da7ea --- /dev/null +++ b/src/include/replication/conflict.h @@ -0,0 +1,58 @@ +/*------------------------------------------------------------------------- + * conflict.h + * Exports for conflicts logging. + * + * Copyright (c) 2024, PostgreSQL Global Development Group + * + *------------------------------------------------------------------------- + */ +#ifndef CONFLICT_H +#define CONFLICT_H + +#include "nodes/execnodes.h" +#include "utils/timestamp.h" + +/* + * Conflict types that could occur while applying remote changes. + */ +typedef enum +{ + /* The row to be inserted violates unique constraint */ + CT_INSERT_EXISTS, + + /* The row to be updated was modified by a different origin */ + CT_UPDATE_DIFFER, + + /* The updated row value violates unique constraint */ + CT_UPDATE_EXISTS, + + /* The row to be updated is missing */ + CT_UPDATE_MISSING, + + /* The row to be deleted was modified by a different origin */ + CT_DELETE_DIFFER, + + /* The row to be deleted is missing */ + CT_DELETE_MISSING, + + /* + * Other conflicts, such as exclusion constraint violations, involve more + * complex rules than simple equality checks. These conflicts are left for + * future improvements. + */ +} ConflictType; + +extern bool GetTupleTransactionInfo(TupleTableSlot *localslot, + TransactionId *xmin, + RepOriginId *localorigin, + TimestampTz *localts); +extern void ReportApplyConflict(EState *estate, ResultRelInfo *relinfo, + int elevel, ConflictType type, + TupleTableSlot *searchslot, + TupleTableSlot *localslot, + TupleTableSlot *remoteslot, + Oid indexoid, TransactionId localxmin, + RepOriginId localorigin, TimestampTz localts); +extern void InitConflictIndexes(ResultRelInfo *relInfo); + +#endif |