diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml index 57216d6c52..cd92f6a7d5 100644 --- a/doc/src/sgml/logical-replication.sgml +++ b/doc/src/sgml/logical-replication.sgml @@ -1595,8 +1595,8 @@ test_sub=# SELECT * FROM t1 ORDER BY id; unique constraint. Note that to log the origin and commit timestamp details of the conflicting key, track_commit_timestamp - should be enabled. In this case, an error will be raised until the - conflict is resolved manually. + should be enabled on the subscriber. In this case, an error will be + raised until the conflict is resolved manually. diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c index 09b51706db..b8a6de5eca 100644 --- a/src/backend/executor/execReplication.c +++ b/src/backend/executor/execReplication.c @@ -549,8 +549,9 @@ CheckAndReportConflict(ResultRelInfo *resultRelInfo, EState *estate, TransactionId xmin; GetTupleTransactionInfo(conflictslot, &xmin, &origin, &committs); - ReportApplyConflict(ERROR, type, resultRelInfo->ri_RelationDesc, uniqueidx, - xmin, origin, committs, conflictslot); + ReportApplyConflict(ERROR, type, resultRelInfo->ri_RelationDesc, + uniqueidx, xmin, origin, committs, + conflictslot); } } } @@ -623,8 +624,8 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo, * * XXX OTOH, this could lead to clean-up effort for dead tuples added * in heap and index in case of conflicts. But as conflicts shouldn't - * be a frequent thing so we preferred to save the performance overhead - * of extra scan before each insertion. + * be a frequent thing so we preferred to save the performance + * overhead of extra scan before each insertion. */ if (conflict) CheckAndReportConflict(resultRelInfo, estate, CT_INSERT_EXISTS, diff --git a/src/backend/replication/logical/conflict.c b/src/backend/replication/logical/conflict.c index c69194244c..27e7cb1950 100644 --- a/src/backend/replication/logical/conflict.c +++ b/src/backend/replication/logical/conflict.c @@ -20,7 +20,7 @@ #include "utils/lsyscache.h" #include "utils/rel.h" -const char *const ConflictTypeNames[] = { +static const char *const ConflictTypeNames[] = { [CT_INSERT_EXISTS] = "insert_exists", [CT_UPDATE_DIFFER] = "update_differ", [CT_UPDATE_EXISTS] = "update_exists", @@ -211,9 +211,15 @@ errdetail_apply_conflict(ConflictType type, Oid conflictidx, } case CT_DELETE_MISSING: return errdetail("Did not find the row to be deleted."); - } - return 0; /* silence compiler warning */ + /* + * XXX should we add a default behavior instead of just returning zero? + * This style can detect mistakes of coding. + */ + default: + elog(ERROR, "unexpected conflict type: %d", (int) type); + return 0; /* silence compiler warning */ + } } /* diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index b09d780fc5..105af9775c 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -2668,7 +2668,8 @@ apply_handle_update_internal(ApplyExecutionData *edata, TimestampTz localts; /* - * Report the conflict if the tuple was modified by a different origin. + * Report the conflict if the tuple was modified by a different + * origin. */ if (GetTupleTransactionInfo(localslot, &localxmin, &localorigin, &localts) && localorigin != replorigin_session_origin) @@ -2824,7 +2825,8 @@ apply_handle_delete_internal(ApplyExecutionData *edata, TimestampTz localts; /* - * Report the conflict if the tuple was modified by a different origin. + * Report the conflict if the tuple was modified by a different + * origin. */ if (GetTupleTransactionInfo(localslot, &localxmin, &localorigin, &localts) && localorigin != replorigin_session_origin) @@ -3036,7 +3038,8 @@ apply_handle_tuple_routing(ApplyExecutionData *edata, } /* - * Report the conflict if the tuple was modified by a different origin. + * Report the conflict if the tuple was modified by a + * different origin. */ if (GetTupleTransactionInfo(localslot, &localxmin, &localorigin, &localts) && localorigin != replorigin_session_origin) diff --git a/src/include/replication/conflict.h b/src/include/replication/conflict.h index e9ba6818fc..1d466c3cad 100644 --- a/src/include/replication/conflict.h +++ b/src/include/replication/conflict.h @@ -45,12 +45,16 @@ typedef enum */ } ConflictType; -extern bool GetTupleTransactionInfo(TupleTableSlot *localslot, TransactionId *xmin, - RepOriginId *localorigin, TimestampTz *localts); +extern bool GetTupleTransactionInfo(TupleTableSlot *localslot, + TransactionId *xmin, + RepOriginId *localorigin, + TimestampTz *localts); extern void ReportApplyConflict(int elevel, ConflictType type, Relation localrel, Oid conflictidx, - TransactionId localxmin, RepOriginId localorigin, - TimestampTz localts, TupleTableSlot *conflictslot); + TransactionId localxmin, + RepOriginId localorigin, + TimestampTz localts, + TupleTableSlot *conflictslot); extern void InitConflictIndexes(ResultRelInfo *relInfo); #endif diff --git a/src/test/subscription/t/013_partition.pl b/src/test/subscription/t/013_partition.pl index 896985d85b..e26f26acc5 100644 --- a/src/test/subscription/t/013_partition.pl +++ b/src/test/subscription/t/013_partition.pl @@ -786,10 +786,12 @@ ok( $logfile =~ # Enable the track_commit_timestamp to detect the conflict when attempting # to update a row that was previously modified by a different origin. -$node_subscriber1->append_conf('postgresql.conf', 'track_commit_timestamp = on'); +$node_subscriber1->append_conf('postgresql.conf', + 'track_commit_timestamp = on'); $node_subscriber1->restart; -$node_subscriber1->safe_psql('postgres', "INSERT INTO tab2 VALUES (3, 'yyy')"); +$node_subscriber1->safe_psql('postgres', + "INSERT INTO tab2 VALUES (3, 'yyy')"); $node_publisher->safe_psql('postgres', "UPDATE tab2 SET b = 'quux' WHERE a = 3"); @@ -800,7 +802,9 @@ ok( $logfile =~ qr/conflict update_differ detected on relation "public.tab2_1".*\n.*DETAIL:.* Updating a row that was modified locally in transaction [0-9]+ at .*/, 'updating a tuple that was modified by a different origin'); -$node_subscriber1->append_conf('postgresql.conf', 'track_commit_timestamp = off'); +# The remaining tests no longer test conflict detection. +$node_subscriber1->append_conf('postgresql.conf', + 'track_commit_timestamp = off'); $node_subscriber1->restart; # Test that replication continues to work correctly after altering the