@@ -79,6 +79,8 @@ static void process_remote_insert(StringInfo s, Relation rel);
79
79
static void process_remote_update (StringInfo s , Relation rel );
80
80
static void process_remote_delete (StringInfo s , Relation rel );
81
81
82
+ static MemoryContext TopContext ;
83
+
82
84
/*
83
85
* Search the index 'idxrel' for a tuple identified by 'skey' in 'rel'.
84
86
*
@@ -377,34 +379,31 @@ process_remote_message(StringInfo s)
377
379
case 'D' :
378
380
{
379
381
int rc ;
380
-
381
382
MTM_LOG1 ("%d: Executing utility statement %s" , MyProcPid , messageBody );
382
383
SPI_connect ();
383
384
ActivePortal -> sourceText = messageBody ;
384
385
MtmVacuumStmt = NULL ;
385
386
MtmIndexStmt = NULL ;
387
+ MtmDropStmt = NULL ;
386
388
rc = SPI_execute (messageBody , false, 0 );
387
389
SPI_finish ();
388
390
if (rc < 0 ) {
389
391
elog (ERROR , "Failed to execute utility statement %s" , messageBody );
390
392
} else {
391
393
if (MtmVacuumStmt != NULL ) {
392
394
ExecVacuum (MtmVacuumStmt , 1 );
393
- } else if (MtmIndexStmt != NULL ) {
394
- MemoryContext saveCtx = TopTransactionContext ;
395
- Oid relid ;
396
-
397
- TopTransactionContext = MtmApplyContext ;
398
- relid = RangeVarGetRelidExtended (MtmIndexStmt -> relation , ShareUpdateExclusiveLock ,
399
- false, false,
400
- NULL ,
401
- NULL );
395
+ } else if (MtmIndexStmt != NULL ) {
396
+ Oid relid = RangeVarGetRelidExtended (MtmIndexStmt -> relation , ShareUpdateExclusiveLock ,
397
+ false, false,
398
+ NULL ,
399
+ NULL );
402
400
403
401
/* Run parse analysis ... */
404
- MtmIndexStmt = transformIndexStmt (relid , MtmIndexStmt , messageBody );
402
+ // MtmIndexStmt = transformIndexStmt(relid, MtmIndexStmt, messageBody);
405
403
406
404
PushActiveSnapshot (GetTransactionSnapshot ());
407
405
406
+
408
407
DefineIndex (relid , /* OID of heap relation */
409
408
MtmIndexStmt ,
410
409
InvalidOid , /* no predefined OID */
@@ -413,11 +412,11 @@ process_remote_message(StringInfo s)
413
412
false, /* skip_build */
414
413
false); /* quiet */
415
414
416
- TopTransactionContext = saveCtx ;
417
-
418
415
if (ActiveSnapshotSet ())
419
416
PopActiveSnapshot ();
420
417
418
+ } else if (MtmDropStmt != NULL ) {
419
+ RemoveObjects (MtmDropStmt );
421
420
}
422
421
}
423
422
if (standalone ) {
@@ -1025,12 +1024,12 @@ void MtmExecutor(void* work, size_t size)
1025
1024
1026
1025
if (MtmApplyContext == NULL ) {
1027
1026
MtmApplyContext = AllocSetContextCreate (TopMemoryContext ,
1028
- "MessageContext " ,
1029
- ALLOCSET_DEFAULT_MINSIZE ,
1030
- ALLOCSET_DEFAULT_INITSIZE ,
1031
- ALLOCSET_DEFAULT_MAXSIZE );
1027
+ "ApplyContext " ,
1028
+ ALLOCSET_DEFAULT_MINSIZE ,
1029
+ ALLOCSET_DEFAULT_INITSIZE ,
1030
+ ALLOCSET_DEFAULT_MAXSIZE );
1032
1031
}
1033
- MemoryContextSwitchTo (MtmApplyContext );
1032
+ TopContext = MemoryContextSwitchTo (MtmApplyContext );
1034
1033
replorigin_session_origin = InvalidRepOriginId ;
1035
1034
PG_TRY ();
1036
1035
{
0 commit comments