49
49
#include "replication/walsender.h"
50
50
#include "replication/walsender_private.h"
51
51
#include "replication/slot.h"
52
+ #include "replication/message.h"
52
53
#include "port/atomics.h"
53
54
#include "tcop/utility.h"
54
55
#include "nodes/makefuncs.h"
@@ -235,8 +236,8 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
235
236
ProcessUtilityContext context , ParamListInfo params ,
236
237
DestReceiver * dest , char * completionTag );
237
238
238
- // static StringInfo MtmGUCBuffer;
239
- // static bool MtmGUCBufferAllocated = false;
239
+ static StringInfo MtmGUCBuffer ;
240
+ static bool MtmGUCBufferAllocated = false;
240
241
241
242
/*
242
243
* -------------------------------------------
@@ -3024,53 +3025,55 @@ static void MtmBroadcastUtilityStmt(char const* sql, bool ignoreError)
3024
3025
}
3025
3026
}
3026
3027
3027
- static bool MtmProcessDDLCommand (char const * queryString )
3028
- {
3029
- RangeVar * rv ;
3030
- Relation rel ;
3031
- TupleDesc tupDesc ;
3032
- HeapTuple tup ;
3033
- Datum values [Natts_mtm_ddl_log ];
3034
- bool nulls [Natts_mtm_ddl_log ];
3035
- TimestampTz ts = GetCurrentTimestamp ();
3036
-
3037
- rv = makeRangeVar ("public" , MULTIMASTER_DDL_TABLE , -1 );
3038
- rel = heap_openrv_extended (rv , RowExclusiveLock , true);
3028
+ static void MtmGUCBufferAppend (const char * gucQueryString ){
3039
3029
3040
- if (rel == NULL ) {
3041
- if (!MtmIsBroadcast ()) {
3042
- MtmBroadcastUtilityStmt (queryString , false);
3043
- return true;
3044
- }
3045
- return false;
3030
+ if (!MtmGUCBufferAllocated )
3031
+ {
3032
+ MemoryContext oldcontext ;
3033
+ oldcontext = MemoryContextSwitchTo (TopMemoryContext );
3034
+ MtmGUCBuffer = makeStringInfo ();
3035
+ MemoryContextSwitchTo (oldcontext );
3036
+ MtmGUCBufferAllocated = true;
3037
+ appendStringInfoString (MtmGUCBuffer , "RESET SESSION AUTHORIZATION; reset all;" );
3046
3038
}
3047
-
3048
- tupDesc = RelationGetDescr (rel );
3049
3039
3050
- /* Form a tuple. */
3051
- memset (nulls , false, sizeof (nulls ));
3052
-
3053
- values [Anum_mtm_ddl_log_issued - 1 ] = TimestampTzGetDatum (ts );
3054
- values [Anum_mtm_ddl_log_query - 1 ] = CStringGetTextDatum (queryString );
3040
+ appendStringInfoString (MtmGUCBuffer , gucQueryString );
3041
+ /* sometimes there is no ';' char at the end. */
3042
+ // appendStringInfoString(MtmGUCBuffer, ";");
3043
+ }
3055
3044
3056
- tup = heap_form_tuple (tupDesc , values , nulls );
3045
+ static char * MtmGUCBufferGet (void ){
3046
+ if (!MtmGUCBufferAllocated )
3047
+ MtmGUCBufferAppend ("" );
3048
+ return MtmGUCBuffer -> data ;
3049
+ }
3057
3050
3058
- /* Insert the tuple to the catalog. */
3059
- simple_heap_insert (rel , tup );
3051
+ static bool MtmProcessDDLCommand (char const * queryString )
3052
+ {
3053
+ char * queryWithContext ;
3054
+ char * gucContext ;
3060
3055
3061
- /* Update the indexes. */
3062
- CatalogUpdateIndexes (rel , tup );
3056
+ /* Append global GUC to utility stmt. */
3057
+ gucContext = MtmGUCBufferGet ();
3058
+ if (gucContext )
3059
+ {
3060
+ queryWithContext = palloc (strlen (gucContext ) + strlen (queryString ) + 1 );
3061
+ strcpy (queryWithContext , gucContext );
3062
+ strcat (queryWithContext , queryString );
3063
+ }
3064
+ else
3065
+ {
3066
+ queryWithContext = (char * ) queryString ;
3067
+ }
3063
3068
3064
- /* Cleanup. */
3065
- heap_freetuple (tup );
3066
- heap_close (rel , RowExclusiveLock );
3069
+ MTM_LOG1 ("Sending utility: %s" , queryWithContext );
3070
+ LogLogicalMessage ("MTM:GUC" , queryWithContext , strlen (queryWithContext ), true);
3067
3071
3068
3072
MtmTx .containsDML = true;
3069
3073
return false;
3070
3074
}
3071
3075
3072
3076
3073
-
3074
3077
/*
3075
3078
* Genenerate global transaction identifier for two-pahse commit.
3076
3079
* It should be unique for all nodes
@@ -3170,43 +3173,28 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
3170
3173
DiscardStmt * stmt = (DiscardStmt * ) parsetree ;
3171
3174
skipCommand = stmt -> target == DISCARD_TEMP ;
3172
3175
3173
- // skipCommand = true;
3174
-
3175
- // if (MtmGUCBufferAllocated)
3176
- // {
3177
- // // XXX: move allocation somewhere to backend startup and check
3178
- // // where buffer is empty in send routines.
3179
- // MtmGUCBufferAllocated = false;
3180
- // pfree(MtmGUCBuffer);
3181
- // }
3182
-
3176
+ if (!IsTransactionBlock ())
3177
+ {
3178
+ skipCommand = true;
3179
+ MtmGUCBufferAppend (queryString );
3180
+ }
3183
3181
}
3184
3182
break ;
3185
3183
case T_VariableSetStmt :
3186
3184
{
3187
3185
VariableSetStmt * stmt = (VariableSetStmt * ) parsetree ;
3188
3186
3189
- skipCommand = true;
3187
+ // skipCommand = true;
3190
3188
3191
3189
/* Prevent SET TRANSACTION from replication */
3192
3190
if (stmt -> kind == VAR_SET_MULTI )
3193
- // break;
3194
3191
skipCommand = true;
3195
3192
3196
- // if (!MtmGUCBufferAllocated)
3197
- // {
3198
- // MemoryContext oldcontext;
3199
-
3200
- // oldcontext = MemoryContextSwitchTo(TopMemoryContext);
3201
- // MtmGUCBuffer = makeStringInfo();
3202
- // MemoryContextSwitchTo(oldcontext);
3203
- // MtmGUCBufferAllocated = true;
3204
- // }
3205
-
3206
- // appendStringInfoString(MtmGUCBuffer, queryString);
3207
-
3208
- // sometimes there is no ';' char at the end.
3209
- // appendStringInfoString(MtmGUCBuffer, ";");
3193
+ if (!IsTransactionBlock ())
3194
+ {
3195
+ skipCommand = true;
3196
+ MtmGUCBufferAppend (queryString );
3197
+ }
3210
3198
}
3211
3199
break ;
3212
3200
case T_CreateTableAsStmt :
@@ -3232,7 +3220,8 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
3232
3220
3233
3221
viewParse = parse_analyze ((Node * ) copyObject (stmt -> query ),
3234
3222
queryString , NULL , 0 );
3235
- skipCommand = isQueryUsingTempRelation (viewParse );
3223
+ skipCommand = isQueryUsingTempRelation (viewParse ) ||
3224
+ stmt -> view -> relpersistence == RELPERSISTENCE_TEMP ;
3236
3225
// ||
3237
3226
// (stmt->relation->schemaname && strcmp(stmt->relation->schemaname, "pg_temp") == 0);
3238
3227
}
0 commit comments