PostgreSQL Source Code git master
Loading...
Searching...
No Matches
conflict.h File Reference
#include "access/xlogdefs.h"
#include "datatype/timestamp.h"
#include "nodes/pg_list.h"
Include dependency graph for conflict.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ConflictTupleInfo
 

Macros

#define CONFLICT_NUM_TYPES   (CT_MULTIPLE_UNIQUE_CONFLICTS + 1)
 
#define CONFLICTS_LOGGED_TO_TABLE(dest)    ((dest == CONFLICT_LOG_DEST_TABLE) || (dest == CONFLICT_LOG_DEST_ALL))
 
#define CONFLICTS_LOGGED_TO_LOG(dest)    ((dest == CONFLICT_LOG_DEST_LOG) || (dest == CONFLICT_LOG_DEST_ALL))
 

Typedefs

typedef struct EState EState
 
typedef struct ResultRelInfo ResultRelInfo
 
typedef struct TupleTableSlot TupleTableSlot
 
typedef struct ConflictTupleInfo ConflictTupleInfo
 
typedef enum ConflictLogDest ConflictLogDest
 

Enumerations

enum  ConflictType {
  CT_INSERT_EXISTS , CT_UPDATE_ORIGIN_DIFFERS , CT_UPDATE_EXISTS , CT_UPDATE_DELETED ,
  CT_UPDATE_MISSING , CT_DELETE_ORIGIN_DIFFERS , CT_DELETE_MISSING , CT_MULTIPLE_UNIQUE_CONFLICTS
}
 
enum  ConflictLogDest { CONFLICT_LOG_DEST_LOG = 0 , CONFLICT_LOG_DEST_TABLE , CONFLICT_LOG_DEST_ALL }
 

Functions

Oid create_conflict_log_table (Oid subid, char *subname, Oid subowner)
 
ConflictLogDest GetConflictLogDest (const char *dest)
 
bool GetTupleTransactionInfo (TupleTableSlot *localslot, TransactionId *xmin, ReplOriginId *localorigin, TimestampTz *localts)
 
void ReportApplyConflict (EState *estate, ResultRelInfo *relinfo, int elevel, ConflictType type, TupleTableSlot *searchslot, TupleTableSlot *remoteslot, List *conflicttuples)
 
void InitConflictIndexes (ResultRelInfo *relInfo)
 

Variables

PGDLLIMPORT const char *const ConflictLogDestNames []
 

Macro Definition Documentation

◆ CONFLICT_NUM_TYPES

#define CONFLICT_NUM_TYPES   (CT_MULTIPLE_UNIQUE_CONFLICTS + 1)

Definition at line 64 of file conflict.h.

◆ CONFLICTS_LOGGED_TO_LOG

#define CONFLICTS_LOGGED_TO_LOG (   dest)     ((dest == CONFLICT_LOG_DEST_LOG) || (dest == CONFLICT_LOG_DEST_ALL))

Definition at line 98 of file conflict.h.

◆ CONFLICTS_LOGGED_TO_TABLE

#define CONFLICTS_LOGGED_TO_TABLE (   dest)     ((dest == CONFLICT_LOG_DEST_TABLE) || (dest == CONFLICT_LOG_DEST_ALL))

Definition at line 96 of file conflict.h.

Typedef Documentation

◆ ConflictLogDest

◆ ConflictTupleInfo

◆ EState

Definition at line 17 of file conflict.h.

◆ ResultRelInfo

Definition at line 18 of file conflict.h.

◆ TupleTableSlot

Definition at line 19 of file conflict.h.

Enumeration Type Documentation

◆ ConflictLogDest

Enumerator
CONFLICT_LOG_DEST_LOG 
CONFLICT_LOG_DEST_TABLE 
CONFLICT_LOG_DEST_ALL 

Definition at line 89 of file conflict.h.

