Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ed275f9

Browse files
committed
properly handle transaction state in MtmRefereeHasLocalTable/MtmRefereeReadSaved
1 parent 5dfe54e commit ed275f9

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

state.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,23 @@ MtmRefereeHasLocalTable()
592592
RangeVar *rv;
593593
Oid rel_oid;
594594
static bool _has_local_tables;
595+
bool txstarted = false;
595596

596597
/* memoized */
597598
if (_has_local_tables)
598599
return true;
599600

600-
StartTransactionCommand();
601+
if (!IsTransactionState())
602+
{
603+
txstarted = true;
604+
StartTransactionCommand();
605+
}
606+
601607
rv = makeRangeVar(MULTIMASTER_SCHEMA_NAME, "referee_decision", -1);
602608
rel_oid = RangeVarGetRelid(rv, NoLock, true);
603-
CommitTransactionCommand();
609+
610+
if (txstarted)
611+
CommitTransactionCommand();
604612

605613
if (OidIsValid(rel_oid))
606614
{
@@ -617,12 +625,17 @@ MtmRefereeReadSaved(void)
617625
{
618626
int winner = -1;
619627
int rc;
628+
bool txstarted = false;
620629

621630
if (!MtmRefereeHasLocalTable())
622631
return -1;
623632

624633
/* Save result locally */
625-
StartTransactionCommand();
634+
if (!IsTransactionState())
635+
{
636+
txstarted = true;
637+
StartTransactionCommand();
638+
}
626639
SPI_connect();
627640
PushActiveSnapshot(GetTransactionSnapshot());
628641
rc = SPI_execute("select node_id from mtm.referee_decision where key = 'winner';", true, 0);
@@ -644,7 +657,8 @@ MtmRefereeReadSaved(void)
644657
}
645658
SPI_finish();
646659
PopActiveSnapshot();
647-
CommitTransactionCommand();
660+
if (txstarted)
661+
CommitTransactionCommand();
648662

649663
MTM_LOG1("Read saved referee decision, winner=%d.", winner);
650664
return winner;

0 commit comments

Comments
 (0)