summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/pgxc/pool/execRemote.c121
-rw-r--r--src/test/regress/expected/domain_1.out4
-rw-r--r--src/test/regress/output/constraints_1.source2
3 files changed, 42 insertions, 85 deletions
diff --git a/src/backend/pgxc/pool/execRemote.c b/src/backend/pgxc/pool/execRemote.c
index 36b6b37204..67fa618f05 100644
--- a/src/backend/pgxc/pool/execRemote.c
+++ b/src/backend/pgxc/pool/execRemote.c
@@ -153,6 +153,7 @@ static char *pgxc_node_get_nodelist(bool localNode);
static void ExecClearTempObjectIncluded(void);
static void init_RemoteXactState(bool preparedLocalNode);
static void clear_RemoteXactState(void);
+static void pgxc_node_report_error(RemoteQueryState *combiner);
#define MAX_STATEMENTS_PER_TRAN 10
@@ -1187,6 +1188,7 @@ pgxc_node_receive_responses(const int conn_count, PGXCNodeHandle ** connections,
}
}
}
+ pgxc_node_report_error(combiner);
return 0;
}
@@ -1672,18 +1674,8 @@ pgxc_node_remote_prepare(char *prepareGID)
if (result)
{
remoteXactState.status = RXACT_PREPARE_FAILED;
- if (combiner && combiner->errorMessage)
- {
- char *code = combiner->errorCode;
- if (combiner->errorDetail != NULL)
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", combiner->errorMessage), errdetail("%s", combiner->errorDetail) ));
- else
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", combiner->errorMessage)));
- }
+ if (combiner)
+ pgxc_node_report_error(combiner);
else
elog(ERROR, "failed to PREPARE transaction on one or more nodes");
}
@@ -1904,18 +1896,8 @@ pgxc_node_remote_commit(void)
if (result)
{
- if (combiner && combiner->errorMessage)
- {
- char *code = combiner->errorCode;
- if (combiner->errorDetail != NULL)
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", combiner->errorMessage), errdetail("%s", combiner->errorDetail) ));
- else
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", combiner->errorMessage)));
- }
+ if (combiner)
+ pgxc_node_report_error(combiner);
else
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
@@ -2045,13 +2027,8 @@ pgxc_node_remote_abort(void)
if (result)
{
- if (combiner && combiner->errorMessage)
- {
- if (combiner->errorDetail != NULL)
- elog(LOG, "%s %s", combiner->errorMessage, combiner->errorDetail);
- else
- elog(LOG, "%s", combiner->errorMessage);
- }
+ if (combiner)
+ pgxc_node_report_error(combiner);
else
elog(LOG, "Failed to ABORT an implicitly PREPARED "
"transaction - result %d", result);
@@ -2963,18 +2940,8 @@ do_query(RemoteQueryState *node)
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("Unexpected response from data node")));
}
- if (node->errorMessage)
- {
- char *code = node->errorCode;
- if (node->errorDetail != NULL)
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", node->errorMessage), errdetail("%s", node->errorDetail) ));
- else
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", node->errorMessage)));
- }
+ /* report error if any */
+ pgxc_node_report_error(node);
}
for (i = 0; i < regular_conn_count; i++)
@@ -3102,19 +3069,8 @@ do_query(RemoteQueryState *node)
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("Unexpected response from data node")));
}
-
- if (node->errorMessage)
- {
- char *code = node->errorCode;
- if (node->errorDetail != NULL)
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", node->errorMessage), errdetail("%s", node->errorDetail) ));
- else
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", node->errorMessage)));
- }
+ /* report error if any */
+ pgxc_node_report_error(node);
}
if (node->cursor_count)
@@ -3400,20 +3356,8 @@ RemoteQueryNext(RemoteQueryState *node)
else
ExecClearTuple(resultslot);
}
-
- if (node->errorMessage)
- {
- char *code = node->errorCode;
- if (node->errorDetail != NULL)
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", node->errorMessage), errdetail("%s", node->errorDetail) ));
- else
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", node->errorMessage)));
- }
-
+ /* report error if any */
+ pgxc_node_report_error(node);
/*
* While we are emitting rows we ignore outer plan
*/
@@ -3953,18 +3897,7 @@ ExecRemoteUtility(RemoteQuery *node)
* error message pending we can report it. All connections should be in
* consistent state now and so they can be released to the pool after ROLLBACK.
*/
- if (remotestate->errorMessage)
- {
- char *code = remotestate->errorCode;
- if (remotestate->errorDetail != NULL)
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", remotestate->errorMessage), errdetail("%s", remotestate->errorDetail) ));
- else
- ereport(ERROR,
- (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
- errmsg("%s", remotestate->errorMessage)));
- }
+ pgxc_node_report_error(remotestate);
}
@@ -4723,3 +4656,27 @@ FinishRemotePreparedTransaction(char *prepareGID, bool commit)
return prepared_local;
}
+
+/*
+ * pgxc_node_report_error
+ * Throw error from datanode if any.
+ */
+static void
+pgxc_node_report_error(RemoteQueryState *combiner)
+{
+ /* If no combiner, nothing to do */
+ if (!combiner)
+ return;
+ if (combiner->errorMessage)
+ {
+ char *code = combiner->errorCode;
+ if (combiner->errorDetail != NULL)
+ ereport(ERROR,
+ (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
+ errmsg("%s", combiner->errorMessage), errdetail("%s", combiner->errorDetail) ));
+ else
+ ereport(ERROR,
+ (errcode(MAKE_SQLSTATE(code[0], code[1], code[2], code[3], code[4])),
+ errmsg("%s", combiner->errorMessage)));
+ }
+}
diff --git a/src/test/regress/expected/domain_1.out b/src/test/regress/expected/domain_1.out
index 3bb96e2d01..46af275e06 100644
--- a/src/test/regress/expected/domain_1.out
+++ b/src/test/regress/expected/domain_1.out
@@ -208,13 +208,13 @@ ERROR: null value in column "col3" violates not-null constraint
INSERT INTO nulltest values ('a', 'b', 'c', NULL, 'd'); -- Good
-- Test copy
COPY nulltest FROM stdin; --fail
-ERROR: Error while running COPY
+ERROR: null value in column "col3" violates not-null constraint
COPY nulltest FROM stdin; --fail
ERROR: domain dcheck does not allow null values
CONTEXT: COPY nulltest, line 1, column col5: null input
-- Last row is bad
COPY nulltest FROM stdin;
-ERROR: Error while running COPY
+ERROR: new row for relation "nulltest" violates check constraint "nulltest_col5_check"
select * from nulltest order by 1, 2, 3, 4, 5;
col1 | col2 | col3 | col4 | col5
------+------+------+------+------
diff --git a/src/test/regress/output/constraints_1.source b/src/test/regress/output/constraints_1.source
index 966d447193..1b45784814 100644
--- a/src/test/regress/output/constraints_1.source
+++ b/src/test/regress/output/constraints_1.source
@@ -278,7 +278,7 @@ SELECT '' AS two, * FROM COPY_TBL order by x,y,z;
(2 rows)
COPY COPY_TBL FROM '@abs_srcdir@/data/constrf.data';
-ERROR: Error while running COPY
+ERROR: new row for relation "copy_tbl" violates check constraint "copy_con"
SELECT * FROM COPY_TBL order by x,y,z;
x | y | z
---+---------------+---