bdr: refactoring: remove duplicate enum for conflict handlers/logging
authorChristian Kruse <cjk@defunct.ch>
Tue, 13 May 2014 07:55:42 +0000 (09:55 +0200)
committerAndres Freund <andres@anarazel.de>
Thu, 3 Jul 2014 15:55:34 +0000 (17:55 +0200)
contrib/bdr/bdr--0.5.sql
contrib/bdr/bdr.h
contrib/bdr/bdr_apply.c
contrib/bdr/bdr_conflict_handlers.c
contrib/bdr/bdr_conflict_logging.c

index f5910687912e5cc93692b8b12b09e14a7c0dcf7b..e52fbaa5b466964f5b70026331cba4e119de4537 100644 (file)
@@ -146,17 +146,23 @@ VALUES (
     'bdr_sequence_options'
 );
 
-CREATE TYPE bdr.bdr_handler_types AS ENUM(
-    'UPDATE_VS_UPDATE', 'UPDATE_VS_DELETE',
-    'INSERT_VS_INSERT', 'INSERT_VS_UPDATE'
+CREATE TYPE bdr_conflict_type AS ENUM
+(
+    'insert_insert',
+    'insert_update',
+    'update_update',
+    'update_delete',
+    'unhandled_tx_abort'
 );
 
+COMMENT ON TYPE bdr_conflict_type IS 'The nature of a BDR apply conflict - concurrent updates (update_update), conflicting inserts, etc.';
+
 CREATE TYPE bdr.bdr_conflict_handler_action
     AS ENUM('IGNORE', 'ROW', 'SKIP');
 
 CREATE TABLE bdr.bdr_conflict_handlers (
     ch_name NAME NOT NULL,
-    ch_type bdr.bdr_handler_types NOT NULL,
+    ch_type bdr.bdr_conflict_type NOT NULL,
     ch_reloid Oid NOT NULL,
     ch_fun regprocedure NOT NULL,
     ch_timeframe INTERVAL,
@@ -172,7 +178,7 @@ CREATE FUNCTION bdr.bdr_create_conflict_handler(
     ch_rel REGCLASS,
     ch_name NAME,
     ch_proc REGPROCEDURE,
-    ch_type bdr.bdr_handler_types,
+    ch_type bdr.bdr_conflict_type,
     ch_timeframe INTERVAL
 )
 RETURNS VOID
@@ -185,7 +191,7 @@ CREATE FUNCTION bdr.bdr_create_conflict_handler(
     ch_rel REGCLASS,
     ch_name NAME,
     ch_proc REGPROCEDURE,
-    ch_type bdr.bdr_handler_types
+    ch_type bdr.bdr_conflict_type
 )
 RETURNS VOID
 LANGUAGE C
@@ -206,16 +212,6 @@ CREATE VIEW bdr_list_conflict_handlers(ch_name, ch_type, ch_reloid, ch_fun) AS
 ;
 
 
-CREATE TYPE bdr_conflict_type AS ENUM
-(
-    'insert_insert',
-    'update_update',
-    'update_delete',
-    'unhandled_tx_abort'
-);
-
-COMMENT ON TYPE bdr_conflict_type IS 'The nature of a BDR apply conflict - concurrent updates (update_update), conflicting inserts, etc.';
-
 CREATE TYPE bdr_conflict_resolution AS ENUM
 (
     'conflict_trigger_skip_change',
index 73da0aa2ba5a93210345e4e62c737c10676b32c0..5f3b52db32529d9244d8a7b8cf6691bfa5404a74 100644 (file)
@@ -43,14 +43,6 @@ typedef enum BdrOutputCommitFlags
    BDR_OUTPUT_COMMIT_HAS_ORIGIN = 1
 } BdrOutputCommitFlags;
 
-typedef enum BDRConflictHandlerType
-{
-   BDRUpdateUpdateConflictHandler,
-   BDRUpdateDeleteConflictHandler,
-   BDRInsertInsertConflictHandler,
-   BDRInsertUpdateConflictHandler
-}  BDRConflictHandlerType;
-
 /*
  * BDR conflict detection: type of conflict that was identified.
  *
@@ -60,6 +52,7 @@ typedef enum BDRConflictHandlerType
 typedef enum BdrConflictType
 {
    BdrConflictType_InsertInsert,
+   BdrConflictType_InsertUpdate,
    BdrConflictType_UpdateUpdate,
    BdrConflictType_UpdateDelete,
    BdrConflictType_UnhandledTxAbort
@@ -83,7 +76,7 @@ typedef enum BdrConflictResolution
 typedef struct BDRConflictHandler
 {
    Oid         handler_oid;
-   BDRConflictHandlerType handler_type;
+   BdrConflictType handler_type;
    uint64      timeframe;
 }  BDRConflictHandler;
 
@@ -342,7 +335,7 @@ extern void bdr_conflict_handlers_init(void);
 
 extern HeapTuple bdr_conflict_handlers_resolve(BDRRelation * rel, const HeapTuple local,
                              const HeapTuple remote, const char *command_tag,
-                             BDRConflictHandlerType event_type,
+                             BdrConflictType event_type,
                              uint64 timeframe, bool *skip);
 
 #endif   /* BDR_H */
index 2b3392d296ebeaea8a15154d3164cd18b23ed425..f41e0769623ba68f9a2ef5ebb3ca8e0c2499e4e9 100644 (file)
@@ -870,7 +870,7 @@ check_apply_update(RepNodeId local_node_id, TimestampTz local_ts,
 
            *new_tuple = bdr_conflict_handlers_resolve(rel, local_tuple,
                                                       remote_tuple, "UPDATE",
-                                                      BDRUpdateUpdateConflictHandler,
+                                                      BdrConflictType_UpdateUpdate,
                                                       abs(secs) * 1000000 + abs(microsecs),
                                                       &skip);
 
index e5181333db1619f0fc8f5540ff6e503310e67f41..63305e5d6a154efdeb2f4e7bb025c46cf86e28c0 100644 (file)
@@ -64,7 +64,7 @@ const char *get_conflict_handlers_for_table_sql =
 
 static void bdr_conflict_handlers_check_handler_fun(Relation rel, Oid proc_oid);
 static void bdr_conflict_handlers_check_access(Oid reloid);
-static const char *bdr_conflict_handlers_event_type_name(BDRConflictHandlerType event_type);
+static const char *bdr_conflict_handlers_event_type_name(BdrConflictType event_type);
 
 static Oid bdr_conflict_handler_table_oid = InvalidOid;
 static Oid bdr_conflict_handler_type_oid = InvalidOid;
@@ -107,7 +107,7 @@ bdr_conflict_handlers_init(void)
        elog(ERROR, "cache lookup failed for relation bdr.bdr_conflict_handlers");
 
    bdr_conflict_handler_type_oid =
-       GetSysCacheOidError2(TYPENAMENSP, PointerGetDatum("bdr_handler_types"),
+       GetSysCacheOidError2(TYPENAMENSP, PointerGetDatum("bdr_conflict_type"),
                             ObjectIdGetDatum(schema_oid));
 
    bdr_conflict_handler_action_oid =
@@ -532,7 +532,7 @@ bdr_conflict_handlers_check_handler_fun(Relation rel, Oid proc_oid)
    if (failed)
        ereport(ERROR,
                (errmsg("handler function is expected to accept " \
-       "tablerow IN, tablerow IN, text IN, text IN, bdr_handler_types IN," \
+       "tablerow IN, tablerow IN, text IN, text IN, bdr_conflict_type IN," \
                        "tablerow OUT, bdr_conflict_handler_action OUT")));
 }
 
@@ -616,14 +616,14 @@ bdr_get_conflict_handlers(BDRRelation * rel)
 
            htype = TextDatumGetCString(dat);
 
-           if (strcmp(htype, "UPDATE_VS_UPDATE") == 0)
-               rel->conflict_handlers[i].handler_type = BDRUpdateUpdateConflictHandler;
-           else if (strcmp(htype, "UPDATE_VS_DELETE") == 0)
-               rel->conflict_handlers[i].handler_type = BDRUpdateDeleteConflictHandler;
-           else if (strcmp(htype, "INSERT_VS_INSERT") == 0)
-               rel->conflict_handlers[i].handler_type = BDRInsertInsertConflictHandler;
-           else if (strcmp(htype, "INSERT_VS_UPDATE") == 0)
-               rel->conflict_handlers[i].handler_type = BDRInsertUpdateConflictHandler;
+           if (strcmp(htype, "update_update") == 0)
+               rel->conflict_handlers[i].handler_type = BdrConflictType_UpdateUpdate;
+           else if (strcmp(htype, "update_delete") == 0)
+               rel->conflict_handlers[i].handler_type = BdrConflictType_UpdateDelete;
+           else if (strcmp(htype, "insert_insert") == 0)
+               rel->conflict_handlers[i].handler_type = BdrConflictType_InsertInsert;
+           else if (strcmp(htype, "insert_update") == 0)
+               rel->conflict_handlers[i].handler_type = BdrConflictType_InsertUpdate;
            else
                elog(ERROR, "unknown handler type: %s", htype);
 
@@ -649,18 +649,25 @@ bdr_get_conflict_handlers(BDRRelation * rel)
 }
 
 static const char *
-bdr_conflict_handlers_event_type_name(BDRConflictHandlerType event_type)
+bdr_conflict_handlers_event_type_name(BdrConflictType event_type)
 {
    switch (event_type)
    {
-       case BDRUpdateUpdateConflictHandler:
-           return "UPDATE_VS_UPDATE";
-       case BDRUpdateDeleteConflictHandler:
-           return "UPDATE_VS_DELETE";
-       case BDRInsertInsertConflictHandler:
-           return "INSERT_VS_INSERT";
-       case BDRInsertUpdateConflictHandler:
-           return "INSERT_VS_UPDATE";
+       case BdrConflictType_InsertInsert:
+           return "insert_insert";
+       case BdrConflictType_InsertUpdate:
+           return "insert_update";
+       case BdrConflictType_UpdateUpdate:
+           return "update_update";
+       case BdrConflictType_UpdateDelete:
+           return "update_delete";
+       case BdrConflictType_UnhandledTxAbort:
+           return "unhandled_tx_abort";
+
+       default:
+           elog(ERROR,
+                "wrong value for event type, possibly corrupted memory: %d",
+               event_type);
    }
 
    return "(unknown)";
@@ -673,7 +680,7 @@ bdr_conflict_handlers_event_type_name(BDRConflictHandlerType event_type)
 HeapTuple
 bdr_conflict_handlers_resolve(BDRRelation * rel, const HeapTuple local,
                              const HeapTuple remote, const char *command_tag,
-                             BDRConflictHandlerType event_type,
+                             BdrConflictType event_type,
                              uint64 timeframe, bool *skip)
 {
    size_t      i;
index f3c904bf893337b55d93665fbebed025575710b1..94d9bbe7e37278f037a352709998d77c6e622cf4 100644 (file)
@@ -146,6 +146,9 @@ bdr_conflict_type_get_datum(BdrConflictType conflict_type)
        case BdrConflictType_InsertInsert:
            enumname = "insert_insert";
            break;
+       case BdrConflictType_InsertUpdate:
+           enumname = "insert_update";
+           break;
        case BdrConflictType_UpdateUpdate:
            enumname = "update_update";
            break;