5656#include "catalog/indexing.h"
5757#include "catalog/namespace.h"
5858#include "pglogical_output/hooks.h"
59+ #include "parser/analyze.h"
60+ #include "parser/parse_relation.h"
5961
6062#include "multimaster.h"
6163#include "ddd.h"
@@ -147,6 +149,7 @@ static void MtmShmemStartup(void);
147149static BgwPool * MtmPoolConstructor (void );
148150static bool MtmRunUtilityStmt (PGconn * conn , char const * sql , char * * errmsg );
149151static void MtmBroadcastUtilityStmt (char const * sql , bool ignoreError );
152+ static bool MtmProcessDDLCommand (char const * queryString );
150153
151154MtmState * Mtm ;
152155
@@ -175,7 +178,8 @@ static TransactionManager MtmTM = {
175178 MtmGetTransactionStateSize ,
176179 MtmSerializeTransactionState ,
177180 MtmDeserializeTransactionState ,
178- MtmInitializeSequence
181+ // MtmInitializeSequence
182+ PgInitializeSequence
179183};
180184
181185char const * const MtmNodeStatusMnem [] =
@@ -207,6 +211,8 @@ int MtmHeartbeatRecvTimeout;
207211bool MtmUseRaftable ;
208212bool MtmUseDtm ;
209213
214+ // static int reset_wrokers = 0;
215+
210216static char * MtmConnStrs ;
211217static int MtmQueueSize ;
212218static int MtmWorkers ;
@@ -228,8 +234,8 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
228234 ProcessUtilityContext context , ParamListInfo params ,
229235 DestReceiver * dest , char * completionTag );
230236
231- static StringInfo MtmGUCBuffer ;
232- static bool MtmGUCBufferAllocated = false;
237+ // static StringInfo MtmGUCBuffer;
238+ // static bool MtmGUCBufferAllocated = false;
233239
234240/*
235241 * -------------------------------------------
@@ -614,7 +620,7 @@ MtmXactCallback(XactEvent event, void *arg)
614620{
615621 switch (event )
616622 {
617- case XACT_EVENT_START :
623+ case XACT_EVENT_START :
618624 MtmBeginTransaction (& MtmTx );
619625 break ;
620626 case XACT_EVENT_PRE_PREPARE :
@@ -1159,8 +1165,8 @@ void MtmHandleApplyError(void)
11591165 case ERRCODE_OUT_OF_MEMORY :
11601166 elog (WARNING , "Node is excluded from cluster because of non-recoverable error %d, %s, pid=%u" ,
11611167 edata -> sqlerrcode , edata -> message , getpid ());
1162- MtmSwitchClusterMode (MTM_OUT_OF_SERVICE );
1163- kill (PostmasterPid , SIGQUIT );
1168+ // MtmSwitchClusterMode(MTM_OUT_OF_SERVICE);
1169+ // kill(PostmasterPid, SIGQUIT);
11641170 break ;
11651171 }
11661172 FreeErrorData (edata );
@@ -2929,13 +2935,13 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
29292935 {
29302936 if (conns [i ])
29312937 {
2932- if (MtmGUCBufferAllocated && !MtmRunUtilityStmt (conns [i ], MtmGUCBuffer -> data , & utility_errmsg ) && !ignoreError )
2933- {
2934- errorMsg = "Failed to set GUC variables at node %d" ;
2935- elog (WARNING , "%s" , utility_errmsg );
2936- failedNode = i ;
2937- break ;
2938- }
2938+ // if (MtmGUCBufferAllocated && !MtmRunUtilityStmt(conns[i], MtmGUCBuffer->data, &utility_errmsg) && !ignoreError)
2939+ // {
2940+ // errorMsg = "Failed to set GUC variables at node %d";
2941+ // elog(WARNING, "%s", utility_errmsg);
2942+ // failedNode = i;
2943+ // break;
2944+ // }
29392945 if (!MtmRunUtilityStmt (conns [i ], "BEGIN TRANSACTION" , & utility_errmsg ) && !ignoreError )
29402946 {
29412947 errorMsg = "Failed to start transaction at node %d" ;
@@ -2999,7 +3005,7 @@ static bool MtmProcessDDLCommand(char const* queryString)
29993005 bool nulls [Natts_mtm_ddl_log ];
30003006 TimestampTz ts = GetCurrentTimestamp ();
30013007
3002- rv = makeRangeVar (MULTIMASTER_SCHEMA_NAME , MULTIMASTER_DDL_TABLE , -1 );
3008+ rv = makeRangeVar ("public" , MULTIMASTER_DDL_TABLE , -1 );
30033009 rel = heap_openrv_extended (rv , RowExclusiveLock , true);
30043010
30053011 if (rel == NULL ) {
@@ -3132,18 +3138,18 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
31323138 break ;
31333139 case T_DiscardStmt :
31343140 {
3135- // DiscardStmt *stmt = (DiscardStmt *) parsetree;
3136- // skipCommand = stmt->target == DISCARD_TEMP;
3141+ DiscardStmt * stmt = (DiscardStmt * ) parsetree ;
3142+ skipCommand = stmt -> target == DISCARD_TEMP ;
31373143
3138- skipCommand = true;
3144+ // skipCommand = true;
31393145
3140- if (MtmGUCBufferAllocated )
3141- {
3142- // XXX: move allocation somewhere to backend startup and check
3143- // where buffer is empty in send routines.
3144- MtmGUCBufferAllocated = false;
3145- pfree (MtmGUCBuffer );
3146- }
3146+ // if (MtmGUCBufferAllocated)
3147+ // {
3148+ // // XXX: move allocation somewhere to backend startup and check
3149+ // // where buffer is empty in send routines.
3150+ // MtmGUCBufferAllocated = false;
3151+ // pfree(MtmGUCBuffer);
3152+ // }
31473153
31483154 }
31493155 break ;
@@ -3155,22 +3161,31 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
31553161
31563162 /* Prevent SET TRANSACTION from replication */
31573163 if (stmt -> kind == VAR_SET_MULTI )
3158- break ;
3164+ // break;
3165+ skipCommand = true;
31593166
3160- if (!MtmGUCBufferAllocated )
3161- {
3162- MemoryContext oldcontext ;
3167+ // if (!MtmGUCBufferAllocated)
3168+ // {
3169+ // MemoryContext oldcontext;
31633170
3164- oldcontext = MemoryContextSwitchTo (TopMemoryContext );
3165- MtmGUCBuffer = makeStringInfo ();
3166- MemoryContextSwitchTo (oldcontext );
3167- MtmGUCBufferAllocated = true;
3168- }
3171+ // oldcontext = MemoryContextSwitchTo(TopMemoryContext);
3172+ // MtmGUCBuffer = makeStringInfo();
3173+ // MemoryContextSwitchTo(oldcontext);
3174+ // MtmGUCBufferAllocated = true;
3175+ // }
31693176
3170- appendStringInfoString (MtmGUCBuffer , queryString );
3177+ // appendStringInfoString(MtmGUCBuffer, queryString);
31713178
31723179 // sometimes there is no ';' char at the end.
3173- appendStringInfoString (MtmGUCBuffer , ";" );
3180+ // appendStringInfoString(MtmGUCBuffer, ";");
3181+ }
3182+ break ;
3183+ case T_CreateTableAsStmt :
3184+ {
3185+ /* Do not replicate temp tables */
3186+ CreateTableAsStmt * stmt = (CreateTableAsStmt * ) parsetree ;
3187+ skipCommand = stmt -> into -> rel -> relpersistence == RELPERSISTENCE_TEMP ||
3188+ (stmt -> into -> rel -> schemaname && strcmp (stmt -> into -> rel -> schemaname , "pg_temp" ) == 0 );
31743189 }
31753190 break ;
31763191 case T_CreateStmt :
@@ -3181,6 +3196,18 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
31813196 (stmt -> relation -> schemaname && strcmp (stmt -> relation -> schemaname , "pg_temp" ) == 0 );
31823197 }
31833198 break ;
3199+ case T_ViewStmt :
3200+ {
3201+ ViewStmt * stmt = (ViewStmt * ) parsetree ;
3202+ Query * viewParse ;
3203+
3204+ viewParse = parse_analyze ((Node * ) copyObject (stmt -> query ),
3205+ queryString , NULL , 0 );
3206+ skipCommand = isQueryUsingTempRelation (viewParse );
3207+ // ||
3208+ // (stmt->relation->schemaname && strcmp(stmt->relation->schemaname, "pg_temp") == 0);
3209+ }
3210+ break ;
31843211 case T_IndexStmt :
31853212 {
31863213 Oid relid ;
@@ -3219,6 +3246,19 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
32193246 heap_close (rel , ShareLock );
32203247 }
32213248 }
3249+ else if (stmt -> removeType == OBJECT_INDEX )
3250+ {
3251+ RangeVar * rv = makeRangeVarFromNameList (
3252+ (List * ) lfirst (list_head (stmt -> objects )));
3253+ Oid relid = RelnameGetRelid (rv -> relname );
3254+
3255+ if (OidIsValid (relid ))
3256+ {
3257+ Relation irel = index_open (relid , ShareLock );
3258+ skipCommand = irel -> rd_rel -> relpersistence == RELPERSISTENCE_TEMP ;
3259+ index_close (irel , ShareLock );
3260+ }
3261+ }
32223262 }
32233263 break ;
32243264 case T_CopyStmt :
0 commit comments