90{
91 CONFLICT_LOG_DEST_LOG = 0, /* Emit to server logs */
92 CONFLICT_LOG_DEST_TABLE, /* Insert into the conflict log table */
93 CONFLICT_LOG_DEST_ALL /* Both log and table */
ConflictLogDest
Definition conflict.h:90
@ CONFLICT_LOG_DEST_TABLE
Definition conflict.h:92
@ CONFLICT_LOG_DEST_ALL
Definition conflict.h:93
@ CONFLICT_LOG_DEST_LOG
Definition conflict.h:91

◆ ConflictType

Enumerator
CT_INSERT_EXISTS 
CT_UPDATE_ORIGIN_DIFFERS 
CT_UPDATE_EXISTS 
CT_UPDATE_DELETED 
CT_UPDATE_MISSING 
CT_DELETE_ORIGIN_DIFFERS 
CT_DELETE_MISSING 
CT_MULTIPLE_UNIQUE_CONFLICTS 

Definition at line 31 of file conflict.h.

32{
33 /* The row to be inserted violates unique constraint */
35
36 /* The row to be updated was modified by a different origin */
38
39 /* The updated row value violates unique constraint */
41
42 /* The row to be updated was concurrently deleted by a different origin */
44
45 /* The row to be updated is missing */
47
48 /* The row to be deleted was modified by a different origin */
50
51 /* The row to be deleted is missing */
53
54 /* The row to be inserted/updated violates multiple unique constraint */
56
57 /*
58 * Other conflicts, such as exclusion constraint violations, involve more
59 * complex rules than simple equality checks. These conflicts are left for
60 * future improvements.
61 */
ConflictType
Definition conflict.h:32
@ CT_UPDATE_DELETED
Definition conflict.h:43
@ CT_MULTIPLE_UNIQUE_CONFLICTS
Definition conflict.h:55
@ CT_DELETE_MISSING
Definition conflict.h:52
@ CT_UPDATE_ORIGIN_DIFFERS
Definition conflict.h:37
@ CT_INSERT_EXISTS
Definition conflict.h:34
@ CT_UPDATE_EXISTS
Definition conflict.h:40
@ CT_UPDATE_MISSING
Definition conflict.h:46
@ CT_DELETE_ORIGIN_DIFFERS
Definition conflict.h:49

Function Documentation

◆ create_conflict_log_table()

Oid create_conflict_log_table ( Oid  subid,
char subname,
Oid  subowner 
)
extern

Definition at line 147 of file conflict.c.

148{
149 TupleDesc tupdesc;
150 Oid relid;
151 char relname[NAMEDATALEN];
152
153 snprintf(relname, NAMEDATALEN, "pg_conflict_log_%u", subid);
154
155 /* Build the tuple descriptor for the new table. */
157
158 /* Create conflict log table. */
161 0, /* tablespace */
162 InvalidOid, /* relid */
163 InvalidOid, /* reltypeid */
164 InvalidOid, /* reloftypeid */
165 subowner,
167 tupdesc,
168 NIL,
171 false, /* shared_relation */
172 false, /* mapped_relation */
174 (Datum) 0, /* reloptions */
175 false, /* use_user_acl */
176 false, /* allow_system_table_mods */
177 true, /* is_internal */
178 InvalidOid, /* relrewrite */
179 NULL); /* typaddress */
180 Assert(OidIsValid(relid));
181
182 /* Release tuple descriptor memory. */
183 FreeTupleDesc(tupdesc);
184
185 /*
186 * We must bump the command counter to make the newly-created relation
187 * tuple visible for opening.
188 */
190
191 /*
192 * Create a TOAST table for the conflict log to support out-of-line
193 * storage of large json data.
194 */
196
198 (errmsg("created conflict log table \"%s\" for subscription \"%s\"",
200 subname)));
201
202 return relid;
203}
#define Assert(condition)
Definition c.h:1002
#define OidIsValid(objectId)
Definition c.h:917
static TupleDesc create_conflict_log_table_tupdesc(void)
Definition conflict.c:118
#define NOTICE
Definition elog.h:36
#define ereport(elevel,...)
Definition elog.h:152
Oid heap_create_with_catalog(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, Oid reltypeid, Oid reloftypeid, Oid ownerid, Oid accessmtd, TupleDesc tupdesc, List *cooked_constraints, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, OnCommitAction oncommit, Datum reloptions, bool use_user_acl, bool allow_system_table_mods, bool is_internal, Oid relrewrite, ObjectAddress *typaddress)
Definition heap.c:1140
char * get_qualified_objname(Oid nspid, char *objname)
Definition lsyscache.c:3720
static char * errmsg
NameData relname
Definition pg_class.h:40
#define NAMEDATALEN
#define NIL
Definition pg_list.h:68
NameData subname
#define snprintf
Definition port.h:261
uint64_t Datum
Definition postgres.h:70
#define InvalidOid
unsigned int Oid
static int fb(int x)
@ ONCOMMIT_NOOP
Definition primnodes.h:59
void NewRelationCreateToastTable(Oid relOid, Datum reloptions)
Definition toasting.c:72
void FreeTupleDesc(TupleDesc tupdesc)
Definition tupdesc.c:569
void CommandCounterIncrement(void)
Definition xact.c:1130

