Skip to content

Commit 0ae4205

Browse files
committed
Rename the delete_late conflict to delete_exists
"Exists" means for us that something exists that is unexpected, such as for insert_exists. In the delete_exists case, it is unexpected that a newer timestamped row exists.
1 parent 181c7a6 commit 0ae4205

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

include/spock_conflict.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern bool spock_save_resolutions;
4646
/*
4747
* We want to eventually match native PostgreSQL conflict types,
4848
* so use same ordering and similar naming.
49-
* We add one additional conflict type, CT_DELETE_LATE.
49+
* We add one additional conflict type, CT_DELETE_EXISTS.
5050
*/
5151
typedef enum
5252
{
@@ -72,7 +72,7 @@ typedef enum
7272
* Unique to Spock, delete timestamp is earlier than an existing row.
7373
* Use a higher number so we don't conflict with PostgreSQL in the future.
7474
*/
75-
SPOCK_CT_DELETE_LATE = 101
75+
SPOCK_CT_DELETE_EXISTS = 101
7676

7777
} SpockConflictType;
7878

@@ -109,6 +109,8 @@ extern bool try_resolve_conflict(Relation rel, HeapTuple localtuple,
109109
RepOriginId local_origin, TimestampTz local_ts,
110110
SpockConflictResolution *resolution);
111111

