From dc370335a9a3b2b0f90a9cb3140d64377d1f6903 Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Wed, 26 Jan 2022 16:57:08 +0100 Subject: [PATCH] Use a fixed application_name while connecting to remote nodes Citus heavily relies on application_name, see `IsCitusInitiatedRemoteBackend()`. But if the user set the application name, such as export PGAPPNAME=test_name, Citus uses that name while connecting to the remote node. With this commit, we ensure that Citus always connects with the "citus" user name to the remote nodes. --- .../connection/connection_configuration.c | 12 ++++++------ src/test/regress/expected/mx_application_name.out | 14 ++++++++++++++ src/test/regress/multi_mx_schedule | 1 + src/test/regress/sql/mx_application_name.sql | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 src/test/regress/expected/mx_application_name.out create mode 100644 src/test/regress/sql/mx_application_name.sql diff --git a/src/backend/distributed/connection/connection_configuration.c b/src/backend/distributed/connection/connection_configuration.c index a0bd31e25..32dc21e40 100644 --- a/src/backend/distributed/connection/connection_configuration.c +++ b/src/backend/distributed/connection/connection_configuration.c @@ -72,8 +72,8 @@ InitConnParams() /* * ResetConnParams frees all strings in the keywords and parameters arrays, * sets their elements to null, and resets the ConnParamsSize to zero before - * adding back any hardcoded global connection settings (at present, only the - * fallback_application_name of 'citus'). + * adding back any hardcoded global connection settings (at present, there + * are no). */ void ResetConnParams() @@ -89,8 +89,6 @@ ResetConnParams() ConnParams.size = 0; InvalidateConnParamsHashEntries(); - - AddConnParam("fallback_application_name", CITUS_APPLICATION_NAME); } @@ -253,14 +251,16 @@ GetConnParams(ConnectionHashKey *key, char ***keywords, char ***values, "port", "dbname", "user", - "client_encoding" + "client_encoding", + "application_name" }; const char *runtimeValues[] = { key->hostname, nodePortString, key->database, key->user, - GetDatabaseEncodingName() + GetDatabaseEncodingName(), + CITUS_APPLICATION_NAME }; /* diff --git a/src/test/regress/expected/mx_application_name.out b/src/test/regress/expected/mx_application_name.out new file mode 100644 index 000000000..f35f29d29 --- /dev/null +++ b/src/test/regress/expected/mx_application_name.out @@ -0,0 +1,14 @@ +CREATE SCHEMA mx_app_name; +CREATE TABLE output (line text); +-- a hack to run command with another application name +\COPY output FROM PROGRAM 'psql postgres://postgres@localhost:xxxxx/regression?application_name=test -c "CREATE TABLE dist_1(a int)"' +\COPY output FROM PROGRAM 'psql postgres://postgres@localhost:xxxxx/regression?application_name=test -c "SELECT create_distributed_table(''dist_1'', ''a'');"' +-- ensure the command executed fine +SELECT count(*) FROM pg_dist_partition WHERE logicalrelid = 'dist_1'::regclass; + count +--------------------------------------------------------------------- + 1 +(1 row) + +\COPY output FROM PROGRAM 'psql postgres://postgres@localhost:xxxxx/regression?application_name=test -c "DROP TABLE dist_1;"' +DROP SCHEMA mx_app_name CASCADE; diff --git a/src/test/regress/multi_mx_schedule b/src/test/regress/multi_mx_schedule index 973c3bf05..5aaf76aa6 100644 --- a/src/test/regress/multi_mx_schedule +++ b/src/test/regress/multi_mx_schedule @@ -59,6 +59,7 @@ test: locally_execute_intermediate_results test: multi_mx_alter_distributed_table test: update_colocation_mx test: resync_metadata_with_sequences +test: mx_application_name # should be executed sequentially because it modifies metadata test: local_shard_execution_dropped_column diff --git a/src/test/regress/sql/mx_application_name.sql b/src/test/regress/sql/mx_application_name.sql new file mode 100644 index 000000000..8e2258774 --- /dev/null +++ b/src/test/regress/sql/mx_application_name.sql @@ -0,0 +1,14 @@ +CREATE SCHEMA mx_app_name; + +CREATE TABLE output (line text); + +-- a hack to run command with another application name +\COPY output FROM PROGRAM 'psql postgres://postgres@localhost:57636/regression?application_name=test -c "CREATE TABLE dist_1(a int)"' +\COPY output FROM PROGRAM 'psql postgres://postgres@localhost:57636/regression?application_name=test -c "SELECT create_distributed_table(''dist_1'', ''a'');"' + +-- ensure the command executed fine +SELECT count(*) FROM pg_dist_partition WHERE logicalrelid = 'dist_1'::regclass; + +\COPY output FROM PROGRAM 'psql postgres://postgres@localhost:57636/regression?application_name=test -c "DROP TABLE dist_1;"' + +DROP SCHEMA mx_app_name CASCADE;