References Assert, CommandCounterIncrement(), create_conflict_log_table_tupdesc(), ereport, errmsg, fb(), FreeTupleDesc(), get_qualified_objname(), heap_create_with_catalog(), InvalidOid, NAMEDATALEN, NewRelationCreateToastTable(), NIL, NOTICE, OidIsValid, ONCOMMIT_NOOP, relname, snprintf, and subname.

Referenced by alter_sub_conflict_log_dest().

◆ GetConflictLogDest()

ConflictLogDest GetConflictLogDest ( const char dest)
extern

Definition at line 210 of file conflict.c.

211{
212 /* NULL defaults to LOG. */
213 if (dest == NULL || pg_strcasecmp(dest, "log") == 0)
215
216 if (pg_strcasecmp(dest, "table") == 0)
218
219 if (pg_strcasecmp(dest, "all") == 0)
221
222 /* Unrecognized string. */
225 errmsg("unrecognized conflict_log_destination value: \"%s\"", dest),
226 errhint("Valid values are \"log\", \"table\", and \"all\".")));
227}
int errcode(int sqlerrcode)
Definition elog.c:875
int errhint(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
int pg_strcasecmp(const char *s1, const char *s2)

References CONFLICT_LOG_DEST_ALL, CONFLICT_LOG_DEST_LOG, CONFLICT_LOG_DEST_TABLE, ereport, errcode(), errhint(), errmsg, ERROR, fb(), and pg_strcasecmp().

Referenced by AlterSubscription(), and parse_subscription_options().

◆ GetTupleTransactionInfo()

bool GetTupleTransactionInfo ( TupleTableSlot localslot,
TransactionId xmin,
ReplOriginId localorigin,
TimestampTz localts 
)
extern

Definition at line 236 of file conflict.c.

238{
240 bool isnull;
241
243 &isnull);
245 Assert(!isnull);
246
247 /*
248 * The commit timestamp data is not available if track_commit_timestamp is
249 * disabled.
250 */
252 {
254 *localts = 0;
255 return false;
256 }
257
259}
bool track_commit_timestamp
Definition commit_ts.c:121
bool TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts, ReplOriginId *nodeid)
Definition commit_ts.c:283
#define InvalidReplOriginId
Definition origin.h:33
static TransactionId DatumGetTransactionId(Datum X)
Definition postgres.h:282
#define MinTransactionIdAttributeNumber
Definition sysattr.h:22
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition tuptable.h:438

References Assert, DatumGetTransactionId(), fb(), InvalidReplOriginId, MinTransactionIdAttributeNumber, slot_getsysattr(), track_commit_timestamp, and TransactionIdGetCommitTsData().

Referenced by apply_handle_delete_internal(), apply_handle_tuple_routing(), apply_handle_update_internal(), and CheckAndReportConflict().

◆ InitConflictIndexes()