112+
extern const char *SpockConflictTypeName(SpockConflictType t);
113+
112114
extern void spock_report_conflict(SpockConflictType conflict_type,
113115
SpockRelation *rel,
114116
HeapTuple localtuple,

src/spock_apply_heap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ spock_apply_heap_delete(SpockRelation *rel, SpockTupleData *oldtup)
11971197
local_ts, &resolution))
11981198
{
11991199
/* Current DELETE happened before current tuple */
1200-
spock_report_conflict(SPOCK_CT_DELETE_LATE,
1200+
spock_report_conflict(SPOCK_CT_DELETE_EXISTS,
12011201
rel, TTS_TUP(localslot), oldtup,
12021202
NULL, /* remotetuple */
12031203
local_tuple, SpockResolution_Skip,

src/spock_conflict.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,29 @@
5656
#include "spock_worker.h"
5757

5858

59-
/* From src/backend/replication/logical/conflict.c */
60-
static const char *const SpockConflictTypeNames[] = {
61-
[SPOCK_CT_INSERT_EXISTS] = "insert_exists",
62-
[SPOCK_CT_UPDATE_ORIGIN_DIFFERS] = "update_origin_differs",
63-
[SPOCK_CT_UPDATE_EXISTS] = "update_exists",
64-
[SPOCK_CT_UPDATE_MISSING] = "update_missing",
65-
[SPOCK_CT_DELETE_ORIGIN_DIFFERS] = "delete_origin_differs",
66-
[SPOCK_CT_DELETE_MISSING] = "delete_missing",
67-
[SPOCK_CT_DELETE_LATE] = "delete_late"
68-
};
59+
const char *
60+
SpockConflictTypeName(SpockConflictType t)
61+
{
62+
switch (t)
63+
{
64+
case SPOCK_CT_INSERT_EXISTS:
65+
return "insert_exists";
66+
case SPOCK_CT_UPDATE_ORIGIN_DIFFERS:
67+
return "update_origin_differs";
68+
case SPOCK_CT_UPDATE_EXISTS:
69+
return "update_exists";
70+
case SPOCK_CT_UPDATE_MISSING:
71+
return "update_missing";
72+
case SPOCK_CT_DELETE_ORIGIN_DIFFERS:
73+
return "delete_origin_differs";
74+
case SPOCK_CT_DELETE_MISSING:
75+
return "delete_missing";
76+
case SPOCK_CT_DELETE_EXISTS:
77+
return "delete_exists";
78+
default:
79+
return "unknown";
80+
}
81+
}
6982

7083

7184
int spock_conflict_resolver = SPOCK_RESOLVE_LAST_UPDATE_WINS;
@@ -478,7 +491,7 @@ spock_report_conflict(SpockConflictType conflict_type,
478491
ereport(spock_conflict_log_level,
479492
(errcode(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION),
480493
errmsg("CONFLICT: remote %s on relation %s (local index %s). Resolution: %s.",
481-
SpockConflictTypeNames[conflict_type],
494+
SpockConflictTypeName(conflict_type),
482495
qualrelname, idxname,
483496
conflict_resolution_to_string(resolution)),
484497
errdetail("existing local tuple {%s} xid=%u,origin=%s,timestamp=%s; remote tuple {%s} in xact origin=%u,timestamp=%s,commit_lsn=%X/%X",
@@ -495,7 +508,7 @@ spock_report_conflict(SpockConflictType conflict_type,
495508
ereport(spock_conflict_log_level,
496509
(errcode(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION),
497510
errmsg("CONFLICT: remote %s on relation %s replica identity index %s (tuple not found). Resolution: %s.",
498-
SpockConflictTypeNames[conflict_type],
511+
SpockConflictTypeName(conflict_type),
499512
qualrelname, idxname,
500513
conflict_resolution_to_string(resolution)),
501514
errdetail("remote tuple {%s} in xact origin=%u,timestamp=%s,commit_lsn=%X/%X",
@@ -509,7 +522,7 @@ spock_report_conflict(SpockConflictType conflict_type,
509522
ereport(spock_conflict_log_level,
510523
(errcode(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION),
511524
errmsg("CONFLICT: remote %s on relation %s replica identity index %s (tuple not found). Resolution: %s.",
512-
SpockConflictTypeNames[conflict_type],
525+
SpockConflictTypeName(conflict_type),
513526
qualrelname, idxname,
514527
conflict_resolution_to_string(resolution)),
515528
errdetail("tuple for remote delete in xact origin=%u,timestamp=%s,commit_lsn=%X/%X",
@@ -518,11 +531,11 @@ spock_report_conflict(SpockConflictType conflict_type,
518531
(uint32) (replorigin_session_origin_lsn << 32),
519532
(uint32) replorigin_session_origin_lsn)));
520533
break;
521-
case SPOCK_CT_DELETE_LATE:
534+
case SPOCK_CT_DELETE_EXISTS:
522535
ereport(spock_conflict_log_level,
523536
(errcode(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION),
524537
errmsg("CONFLICT: remote %s on relation %s replica identity index %s (newer tuple found). Resolution: %s.",
525-
SpockConflictTypeNames[conflict_type],
538+
SpockConflictTypeName(conflict_type),
526539
qualrelname, idxname,
527540
conflict_resolution_to_string(resolution)),
528541
errdetail("remote delete in xact origin=%u,timestamp=%s,commit_lsn=%X/%X",
@@ -621,7 +634,7 @@ spock_conflict_log_table(SpockConflictType conflict_type,
621634
nulls[4] = true;
622635

623636
/* conflict type */
624-
values[5] = CStringGetTextDatum(SpockConflictTypeNames[conflict_type]);
637+
values[5] = CStringGetTextDatum(SpockConflictTypeName(conflict_type));
625638
/* conflict_resolution */
626639
values[6] = CStringGetTextDatum(conflict_resolution_to_string(resolution));
627640
/* local_origin */

tests/regress/expected/tuple_origin.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ SELECT pg_sleep(3);
147147

148148
(1 row)
149149

150-
-- We should see one resolution, delete_late
150+
-- We should see one resolution, delete_exists
151151
SELECT conflict_type, local_tuple FROM spock.resolutions;
152152
conflict_type | local_tuple
153153
---------------+-----------------------
154-
delete_late | {"id":3,"mgr_id":333}
154+
delete_exists | {"id":3,"mgr_id":333}
155155
(1 row)
156156

157157
-- Empty

tests/regress/sql/tuple_origin.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ UPDATE users SET mgr_id = 333 WHERE id = 3;
9090
-- so that the delayed DELETE finally arrives (late)
9191
SELECT pg_sleep(3);
9292

93-
-- We should see one resolution, delete_late
93+
-- We should see one resolution, delete_exists
9494
SELECT conflict_type, local_tuple FROM spock.resolutions;
9595

9696
-- Empty

0 commit comments

Comments
 (0)