Update ereport format

pull/552/head
Metin Doslu 2016-06-07 14:22:10 +03:00
parent 8bac89b663
commit 15eed396b3
6 changed files with 42 additions and 31 deletions

View File

@ -198,34 +198,31 @@ void
ReportRemoteError(PGconn *connection, PGresult *result)
{
char *sqlStateString = PQresultErrorField(result, PG_DIAG_SQLSTATE);
char *remoteMessage = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
char *messagePrimary = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
char *messageDetail = PQresultErrorField(result, PG_DIAG_MESSAGE_DETAIL);
char *messageHint = PQresultErrorField(result, PG_DIAG_MESSAGE_HINT);
char *messageContext = PQresultErrorField(result, PG_DIAG_CONTEXT);
char *nodeName = ConnectionGetOptionValue(connection, "host");
char *nodePort = ConnectionGetOptionValue(connection, "port");
char *errorPrefix = "Connection failed to";
int sqlState = ERRCODE_CONNECTION_FAILURE;
if (sqlStateString != NULL)
{
sqlState = MAKE_SQLSTATE(sqlStateString[0], sqlStateString[1], sqlStateString[2],
sqlStateString[3], sqlStateString[4]);
/* use more specific error prefix for result failures */
if (sqlState != ERRCODE_CONNECTION_FAILURE)
{
errorPrefix = "Bad result from";
}
}
/*
* If the PGresult did not contain a message, the connection may provide a
* suitable top level one. At worst, this is an empty string.
*/
if (remoteMessage == NULL)
if (messagePrimary == NULL)
{
char *lastNewlineIndex = NULL;
remoteMessage = PQerrorMessage(connection);
lastNewlineIndex = strrchr(remoteMessage, '\n');
messagePrimary = PQerrorMessage(connection);
lastNewlineIndex = strrchr(messagePrimary, '\n');
/* trim trailing newline, if any */
if (lastNewlineIndex != NULL)
@ -234,9 +231,21 @@ ReportRemoteError(PGconn *connection, PGresult *result)
}
}
ereport(WARNING, (errcode(sqlState),
errmsg("%s %s:%s", errorPrefix, nodeName, nodePort),
errdetail("Remote message: %s", remoteMessage)));
if (sqlState == ERRCODE_CONNECTION_FAILURE)
{
ereport(WARNING, (errcode(sqlState),
errmsg("connection failed to %s:%s", nodeName, nodePort),
errdetail("%s", messagePrimary)));
}
else
{
ereport(WARNING, (errcode(sqlState), errmsg("%s", messagePrimary),
messageDetail ? errdetail("%s", messageDetail) : 0,
messageHint ? errhint("%s", messageHint) : 0,
messageContext ? errcontext("%s", messageContext) : 0,
errcontext("Error occurred on remote connection to %s:%s.",
nodeName, nodePort)));
}
}

View File

@ -28,7 +28,7 @@ CREATE FUNCTION set_connection_status_bad(cstring, integer)
\set VERBOSITY terse
-- connect to non-existent host
SELECT initialize_remote_temp_table('dummy-host-name', 12345);
WARNING: Connection failed to dummy-host-name:12345
WARNING: connection failed to dummy-host-name:12345
initialize_remote_temp_table
------------------------------
f

View File

@ -139,12 +139,13 @@ ERROR: creating unique indexes on append-partitioned tables is currently unsupp
CREATE INDEX lineitem_orderkey_index ON lineitem (l_orderkey);
ERROR: relation "lineitem_orderkey_index" already exists
CREATE INDEX try_index ON lineitem USING gist (l_orderkey);
WARNING: Bad result from localhost:57638
DETAIL: Remote message: data type bigint has no default operator class for access method "gist"
WARNING: data type bigint has no default operator class for access method "gist"
HINT: You must specify an operator class for the index or define a default operator class for the data type.
CONTEXT: Error occurred on remote connection to localhost:57638.
ERROR: could not execute DDL command on worker node shards
CREATE INDEX try_index ON lineitem (non_existent_column);
WARNING: Bad result from localhost:57638
DETAIL: Remote message: column "non_existent_column" does not exist
WARNING: column "non_existent_column" does not exist
CONTEXT: Error occurred on remote connection to localhost:57638.
ERROR: could not execute DDL command on worker node shards
CREATE INDEX ON lineitem (l_orderkey);
ERROR: creating index without a name on a distributed table is currently unsupported