void InitConflictIndexes ( ResultRelInfo relInfo)
extern

Definition at line 312 of file conflict.c.

313{
315
316 for (int i = 0; i < relInfo->ri_NumIndices; i++)
317 {
318 Relation indexRelation = relInfo->ri_IndexRelationDescs[i];
319
320 if (indexRelation == NULL)
321 continue;
322
323 /* Detect conflict only for unique indexes */
324 if (!relInfo->ri_IndexRelationInfo[i]->ii_Unique)
325 continue;
326
327 /* Don't support conflict detection for deferrable index */
328 if (!indexRelation->rd_index->indimmediate)
329 continue;
330
332 RelationGetRelid(indexRelation));
333 }
334
335 relInfo->ri_onConflictArbiterIndexes = uniqueIndexes;
336}
int i
Definition isn.c:77
List * lappend_oid(List *list, Oid datum)
Definition list.c:375
#define RelationGetRelid(relation)
Definition rel.h:516
Definition pg_list.h:54
Form_pg_index rd_index
Definition rel.h:192

References fb(), i, lappend_oid(), NIL, RelationData::rd_index, and RelationGetRelid.

Referenced by apply_handle_insert_internal(), apply_handle_tuple_routing(), and apply_handle_update_internal().

◆ ReportApplyConflict()

void ReportApplyConflict ( EState estate,
ResultRelInfo relinfo,
int  elevel,
ConflictType  type,
TupleTableSlot searchslot,
TupleTableSlot remoteslot,
List conflicttuples 
)
extern

Definition at line 277 of file conflict.c.

280{
281 Relation localrel = relinfo->ri_RelationDesc;
283
285
286 /* Form errdetail message by combining conflicting tuples information. */
290 conflicttuple->indexoid,
291 conflicttuple->xmin,
292 conflicttuple->origin,
293 conflicttuple->ts,
294 &err_detail);
295
297
298 ereport(elevel,
300 errmsg("conflict detected on relation \"%s.%s\": conflict=%s",
302 RelationGetRelationName(localrel),
304 errdetail_internal("%s", err_detail.data));
305}
Subscription * MySubscription
Definition worker.c:484
static const char *const ConflictTypeNames[]
Definition conflict.c:84
static void errdetail_apply_conflict(EState *estate, ResultRelInfo *relinfo, ConflictType type, TupleTableSlot *searchslot, TupleTableSlot *localslot, TupleTableSlot *remoteslot, Oid indexoid, TransactionId localxmin, ReplOriginId localorigin, TimestampTz localts, StringInfo err_msg)
Definition conflict.c:403
static int errcode_apply_conflict(ConflictType type)
Definition conflict.c:342
int int errdetail_internal(const char *fmt,...) pg_attribute_printf(1
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3682
#define foreach_ptr(type, var, lst)
Definition pg_list.h:501
void pgstat_report_subscription_conflict(Oid subid, ConflictType type)
#define RelationGetRelationName(relation)
Definition rel.h:550
#define RelationGetNamespace(relation)
Definition rel.h:557
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
const char * type

References ConflictTypeNames, ereport, errcode_apply_conflict(), errdetail_apply_conflict(), errdetail_internal(), errmsg, fb(), foreach_ptr, get_namespace_name(), initStringInfo(), MySubscription, Subscription::oid, pgstat_report_subscription_conflict(), RelationGetNamespace, RelationGetRelationName, and type.

Referenced by apply_handle_delete_internal(), apply_handle_tuple_routing(), apply_handle_update_internal(), and CheckAndReportConflict().

Variable Documentation

◆ ConflictLogDestNames

PGDLLIMPORT const char* const ConflictLogDestNames[]
extern

Definition at line 34 of file conflict.c.

34 {
35 [CONFLICT_LOG_DEST_LOG] = "log",
36 [CONFLICT_LOG_DEST_TABLE] = "table",
37 [CONFLICT_LOG_DEST_ALL] = "all"
38};

Referenced by AlterSubscription().