@@ -962,14 +962,17 @@ process_remote_commit(StringInfo in, GlobalTransactionId *current_gtid, MtmRecei
962962			strncpy (gid , pq_getmsgstring (in ), sizeof  gid );
963963			MtmBeginSession (origin_node );
964964
965- 			if  (!IsTransactionState ()) {
965+ 			if  (!IsTransactionState ())
966+ 			{
966967				StartTransactionCommand ();
967968				SetPreparedTransactionState (gid , MULTIMASTER_PRECOMMITTED );
968969				CommitTransactionCommand ();
970+ 
969971				MemoryContextSwitchTo (MtmApplyContext );
970- 			} else  {
971- 				SetPreparedTransactionState (gid , MULTIMASTER_PRECOMMITTED );
972972			}
973+ 			else 
974+ 				SetPreparedTransactionState (gid , MULTIMASTER_PRECOMMITTED );
975+ 
973976			mtm_log (MtmTxFinish , "TXFINISH: %s precommitted" , gid );
974977
975978			if  (receiver_ctx -> parallel_allowed )
@@ -1030,7 +1033,6 @@ process_remote_commit(StringInfo in, GlobalTransactionId *current_gtid, MtmRecei
10301033			current_gtid -> my_xid  =  InvalidTransactionId ;
10311034			MtmDeadlockDetectorRemoveXact (xid );
10321035
1033- 
10341036			MtmEndSession (origin_node , true);
10351037
10361038			mtm_log (MtmApplyTrace ,
@@ -1455,77 +1457,76 @@ MtmExecutor(void* work, size_t size, MtmReceiverContext *receiver_ctx)
14551457    s .len  =  size ;
14561458    s .maxlen  =  -1 ;
14571459	s .cursor  =  0 ;
1458- 	 
1460+ 
14591461	if  (MtmApplyContext  ==  NULL )
1460- 	{
14611462		MtmApplyContext  =  AllocSetContextCreate (TopMemoryContext ,
14621463												"ApplyContext" ,
14631464												ALLOCSET_DEFAULT_SIZES );
1464-     } 
1465+ 
14651466	top_context  =  MemoryContextSwitchTo (MtmApplyContext );
14661467	replorigin_session_origin  =  InvalidRepOriginId ;
14671468
14681469	PG_TRY ();
1469- 
1470- 	AcceptInvalidationMessages ();
1471- 	if  (!receiver_mtm_cfg_valid )
14721470	{
1473- 		if  (receiver_mtm_cfg )
1474- 			pfree (receiver_mtm_cfg );
1471+ 		bool  inside_transaction  =  true;
14751472
1476- 		receiver_mtm_cfg   =   MtmLoadConfig ();
1473+ 		AcceptInvalidationMessages ();
14771474
1478- 		if  (receiver_mtm_cfg -> my_node_id  ==  0  || 
1479- 			MtmNodeById (receiver_mtm_cfg , receiver_ctx -> node_id ) ==  NULL ) //XXX 
1480- 			proc_exit (0 );
1475+ 		/* Clear authorization settings */ 
1476+ 		StartTransactionCommand ();
1477+ 		SetPGVariable ("session_authorization" , NIL , false);
1478+ 		ResetAllOptions ();
1479+ 		CommitTransactionCommand ();
14811480
1482- 		receiver_mtm_cfg_valid  =  true;
1483- 	}
1481+ 		if  (!receiver_mtm_cfg_valid )
1482+ 		{
1483+ 			if  (receiver_mtm_cfg )
1484+ 				pfree (receiver_mtm_cfg );
1485+ 			receiver_mtm_cfg  =  MtmLoadConfig ();
1486+ 			if  (receiver_mtm_cfg -> my_node_id  ==  0  || 
1487+ 				MtmNodeById (receiver_mtm_cfg , receiver_ctx -> node_id ) ==  NULL ) //XXX 
1488+ 				proc_exit (0 );
1489+ 
1490+ 			receiver_mtm_cfg_valid  =  true;
1491+ 		}
14841492
1485- 	StartTransactionCommand ();
1486- 	SetPGVariable ("session_authorization" , NIL , false);
1487- 	ResetAllOptions ();
1488- 	CommitTransactionCommand ();
1493+ 		do  {
1494+ 			char  action  =  pq_getmsgbyte (& s );
14891495
1490-     {    
1491- 		bool  inside_transaction  =  true;
1492-         do  { 
1493-             char  action  =  pq_getmsgbyte (& s );
14941496			old_context  =  MemoryContextSwitchTo (MtmApplyContext );
1495- 
14961497			mtm_log (MtmApplyTrace , "got action '%c'" , action );
14971498
14981499			switch  (action )
14991500			{
1500-                  /* BEGIN */ 
1501-              case  'B' :
1502- 			     inside_transaction  =  process_remote_begin (& s , & current_gtid );
1501+ 				 /* BEGIN */ 
1502+ 			 case  'B' :
1503+ 				 inside_transaction  =  process_remote_begin (& s , & current_gtid );
15031504				break ;
1504-                  /* COMMIT */ 
1505-              case  'C' :
1506-    			     close_rel (rel );
1505+ 				 /* COMMIT */ 
1506+ 			 case  'C' :
1507+ 				 close_rel (rel );
15071508				process_remote_commit (& s , & current_gtid , receiver_ctx );
15081509				inside_transaction  =  false;
1509-                  break ;
1510-                  /* INSERT */ 
1511-              case  'I' :
1510+ 				 break ;
1511+ 				 /* INSERT */ 
1512+ 			 case  'I' :
15121513				Assert (rel );
1513- 			     process_remote_insert (& s , rel );
1514-                  break ;
1515-                  /* UPDATE */ 
1516-              case  'U' :
1514+ 				 process_remote_insert (& s , rel );
1515+ 				 break ;
1516+ 				 /* UPDATE */ 
1517+ 			 case  'U' :
15171518				Assert (rel );
1518-                  process_remote_update (& s , rel );
1519-                  break ;
1520-                  /* DELETE */ 
1521-              case  'D' :
1519+ 				 process_remote_update (& s , rel );
1520+ 				 break ;
1521+ 				 /* DELETE */ 
1522+ 			 case  'D' :
15221523				Assert (rel );
1523-                  process_remote_delete (& s , rel );
1524-                  break ;
1525-              case  'R' :
1526-    			     close_rel (rel );
1527-                  rel  =  read_rel (& s , RowExclusiveLock );
1528-                  break ;
1524+ 				 process_remote_delete (& s , rel );
1525+ 				 break ;
1526+ 			 case  'R' :
1527+ 				 close_rel (rel );
1528+ 				 rel  =  read_rel (& s , RowExclusiveLock );
1529+ 				 break ;
15291530			case  'F' :
15301531			{
15311532				int  node_id  =  pq_getmsgint (& s , 4 );
@@ -1534,9 +1535,10 @@ MtmExecutor(void* work, size_t size, MtmReceiverContext *receiver_ctx)
15341535				spill_file  =  MtmOpenSpillFile (node_id , file_id );
15351536				break ;
15361537			}
1537-  		     case  '(' :
1538+ 			 case  '(' :
15381539			{
1539- 			    size_t  size  =  pq_getmsgint (& s , 4 );    
1540+ 				size_t  size  =  pq_getmsgint (& s , 4 );
1541+ 
15401542				s .data  =  MemoryContextAlloc (TopMemoryContext , size );
15411543				save_cursor  =  s .cursor ;
15421544				save_len  =  s .len ;
@@ -1545,14 +1547,12 @@ MtmExecutor(void* work, size_t size, MtmReceiverContext *receiver_ctx)
15451547				MtmReadSpillFile (spill_file , s .data , size );
15461548				break ;
15471549			}
1548-   		    case  ')' :
1549- 			{
1550-   			    pfree (s .data );
1550+ 			case  ')' :
1551+ 				pfree (s .data );
15511552				s .data  =  work ;
1552-    			     s .cursor  =  save_cursor ;
1553+ 				 s .cursor  =  save_cursor ;
15531554				s .len  =  save_len ;
15541555				break ;
1555- 			}
15561556			case  'N' :
15571557			{
15581558				int64  next ;
@@ -1565,17 +1565,15 @@ MtmExecutor(void* work, size_t size, MtmReceiverContext *receiver_ctx)
15651565				AdjustSequence (relid , next );
15661566				break ;
15671567			}
1568- 		     case  '0' :
1569- 			     Assert (rel  !=  NULL );
1570- 			     heap_truncate_one_rel (rel );
1568+ 			 case  '0' :
1569+ 				 Assert (rel  !=  NULL );
1570+ 				 heap_truncate_one_rel (rel );
15711571				break ;
15721572			case  'M' :
1573- 			{
1574-   			    close_rel (rel );
1573+ 				close_rel (rel );
15751574				rel  =  NULL ;
15761575				inside_transaction  =  !process_remote_message (& s , receiver_ctx );
15771576				break ;
1578- 			}
15791577			case  'Z' :
15801578			{
15811579				int 			rc ;
@@ -1647,10 +1645,6 @@ MtmExecutor(void* work, size_t size, MtmReceiverContext *receiver_ctx)
16471645	}
16481646	PG_END_TRY ();
16491647
1650- 	// Assert(s.cursor == s.len); 
1651- 	// only non-error scenario 
1652- 	// Assert(s.data == work); 
1653- 
16541648	if  (s .data  !=  work )
16551649		pfree (s .data );
16561650	MemoryContextSwitchTo (top_context );
0 commit comments