Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADBDEV-5525: Remove per byte precision message truncation for multibyte strings #1185

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/backend/access/external/url_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "cdb/cdbtimer.h"
#include "cdb/cdbvars.h"
#include "libpq/pqsignal.h"
#include "mb/pg_wchar.h"
#include "utils/resowner.h"

#define EXEC_DATA_P 0 /* index to data pipe */
Expand Down Expand Up @@ -484,7 +485,12 @@ interpretError(int rc, char *buf, size_t buflen, char *err, size_t errlen)
/* Exit codes from commands rarely map to strerror() strings. In here
* we show the error string returned from pclose, and omit the non
* friendly exit code interpretation */
snprintf(buf, buflen, "error. %s", err);
int len = snprintf(buf, buflen, "error. %s", err);
mos65o2 marked this conversation as resolved.
Show resolved Hide resolved

if (len >= buflen)
{
buf[pg_mbcliplen(buf, len, buflen - 1)] = '\0';
}
}
}
else if (WIFSIGNALED(rc))
Expand Down
7 changes: 6 additions & 1 deletion src/backend/cdb/cdbthreadlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ write_log(const char *fmt,...)
{
char errbuf[2048]; /* Arbitrary size? */

vsnprintf(errbuf, sizeof(errbuf), fmt, ap);
int len = vsnprintf(errbuf, sizeof(errbuf), fmt, ap);

if (len >= sizeof(errbuf))
{
errbuf[pg_mbcliplen(errbuf, len, sizeof(errbuf) - 1)] = '\0';
}

/* Write the message in the CSV format */
write_message_to_server_log(LOG,
Expand Down
9 changes: 9 additions & 0 deletions src/test/regress/input/external_table.source
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ FETCH FORWARD 1 FROM _psql_cursor;
CLOSE _psql_cursor;
COMMIT;

-- ensure correct truncate error log according to database encoding
CREATE EXTERNAL WEB TABLE table_test (text text) EXECUTE $$ (echo -n ‘ && seq 1 500 | cut -b1 | tr -d '\n' && echo -n ’) >/dev/stderr && false $$ ON ALL FORMAT 'CSV';
SELECT true FROM table_test;
DROP EXTERNAL TABLE IF EXISTS table_test;
CREATE EXTERNAL WEB TABLE table_test (text text) EXECUTE $$ (echo -n ‘ && seq 1 2006 | cut -b1 | tr -d '\n' && echo -n ’) >/dev/stderr && true $$ ON ALL FORMAT 'CSV';
SELECT true FROM table_test;
SELECT logseverity FROM gp_toolkit.gp_log_system WHERE logmessage LIKE 'read err msg from pipe%' AND logdatabase = current_database() LIMIT 1;
DROP EXTERNAL TABLE IF EXISTS table_test;

-- echo will behave differently on different platforms, force to use bash with -E option
CREATE EXTERNAL WEB TABLE table_qry (val TEXT)
EXECUTE E'/usr/bin/env bash -c ''echo -E "$GP_QUERY_STRING"''' ON SEGMENT 0
Expand Down
19 changes: 19 additions & 0 deletions src/test/regress/output/external_table.source
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ FETCH FORWARD 1 FROM _psql_cursor;

CLOSE _psql_cursor;
COMMIT;
-- ensure correct truncate error log according to database encoding
CREATE EXTERNAL WEB TABLE table_test (text text) EXECUTE $$ (echo -n ‘ && seq 1 500 | cut -b1 | tr -d '\n' && echo -n ’) >/dev/stderr && false $$ ON ALL FORMAT 'CSV';
SELECT true FROM table_test;
ERROR: external table table_test command ended with error. ‘12345678911111111112222222222333333333344444444445555555555666666666677777777778888888888999999999911111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333344444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444445 (seg0 slice1 172.19.0.4:6434 pid=107133)
DETAIL: Command: execute: (echo -n ‘ && seq 1 500 | cut -b1 | tr -d '\n' && echo -n ’) >/dev/stderr && false
DROP EXTERNAL TABLE IF EXISTS table_test;
CREATE EXTERNAL WEB TABLE table_test (text text) EXECUTE $$ (echo -n ‘ && seq 1 2006 | cut -b1 | tr -d '\n' && echo -n ’) >/dev/stderr && true $$ ON ALL FORMAT 'CSV';
SELECT true FROM table_test;
bool
------
(0 rows)

SELECT logseverity FROM gp_toolkit.gp_log_system WHERE logmessage LIKE 'read err msg from pipe%' AND logdatabase = current_database() LIMIT 1;
logseverity
-------------
LOG
(1 row)

DROP EXTERNAL TABLE IF EXISTS table_test;
-- echo will behave differently on different platforms, force to use bash with -E option
CREATE EXTERNAL WEB TABLE table_qry (val TEXT)
EXECUTE E'/usr/bin/env bash -c ''echo -E "$GP_QUERY_STRING"''' ON SEGMENT 0
Expand Down
19 changes: 19 additions & 0 deletions src/test/regress/output/external_table_optimizer.source
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ FETCH FORWARD 1 FROM _psql_cursor;

CLOSE _psql_cursor;
COMMIT;
-- ensure correct truncate error log according to database encoding
CREATE EXTERNAL WEB TABLE table_test (text text) EXECUTE $$ (echo -n ‘ && seq 1 500 | cut -b1 | tr -d '\n' && echo -n ’) >/dev/stderr && false $$ ON ALL FORMAT 'CSV';
SELECT true FROM table_test;
ERROR: external table table_test command ended with error. ‘12345678911111111112222222222333333333344444444445555555555666666666677777777778888888888999999999911111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333344444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444445 (seg0 slice1 172.19.0.4:6434 pid=107133)
DETAIL: Command: execute: (echo -n ‘ && seq 1 500 | cut -b1 | tr -d '\n' && echo -n ’) >/dev/stderr && false
DROP EXTERNAL TABLE IF EXISTS table_test;
CREATE EXTERNAL WEB TABLE table_test (text text) EXECUTE $$ (echo -n ‘ && seq 1 2006 | cut -b1 | tr -d '\n' && echo -n ’) >/dev/stderr && true $$ ON ALL FORMAT 'CSV';
SELECT true FROM table_test;
bool
------
(0 rows)

SELECT logseverity FROM gp_toolkit.gp_log_system WHERE logmessage LIKE 'read err msg from pipe%' AND logdatabase = current_database() LIMIT 1;
logseverity
-------------
LOG
(1 row)

DROP EXTERNAL TABLE IF EXISTS table_test;
-- echo will behave differently on different platforms, force to use bash with -E option
CREATE EXTERNAL WEB TABLE table_qry (val TEXT)
EXECUTE E'/usr/bin/env bash -c ''echo -E "$GP_QUERY_STRING"''' ON SEGMENT 0
Expand Down