From ce25db4e0cda2b87c25ca44fd29807380f61dafb Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Tue, 13 Jun 2017 08:02:33 -0700 Subject: [PATCH 1/4] HAWQ-1373 - Added feature to reload GUC values using hawq reload-config deprecating hawq stop -u --- tools/bin/hawq | 13 +++++++++++++ tools/bin/hawqpylib/HAWQ_HELP.py | 22 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/bin/hawq b/tools/bin/hawq index 5d7571a507..4611cc3bdf 100755 --- a/tools/bin/hawq +++ b/tools/bin/hawq @@ -120,6 +120,19 @@ def main(): if second_arg not in cluster_type_list: print STOP_HELP sys.exit(1) + # Redirects users to use reload-config when using old syntax "hawq stop -u" to reload GUC + if "-u" in sub_args or "--reload" in sub_args or "u" in sub_args.split("-")[1]: + print "To reload GUC values without restarting hawq cluster use 'hawq reload-config '" + sys.exit(1) + cmd = "%s; hawq_ctl %s %s" % (source_hawq_env, hawq_command, sub_args) + result = local_run(cmd) + elif hawq_command == "reload-config": + hawq_command="stop" + sub_args_list.append("-u") + sub_args=" ".join(sub_args_list) + if second_arg not in cluster_type_list: + print RELOAD_CONFIG_HELP + sys.exit(1) cmd = "%s; hawq_ctl %s %s" % (source_hawq_env, hawq_command, sub_args) result = local_run(cmd) elif hawq_command == "init": diff --git a/tools/bin/hawqpylib/HAWQ_HELP.py b/tools/bin/hawqpylib/HAWQ_HELP.py index f506f38784..fef5c8f6a2 100755 --- a/tools/bin/hawqpylib/HAWQ_HELP.py +++ b/tools/bin/hawqpylib/HAWQ_HELP.py @@ -38,6 +38,7 @@ check Verifies and validates HAWQ settings. checkperf Verifies the baseline hardware performance of hosts. register Register parquet files generated by other system into the corrsponding table in HAWQ + reload-config Reload GUC values without restarting hawq cluster. See 'hawq help' for more information on a specific command. """ @@ -81,7 +82,6 @@ -v --verbose Displays detailed status, progress and error messages output by the utility. -t --timeout Sets timeout value in seconds, default is 600 seconds. -M --mode Stop with mode [smart|fast|immediate] - -u --reload Reload GUC values without restarting hawq cluster. See 'hawq --help' for more information on other commands. """ @@ -180,3 +180,23 @@ See 'hawq --help' for more information on other commands. """ +RELOAD_CONFIG_HELP = """ +usage: hawq reload-config [--options] + +The "objects" are: + cluster Reload GUC values for hawq cluster. + master Reload GUC values for hawq master. + segment Reload GUC values for local segment node. + standby Reload GUC values for hawq standby. + allsegments Reload GUC values for all segments. + +The "options" are: + -a --prompt Do not ask before execution. + -l --logdir Sets log dir of management tools. + -q --quiet Run in quiet mode. + -v --verbose Displays detailed status, progress and error messages output by the utility. + -t --timeout Sets timeout value in seconds, default is 600 seconds. + -M --mode Stop with mode [smart|fast|immediate] + +See 'hawq --help' for more information on other commands. +""" From bf79fab6066ed655f23eba3030928eefd75437a4 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Mon, 3 Jul 2017 08:59:13 -0700 Subject: [PATCH 2/4] HAWQ-1373 - Incorporated changes suggested in pull request review --- .../ManagementTool/test_hawq_reload.cpp | 52 +++++++++++++++++++ .../feature/ManagementTool/test_hawq_reload.h | 45 ++++++++++++++++ tools/bin/hawq | 11 ++-- tools/bin/hawqpylib/HAWQ_HELP.py | 6 +-- 4 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 src/test/feature/ManagementTool/test_hawq_reload.cpp create mode 100644 src/test/feature/ManagementTool/test_hawq_reload.h diff --git a/src/test/feature/ManagementTool/test_hawq_reload.cpp b/src/test/feature/ManagementTool/test_hawq_reload.cpp new file mode 100644 index 0000000000..5387d9e77d --- /dev/null +++ b/src/test/feature/ManagementTool/test_hawq_reload.cpp @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "lib/command.h" +#include "lib/sql_util.h" +#include "lib/string_util.h" +#include "lib/hawq_config.h" +#include "test_hawq_reload.h" + +#include "gtest/gtest.h" + +using std::string; +using hawq::test::SQLUtility; +using hawq::test::Command; + +/* +Test case for hawq reload . This test changes the value of GUC +log_min_messages to debug. Reloads the cluster and verifies if the change +was reloaded successfully. After the test it resets the valueof GUC to +default. +*/ +TEST_F(TestHawqReload,TestReloadLogMinMessages) { + + hawq::test::HawqConfig hawq_config; + string defaultGUCValue = hawq_config.getGucValue("log_min_messages"); + hawq_config.setGucValue("log_min_messages","debug"); + string cmd = "hawq reload cluster -au"; + Command reload(cmd); + string result = reload.run().getResultOutput(); + EXPECT_EQ("debug", hawq_config.getGucValue("log_min_messages")); + // Reset to default + hawq_config.setGucValue("log_min_messages",defaultGUCValue); + Command setoriginal(cmd); + string org_result = setoriginal.run().getResultOutput(); +} diff --git a/src/test/feature/ManagementTool/test_hawq_reload.h b/src/test/feature/ManagementTool/test_hawq_reload.h new file mode 100644 index 0000000000..64e8370ee2 --- /dev/null +++ b/src/test/feature/ManagementTool/test_hawq_reload.h @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_HAWQ_RELOAD_H +#define TEST_HAWQ_RELOAD_H + +#include +#include +#include +#include "lib/hdfs_config.h" +#include "gtest/gtest.h" + +class TestHawqReload: public ::testing::Test { + public: + TestHawqReload() { + std::string user = HAWQ_USER; + if(user.empty()) { + struct passwd *pw; + uid_t uid = geteuid(); + pw = getpwuid(uid); + user.assign(pw->pw_name); + } + conn.reset(new hawq::test::PSQL(HAWQ_DB, HAWQ_HOST, HAWQ_PORT, user, HAWQ_PASSWORD)); + } + ~TestHawqReload() {} + + private: + std::unique_ptr conn; +}; +#endif diff --git a/tools/bin/hawq b/tools/bin/hawq index 4611cc3bdf..3fd914fd34 100755 --- a/tools/bin/hawq +++ b/tools/bin/hawq @@ -120,13 +120,16 @@ def main(): if second_arg not in cluster_type_list: print STOP_HELP sys.exit(1) - # Redirects users to use reload-config when using old syntax "hawq stop -u" to reload GUC + # Prints deprecation warning when using old syntax "hawq stop -u" to reload GUC if "-u" in sub_args or "--reload" in sub_args or "u" in sub_args.split("-")[1]: - print "To reload GUC values without restarting hawq cluster use 'hawq reload-config '" - sys.exit(1) + deprecationMessage = """ + hawq stop -u is being deprecated and replaced by 'hawq reload ' + Current syntax will work but please use 'hawq reload ' going forward. + """ + print deprecationMessage cmd = "%s; hawq_ctl %s %s" % (source_hawq_env, hawq_command, sub_args) result = local_run(cmd) - elif hawq_command == "reload-config": + elif hawq_command == "reload": hawq_command="stop" sub_args_list.append("-u") sub_args=" ".join(sub_args_list) diff --git a/tools/bin/hawqpylib/HAWQ_HELP.py b/tools/bin/hawqpylib/HAWQ_HELP.py index fef5c8f6a2..b5446299bd 100755 --- a/tools/bin/hawqpylib/HAWQ_HELP.py +++ b/tools/bin/hawqpylib/HAWQ_HELP.py @@ -38,7 +38,7 @@ check Verifies and validates HAWQ settings. checkperf Verifies the baseline hardware performance of hosts. register Register parquet files generated by other system into the corrsponding table in HAWQ - reload-config Reload GUC values without restarting hawq cluster. + reload Reload GUC values without restarting hawq cluster. See 'hawq help' for more information on a specific command. """ @@ -82,7 +82,7 @@ -v --verbose Displays detailed status, progress and error messages output by the utility. -t --timeout Sets timeout value in seconds, default is 600 seconds. -M --mode Stop with mode [smart|fast|immediate] - + -u --reload Reload GUC values without restarting hawq cluster. See 'hawq --help' for more information on other commands. """ @@ -181,7 +181,7 @@ See 'hawq --help' for more information on other commands. """ RELOAD_CONFIG_HELP = """ -usage: hawq reload-config [--options] +usage: hawq reload [--options] The "objects" are: cluster Reload GUC values for hawq cluster. From f46c7365610847e3f6ac51b831291dffecf09229 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Mon, 3 Jul 2017 11:29:04 -0700 Subject: [PATCH 3/4] HAWQ-1373 - Added check to verify length of arguments list --- tools/bin/hawq | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/bin/hawq b/tools/bin/hawq index 3fd914fd34..c2ea841066 100755 --- a/tools/bin/hawq +++ b/tools/bin/hawq @@ -121,12 +121,13 @@ def main(): print STOP_HELP sys.exit(1) # Prints deprecation warning when using old syntax "hawq stop -u" to reload GUC - if "-u" in sub_args or "--reload" in sub_args or "u" in sub_args.split("-")[1]: - deprecationMessage = """ - hawq stop -u is being deprecated and replaced by 'hawq reload ' - Current syntax will work but please use 'hawq reload ' going forward. - """ - print deprecationMessage + if len(sub_args.split("-")) > 1: + if "-u" in sub_args or "--reload" in sub_args or "u" in sub_args.split("-")[1]: + deprecationMessage = """ + hawq stop -u is being deprecated and replaced by 'hawq reload ' + Current syntax will work but please use 'hawq reload ' going forward. + """ + print deprecationMessage cmd = "%s; hawq_ctl %s %s" % (source_hawq_env, hawq_command, sub_args) result = local_run(cmd) elif hawq_command == "reload": From 48da94d843db58f7a14670abca7e6d77fd81a006 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Fri, 7 Jul 2017 16:18:09 -0700 Subject: [PATCH 4/4] HAWQ-1373 - Enabled printing of help message on hawq reload --- .../feature/ManagementTool/test_hawq_reload.cpp | 2 +- tools/bin/hawq | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/test/feature/ManagementTool/test_hawq_reload.cpp b/src/test/feature/ManagementTool/test_hawq_reload.cpp index 5387d9e77d..f554e366b0 100644 --- a/src/test/feature/ManagementTool/test_hawq_reload.cpp +++ b/src/test/feature/ManagementTool/test_hawq_reload.cpp @@ -33,7 +33,7 @@ using hawq::test::Command; /* Test case for hawq reload . This test changes the value of GUC log_min_messages to debug. Reloads the cluster and verifies if the change -was reloaded successfully. After the test it resets the valueof GUC to +was reloaded successfully. After the test it resets the value of GUC to default. */ TEST_F(TestHawqReload,TestReloadLogMinMessages) { diff --git a/tools/bin/hawq b/tools/bin/hawq index c2ea841066..b456df209d 100755 --- a/tools/bin/hawq +++ b/tools/bin/hawq @@ -23,11 +23,12 @@ try: import subprocess from hawqpylib.HAWQ_HELP import * from hawqpylib.hawqlib import * + from gppylib.gplog import get_default_logger except ImportError, e: sys.exit('ERROR: Cannot import modules. Please check that you ' 'have sourced greenplum_path.sh. Detail: ' + str(e)) -global hawq_home, source_hawq_env +global hawq_home, source_hawq_env, logger def print_version(): @@ -53,6 +54,7 @@ def check_master_or_standby_host(master_host_name='localhost', standby_host_name return True def main(): + logger = get_default_logger() hawq_home = os.getenv('GPHOME') if not hawq_home: print "HAWQ home directory not defined, please check GPHOME settings." @@ -123,20 +125,17 @@ def main(): # Prints deprecation warning when using old syntax "hawq stop -u" to reload GUC if len(sub_args.split("-")) > 1: if "-u" in sub_args or "--reload" in sub_args or "u" in sub_args.split("-")[1]: - deprecationMessage = """ - hawq stop -u is being deprecated and replaced by 'hawq reload ' - Current syntax will work but please use 'hawq reload ' going forward. - """ - print deprecationMessage + logger.info("hawq stop -u is being deprecated and replaced by 'hawq reload '") + logger.info("Current syntax will work, please use 'hawq reload ' going forward.") cmd = "%s; hawq_ctl %s %s" % (source_hawq_env, hawq_command, sub_args) result = local_run(cmd) elif hawq_command == "reload": - hawq_command="stop" - sub_args_list.append("-u") - sub_args=" ".join(sub_args_list) if second_arg not in cluster_type_list: print RELOAD_CONFIG_HELP sys.exit(1) + hawq_command="stop" + sub_args_list.append("-u") + sub_args=" ".join(sub_args_list) cmd = "%s; hawq_ctl %s %s" % (source_hawq_env, hawq_command, sub_args) result = local_run(cmd) elif hawq_command == "init":