View File

@ -276,8 +276,9 @@ WHERE nodename = 'localhost' AND
nodeport = :worker_1_port;
-- Fourth: Perform the same INSERT (primary key violation)
INSERT INTO limit_orders VALUES (275, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
WARNING: Bad result from localhost:57638
DETAIL: Remote message: duplicate key value violates unique constraint "limit_orders_pkey_750001"
WARNING: duplicate key value violates unique constraint "limit_orders_pkey_750001"
DETAIL: Key (id)=(275) already exists.
CONTEXT: Error occurred on remote connection to localhost:57638.
-- Last: Verify the insert worked but the placement with the PK violation is now unhealthy
SELECT count(*) FROM limit_orders WHERE id = 275;
count

View File

@ -261,8 +261,8 @@ ALTER TABLE IF EXISTS non_existent_table ADD COLUMN new_column INTEGER;
NOTICE: relation "non_existent_table" does not exist, skipping
ALTER TABLE IF EXISTS lineitem_alter ALTER COLUMN int_column2 SET DATA TYPE INTEGER;
ALTER TABLE lineitem_alter DROP COLUMN non_existent_column;
WARNING: Bad result from localhost:57638
DETAIL: Remote message: column "non_existent_column" of relation "lineitem_alter_220000" does not exist
WARNING: column "non_existent_column" of relation "lineitem_alter_220000" does not exist
CONTEXT: Error occurred on remote connection to localhost:57638.
ERROR: could not execute DDL command on worker node shards
ALTER TABLE lineitem_alter DROP COLUMN IF EXISTS non_existent_column;
NOTICE: column "non_existent_column" of relation "lineitem_alter" does not exist, skipping
@ -361,16 +361,16 @@ DETAIL: Only ADD|DROP COLUMN, SET|DROP NOT NULL, SET|DROP DEFAULT and TYPE subc
-- Verify that we error out in case of postgres errors on supported statement
-- types
ALTER TABLE lineitem_alter ADD COLUMN new_column non_existent_type;
WARNING: Bad result from localhost:57638
DETAIL: Remote message: type "non_existent_type" does not exist
WARNING: type "non_existent_type" does not exist
CONTEXT: Error occurred on remote connection to localhost:57638.
ERROR: could not execute DDL command on worker node shards
ALTER TABLE lineitem_alter ALTER COLUMN null_column SET NOT NULL;
WARNING: Bad result from localhost:57638
DETAIL: Remote message: column "null_column" contains null values
WARNING: column "null_column" contains null values
CONTEXT: Error occurred on remote connection to localhost:57638.
ERROR: could not execute DDL command on worker node shards
ALTER TABLE lineitem_alter ALTER COLUMN l_partkey SET DEFAULT 'a';
WARNING: Bad result from localhost:57638
DETAIL: Remote message: invalid input syntax for integer: "a"
WARNING: invalid input syntax for integer: "a"
CONTEXT: Error occurred on remote connection to localhost:57638.
ERROR: could not execute DDL command on worker node shards
-- Verify that we error out on statements involving RENAME
ALTER TABLE lineitem_alter RENAME TO lineitem_renamed;

View File

@ -455,8 +455,8 @@ COPY customer_worker_copy_append FROM '@abs_srcdir@/data/customer.1.data' with (
COPY customer_worker_copy_append FROM '@abs_srcdir@/data/customer.2.data' with (delimiter '|', master_host 'localhost', master_port 57636);
-- Test if there is no relation to copy data with the worker copy
COPY lineitem_copy_none FROM '@abs_srcdir@/data/lineitem.1.data' with (delimiter '|', master_host 'localhost', master_port 57636);
WARNING: Bad result from localhost:57636
DETAIL: Remote message: relation "lineitem_copy_none" does not exist
WARNING: relation "lineitem_copy_none" does not exist
CONTEXT: Error occurred on remote connection to localhost:57636.
ERROR: could not run copy from the worker node
-- Connect back to the master node
\c - - - 57636