From: Steve Singer Date: Sat, 15 Apr 2017 00:28:58 +0000 (-0400) Subject: Further changes related to 'Explicitly disallow createEvent and data changes in the... X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=ef15a34f71e62bb27471981bbda78f526a08a93e;p=slony1-engine.git Further changes related to 'Explicitly disallow createEvent and data changes in the same transaction' Add in support where the logApply trigger inserst data into a table that has trigger ,which runs on the replica,that then inserts data into another replicated table. The logApply trigger might have already been called in this transaction but the logTrigger is then called in the same transaction. We then need to setup the plans for inserting data into sl_log_1 or sl_log_2 --- diff --git a/src/backend/slony1_funcs.c b/src/backend/slony1_funcs.c index 657589e9..f4db2d82 100644 --- a/src/backend/slony1_funcs.c +++ b/src/backend/slony1_funcs.c @@ -151,7 +151,9 @@ typedef struct slony_I_cluster_status text *cmdtype_I; text *cmdtype_U; text *cmdtype_D; - bool event_txn; + bool event_txn; + bool apply_init; + bool log_init; struct slony_I_cluster_status *next; } Slony_I_ClusterStatus; @@ -255,10 +257,19 @@ versionFunc(createEvent) (PG_FUNCTION_ARGS) /* * Do the following only once per transaction. */ - if (!TransactionIdEquals(cs->currentXid, newXid)) + if (!TransactionIdEquals(cs->currentXid, newXid) ) { cs->currentXid = newXid; cs->event_txn = true; + cs->apply_init = false; + cs->log_init = false; + } + else if (!cs->log_init) + { + /** + * This transaction has been setup for apply but not logging. + */ + cs->event_txn = true; } if(!cs->event_txn) @@ -436,10 +447,28 @@ versionFunc(logTrigger) (PG_FUNCTION_ARGS) */ cs = getClusterStatus(cluster_name, PLAN_INSERT_LOG_STATUS); + bool initRequired = false; + if(!TransactionIdEquals(cs->currentXid, newXid)) + { + initRequired = true; + cs->apply_init = false; + cs->event_txn=false; + cs->log_init = true; + } + else if (!cs->log_init) + { + initRequired = true; + } + + if(cs->event_txn) + { + elog(ERROR,"Slony-I: log trigger called in an event transaction"); + } + /* * Do the following only once per transaction. */ - if (!TransactionIdEquals(cs->currentXid, newXid)) + if (initRequired) { int32 log_status; bool isnull; @@ -474,13 +503,11 @@ versionFunc(logTrigger) (PG_FUNCTION_ARGS) } cs->currentXid = newXid; - cs->event_txn=false; + cs->event_txn = false; + cs->log_init = true; } - if(cs->event_txn) - { - elog(ERROR,"Slony-I: log trigger called in an event transaction"); - } + /* * Save the current datestyle setting and switch to ISO (if not already) */ @@ -931,7 +958,19 @@ versionFunc(logApply) (PG_FUNCTION_ARGS) /* * Do the following only once per transaction. */ - if (!TransactionIdEquals(cs->currentXid, newXid)) + bool planInitRequired = false; + if(!TransactionIdEquals(cs->currentXid, newXid)) + { + planInitRequired = true; + cs->log_init = false; + cs->event_txn=false; + } + else if (!cs->apply_init) + { + planInitRequired = true; + } + + if (planInitRequired) { HASHCTL hctl; @@ -992,6 +1031,7 @@ versionFunc(logApply) (PG_FUNCTION_ARGS) apply_num_evict = 0; cs->currentXid = newXid; + cs->apply_init = true; } /*