From c2536f7547c2c16707dbf2133dcb9cb90a72f43d Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Fri, 8 Jun 2018 21:08:36 +0200 Subject: [PATCH] Always throw errors on failure on critical connection in router executor --- .../executor/multi_router_executor.c | 23 ++++++++++++++----- .../transaction/remote_transaction.c | 13 +++++++++++ src/include/distributed/remote_transaction.h | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/backend/distributed/executor/multi_router_executor.c b/src/backend/distributed/executor/multi_router_executor.c index 53a0083e2..9f19570cc 100644 --- a/src/backend/distributed/executor/multi_router_executor.c +++ b/src/backend/distributed/executor/multi_router_executor.c @@ -1297,18 +1297,18 @@ SendQueryInSingleRowMode(MultiConnection *connection, char *query, if (querySent == 0) { - const bool raiseErrors = false; + const bool raiseIfTransactionIsCritical = true; - HandleRemoteTransactionConnectionError(connection, raiseErrors); + HandleRemoteTransactionConnectionError(connection, raiseIfTransactionIsCritical); return false; } singleRowMode = PQsetSingleRowMode(connection->pgConn); if (singleRowMode == 0) { - const bool raiseErrors = false; + const bool raiseIfTransactionIsCritical = true; - HandleRemoteTransactionConnectionError(connection, raiseErrors); + HandleRemoteTransactionConnectionError(connection, raiseIfTransactionIsCritical); return false; } @@ -1450,6 +1450,10 @@ StoreQueryResult(CitusScanState *scanState, MultiConnection *connection, int category = 0; bool isConstraintViolation = false; + /* + * Mark transaction as failed, but don't throw an error. This allows us + * to give a more meaningful error message below. + */ MarkRemoteTransactionFailed(connection, false); /* @@ -1460,7 +1464,8 @@ StoreQueryResult(CitusScanState *scanState, MultiConnection *connection, category = ERRCODE_TO_CATEGORY(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION); isConstraintViolation = SqlStateMatchesCategory(sqlStateString, category); - if (isConstraintViolation || failOnError) + if (isConstraintViolation || failOnError || + IsRemoteTransactionCritical(connection)) { ReportResultError(connection, result, ERROR); } @@ -1575,6 +1580,11 @@ ConsumeQueryResult(MultiConnection *connection, bool failOnError, int64 *rows) int category = 0; bool isConstraintViolation = false; + /* + * Mark transaction as failed, but don't throw an error even if the + * transaction is critical. This allows us to give a more meaningful + * error message below. + */ MarkRemoteTransactionFailed(connection, false); /* @@ -1585,7 +1595,8 @@ ConsumeQueryResult(MultiConnection *connection, bool failOnError, int64 *rows) category = ERRCODE_TO_CATEGORY(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION); isConstraintViolation = SqlStateMatchesCategory(sqlStateString, category); - if (isConstraintViolation || failOnError) + if (isConstraintViolation || failOnError || + IsRemoteTransactionCritical(connection)) { ReportResultError(connection, result, ERROR); } diff --git a/src/backend/distributed/transaction/remote_transaction.c b/src/backend/distributed/transaction/remote_transaction.c index 044876547..81d874044 100644 --- a/src/backend/distributed/transaction/remote_transaction.c +++ b/src/backend/distributed/transaction/remote_transaction.c @@ -721,6 +721,19 @@ MarkRemoteTransactionCritical(struct MultiConnection *connection) } +/* + * IsRemoteTransactionCritical returns whether the remote transaction on + * the given connection has been marked as critical. + */ +bool +IsRemoteTransactionCritical(struct MultiConnection *connection) +{ + RemoteTransaction *transaction = &connection->remoteTransaction; + + return transaction->transactionCritical; +} + + /* * CloseRemoteTransaction handles closing a connection that, potentially, is * part of a coordinated transaction. This should only ever be called from diff --git a/src/include/distributed/remote_transaction.h b/src/include/distributed/remote_transaction.h index 89eb822ab..b224fe483 100644 --- a/src/include/distributed/remote_transaction.h +++ b/src/include/distributed/remote_transaction.h @@ -115,6 +115,7 @@ extern void HandleRemoteTransactionResultError(struct MultiConnection *connectio extern void MarkRemoteTransactionFailed(struct MultiConnection *connection, bool allowErrorPromotion); extern void MarkRemoteTransactionCritical(struct MultiConnection *connection); +extern bool IsRemoteTransactionCritical(struct MultiConnection *connection); /*