Always throw errors on failure on critical connection in router executor

release-7.4
Marco Slot 2018-06-08 21:08:36 +02:00 committed by velioglu
parent 05597a9d5c
commit c2536f7547
3 changed files with 31 additions and 6 deletions

View File

@ -1297,18 +1297,18 @@ SendQueryInSingleRowMode(MultiConnection *connection, char *query,
if (querySent == 0) if (querySent == 0)
{ {
const bool raiseErrors = false; const bool raiseIfTransactionIsCritical = true;
HandleRemoteTransactionConnectionError(connection, raiseErrors); HandleRemoteTransactionConnectionError(connection, raiseIfTransactionIsCritical);
return false; return false;
} }
singleRowMode = PQsetSingleRowMode(connection->pgConn); singleRowMode = PQsetSingleRowMode(connection->pgConn);
if (singleRowMode == 0) if (singleRowMode == 0)
{ {
const bool raiseErrors = false; const bool raiseIfTransactionIsCritical = true;
HandleRemoteTransactionConnectionError(connection, raiseErrors); HandleRemoteTransactionConnectionError(connection, raiseIfTransactionIsCritical);
return false; return false;
} }
@ -1450,6 +1450,10 @@ StoreQueryResult(CitusScanState *scanState, MultiConnection *connection,
int category = 0; int category = 0;
bool isConstraintViolation = false; 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); MarkRemoteTransactionFailed(connection, false);
/* /*
@ -1460,7 +1464,8 @@ StoreQueryResult(CitusScanState *scanState, MultiConnection *connection,
category = ERRCODE_TO_CATEGORY(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION); category = ERRCODE_TO_CATEGORY(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION);
isConstraintViolation = SqlStateMatchesCategory(sqlStateString, category); isConstraintViolation = SqlStateMatchesCategory(sqlStateString, category);
if (isConstraintViolation || failOnError) if (isConstraintViolation || failOnError ||
IsRemoteTransactionCritical(connection))
{ {
ReportResultError(connection, result, ERROR); ReportResultError(connection, result, ERROR);
} }
@ -1575,6 +1580,11 @@ ConsumeQueryResult(MultiConnection *connection, bool failOnError, int64 *rows)
int category = 0; int category = 0;
bool isConstraintViolation = false; 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); MarkRemoteTransactionFailed(connection, false);
/* /*
@ -1585,7 +1595,8 @@ ConsumeQueryResult(MultiConnection *connection, bool failOnError, int64 *rows)
category = ERRCODE_TO_CATEGORY(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION); category = ERRCODE_TO_CATEGORY(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION);
isConstraintViolation = SqlStateMatchesCategory(sqlStateString, category); isConstraintViolation = SqlStateMatchesCategory(sqlStateString, category);
if (isConstraintViolation || failOnError) if (isConstraintViolation || failOnError ||
IsRemoteTransactionCritical(connection))
{ {
ReportResultError(connection, result, ERROR); ReportResultError(connection, result, ERROR);
} }

View File

@ -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 * CloseRemoteTransaction handles closing a connection that, potentially, is
* part of a coordinated transaction. This should only ever be called from * part of a coordinated transaction. This should only ever be called from

View File

@ -115,6 +115,7 @@ extern void HandleRemoteTransactionResultError(struct MultiConnection *connectio
extern void MarkRemoteTransactionFailed(struct MultiConnection *connection, extern void MarkRemoteTransactionFailed(struct MultiConnection *connection,
bool allowErrorPromotion); bool allowErrorPromotion);
extern void MarkRemoteTransactionCritical(struct MultiConnection *connection); extern void MarkRemoteTransactionCritical(struct MultiConnection *connection);
extern bool IsRemoteTransactionCritical(struct MultiConnection *connection);
/* /*