summaryrefslogtreecommitdiff
path: root/src/include/replication
diff options
context:
space:
mode:
authorAmit Kapila2024-08-20 03:05:11 +0000
committerAmit Kapila2024-08-20 03:05:11 +0000
commit9758174e2e5cd278cf37e0980da76b51890e0011 (patch)
tree9ca019972be8f6b4b20acd98cdeb12a9475851e9 /src/include/replication
parentadf97c1562380e02acd60dc859c289ed3a8352ee (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/replication')
-rw-r--r--src/include/replication/conflict.h58
1 files changed, 58 insertions, 0 deletions
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