@@ -592,15 +592,23 @@ MtmRefereeHasLocalTable()
592
592
RangeVar * rv ;
593
593
Oid rel_oid ;
594
594
static bool _has_local_tables ;
595
+ bool txstarted = false;
595
596
596
597
/* memoized */
597
598
if (_has_local_tables )
598
599
return true;
599
600
600
- StartTransactionCommand ();
601
+ if (!IsTransactionState ())
602
+ {
603
+ txstarted = true;
604
+ StartTransactionCommand ();
605
+ }
606
+
601
607
rv = makeRangeVar (MULTIMASTER_SCHEMA_NAME , "referee_decision" , -1 );
602
608
rel_oid = RangeVarGetRelid (rv , NoLock , true);
603
- CommitTransactionCommand ();
609
+
610
+ if (txstarted )
611
+ CommitTransactionCommand ();
604
612
605
613
if (OidIsValid (rel_oid ))
606
614
{
@@ -617,12 +625,17 @@ MtmRefereeReadSaved(void)
617
625
{
618
626
int winner = -1 ;
619
627
int rc ;
628
+ bool txstarted = false;
620
629
621
630
if (!MtmRefereeHasLocalTable ())
622
631
return -1 ;
623
632
624
633
/* Save result locally */
625
- StartTransactionCommand ();
634
+ if (!IsTransactionState ())
635
+ {
636
+ txstarted = true;
637
+ StartTransactionCommand ();
638
+ }
626
639
SPI_connect ();
627
640
PushActiveSnapshot (GetTransactionSnapshot ());
628
641
rc = SPI_execute ("select node_id from mtm.referee_decision where key = 'winner';" , true, 0 );
@@ -644,7 +657,8 @@ MtmRefereeReadSaved(void)
644
657
}
645
658
SPI_finish ();
646
659
PopActiveSnapshot ();
647
- CommitTransactionCommand ();
660
+ if (txstarted )
661
+ CommitTransactionCommand ();
648
662
649
663
MTM_LOG1 ("Read saved referee decision, winner=%d." , winner );
650
664
return winner ;
0 commit comments