Fix hard crash when aborting transaction

If something is wrong with a connection we would not be able to
start a transaction on the remote node. So when abort happens we
shoud not try to abort a transaction that hasn't started.
We use xact_depth to check if transaction actually started.
If we find one we remove it from our tx cache which should result in removing
the invalid connection as well.
This commit is contained in:
niksa 2019-09-20 14:33:54 +02:00 committed by Erik Nordström
parent 27f3effcb1
commit b01cc6ef1b
3 changed files with 12 additions and 2 deletions

View File

@ -194,9 +194,10 @@ dist_txn_xact_callback_abort()
testing_callback_call("pre-abort");
remote_txn_store_foreach(state.store, remote_txn)
{
if (!remote_txn_abort(remote_txn))
if (!remote_txn_is_ongoing(remote_txn) || !remote_txn_abort(remote_txn))
{
elog(WARNING, "failure aborting remote transaction during local abort");
if (remote_txn_is_ongoing(remote_txn))
elog(WARNING, "failure aborting remote transaction during local abort");
remote_txn_store_remove(state.store, remote_txn_get_connection_id(remote_txn));
}
}

View File

@ -358,6 +358,14 @@ remote_txn_abort(RemoteTxn *entry)
return true;
}
/* Check if there is ongoing transaction on the remote node */
bool
remote_txn_is_ongoing(RemoteTxn *entry)
{
Assert(entry->xact_depth >= 0);
return entry->xact_depth != 0;
}
/*
* If there were any errors in subtransactions, and we made prepared
* statements, those prepared statements may not have been cleared

View File

@ -37,6 +37,7 @@ extern TSConnectionId remote_txn_get_connection_id(RemoteTxn *txn);
extern bool remote_txn_is_still_in_progress(TransactionId frontend_xid);
extern size_t remote_txn_size(void);
extern bool remote_txn_is_at_sub_txn_level(RemoteTxn *entry, int curlevel);
extern bool remote_txn_is_ongoing(RemoteTxn *entry);
/* Messages/communication */
extern AsyncRequest *remote_txn_async_send_commit(RemoteTxn *entry);