Skip to content

Commit 073e835

Browse files
committed
BUG#35795129 BUG#35782142 BUG#29455103 BUG#29949127
Misc cosmetic fixes and code cleanups BUG#35795129 Incorrect help for Cluster.describe The helper text for Cluster.describe() mentions that the output includes a field named 'version' with the version of each member. That's incorrect and there's no such field in described(). This patch removes the incorrect information from the helper text. BUG#35782142 Shell user, api, and cmdline docs missing info on resource naming The API documentation and helper lacks information about naming limitations for the Cluster/ReplicaSet/ClusterSet name and instance labels. This patch extends the API documentation and helper with all the naming limitations. BUG#29455103 IMPROVE MESSAGES FOR CONFIGUREINSTANCE WHEN INSTANCE IS VALID dba.configureInstance() prints two similar messages when an instance is already ready to be used in a Cluster. For example: The instance 'localhost:3300' is valid for InnoDB cluster usage. The instance 'localhost:3300' is already ready for InnoDB cluster usage. The second message is redundant so this patch removes it while improving the first one. BUG#29949127 MENTION CURRENT SERVER VERSION WHEN ADD_INSTANCE() FAILS DUE < 8.017 When addInstance() finds that only clone can be used and the target instance does not support it because of its version, the command prints an error indicating clone must be used and that it is available since 8.0.17, however, it does not include the target instance version. To make the message more clear, this patch includes the target instance version in the error message. Change-Id: Id0fdac5699e9f0a0697ebe780fd6107d4513826c
1 parent 51a14e5 commit 073e835

File tree

70 files changed

+756
-743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+756
-743
lines changed

modules/adminapi/common/cluster_types.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ std::string to_display_string(Cluster_type type, Display_form form) {
200200
case Cluster_type::GROUP_REPLICATION:
201201
switch (form) {
202202
case Display_form::THING_FULL:
203-
return "InnoDB cluster";
203+
return "InnoDB Cluster";
204204

205205
case Display_form::A_THING_FULL:
206-
return "an InnoDB cluster";
206+
return "an InnoDB Cluster";
207207

208208
case Display_form::THINGS_FULL:
209-
return "InnoDB clusters";
209+
return "InnoDB Clusters";
210210

211211
case Display_form::THING:
212212
return "cluster";

modules/adminapi/common/gtid_validations.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "mysqlshdk/libs/mysql/clone.h"
3232
#include "mysqlshdk/libs/mysql/gtid_utils.h"
3333
#include "mysqlshdk/libs/mysql/replication.h"
34-
#include "mysqlshdk/libs/textui/textui.h"
34+
#include "mysqlshdk/libs/utils/version.h"
3535

3636
namespace mysqlsh {
3737
namespace dba {
@@ -139,18 +139,20 @@ void validate_incremental_recovery(Member_op_action op_action,
139139
}
140140
}
141141

142-
Prompt_type validate_auto_recovery(Cluster_type cluster_type,
143-
Member_op_action op_action,
144-
bool recovery_possible, bool recovery_safe,
145-
bool clone_supported, bool gtid_set_diverged,
146-
bool interactive, bool clone_disabled) {
142+
Prompt_type validate_auto_recovery(
143+
Cluster_type cluster_type, Member_op_action op_action,
144+
bool recovery_possible, bool recovery_safe, bool clone_supported,
145+
bool gtid_set_diverged, bool interactive, bool clone_disabled,
146+
mysqlshdk::utils::Version target_instance_version) {
147147
auto console = current_console();
148148

149149
Prompt_type prompt = None;
150150

151151
std::string clone_available_since =
152152
"Built-in clone support is available starting with MySQL 8.0.17 and is "
153-
"the recommended method for provisioning instances.";
153+
"the recommended method for provisioning instances. Instance is running "
154+
"MySQL " +
155+
target_instance_version.get_full() + ".";
154156

155157
std::string target_clone_or_provisioned_add =
156158
"The target instance must be either cloned or fully provisioned before "
@@ -510,7 +512,8 @@ Member_recovery_method validate_instance_recovery(
510512
} else {
511513
Prompt_type prompt = validate_auto_recovery(
512514
cluster_type, op_action, recovery_possible, recovery_safe,
513-
clone_supported, gtid_set_diverged, interactive, clone_disabled);
515+
clone_supported, gtid_set_diverged, interactive, clone_disabled,
516+
target_instance.get_version());
514517

515518
console->print_info();
516519

modules/adminapi/common/validations.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "modules/adminapi/common/common.h"
3030
#include "modules/adminapi/common/dba_errors.h"
3131
#include "modules/adminapi/common/instance_validations.h"
32+
#include "modules/adminapi/common/topology_executor.h"
3233
#include "modules/adminapi/dba/check_instance.h"
3334
#include "mysqlshdk/include/shellcore/console.h"
3435
#include "mysqlshdk/libs/mysql/replication.h"
@@ -49,11 +50,11 @@ void ensure_gr_instance_configuration_valid(
4950
"Validating instance configuration at " +
5051
target_instance->get_connection_options().uri_endpoint() + "...");
5152

52-
Check_instance check(target_instance->get_connection_options(), "", true,
53-
skip_check_tables_pk);
54-
check.prepare();
55-
result = check.execute();
56-
check.finish();
53+
result =
54+
Topology_executor<Check_instance>{
55+
target_instance->get_connection_options(), "", true,
56+
skip_check_tables_pk}
57+
.run();
5758

5859
if (!result || result.as_map()->at("status").get_string() == "ok") {
5960
console->print_info("Instance configuration is suitable.");

modules/adminapi/dba/check_instance.cc

Lines changed: 42 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,17 @@
2525

2626
#include <memory>
2727

28-
#include "adminapi/common/common.h"
2928
#include "modules/adminapi/common/accounts.h"
29+
#include "modules/adminapi/common/common.h"
3030
#include "modules/adminapi/common/instance_validations.h"
31-
#include "modules/adminapi/common/provision.h"
3231
#include "modules/adminapi/common/server_features.h"
33-
#include "modules/adminapi/common/sql.h"
3432
#include "modules/adminapi/common/validations.h"
3533
#include "mysqlshdk/include/shellcore/console.h"
36-
#include "mysqlshdk/libs/config/config_file_handler.h"
37-
#include "mysqlshdk/libs/config/config_server_handler.h"
38-
#include "mysqlshdk/libs/db/mysql/session.h"
3934
#include "mysqlshdk/libs/mysql/clone.h"
40-
#include "mysqlshdk/libs/mysql/replication.h"
4135
#include "mysqlshdk/libs/utils/utils_file.h"
42-
#include "mysqlshdk/libs/utils/utils_general.h"
4336
#include "mysqlshdk/libs/utils/utils_net.h"
44-
#include "mysqlshdk/libs/utils/utils_string.h"
4537

46-
namespace mysqlsh {
47-
namespace dba {
38+
namespace mysqlsh::dba {
4839

4940
// Constructor receives command parameters, ref to ProvisioningInterface and
5041
// ref to IConsole. It should also perform basic validation of
@@ -58,8 +49,6 @@ Check_instance::Check_instance(
5849
m_silent(silent),
5950
m_skip_check_tables_pk{skip_check_tables_pk} {}
6051

61-
Check_instance::~Check_instance() = default;
62-
6352
void Check_instance::check_instance_address() {
6453
// Sanity check for the instance address
6554
if (is_sandbox(*m_target_instance, nullptr)) {
@@ -158,17 +147,46 @@ bool Check_instance::check_configuration() {
158147
return false;
159148
}
160149

161-
if (!m_silent)
150+
if (!m_silent) {
162151
console->print_info(
163152
"Instance configuration is compatible with InnoDB cluster");
153+
}
154+
164155
return true;
165156
}
166157

167-
/*
168-
* Validates the parameter and performs other validations regarding
169-
* the command execution
170-
*/
171-
void Check_instance::prepare() {
158+
void Check_instance::prepare_config_object() {
159+
bool use_cfg_handler = false;
160+
// if the configuration file was provided and exists, we add it to the
161+
// config object.
162+
if (!m_mycnf_path.empty()) {
163+
if (shcore::is_file(m_mycnf_path)) {
164+
use_cfg_handler = true;
165+
} else {
166+
mysqlsh::current_console()->print_error(
167+
"Configuration file " + m_mycnf_path +
168+
" doesn't exist. The verification of the file will be skipped.");
169+
170+
// Clear it up so we don't print any odd log message
171+
m_mycnf_path = "";
172+
}
173+
}
174+
// Add server configuration handler depending on SET PERSIST support.
175+
// NOTE: Add server handler first to set it has the default handler.
176+
m_cfg = mysqlsh::dba::create_server_config(
177+
m_target_instance.get(), mysqlshdk::config::k_dft_cfg_server_handler,
178+
true);
179+
180+
// Add configuration handle to update option file (if provided) and not to
181+
// be skipped
182+
if (use_cfg_handler) {
183+
mysqlsh::dba::add_config_file_handler(
184+
m_cfg.get(), mysqlshdk::config::k_dft_cfg_file_handler,
185+
m_target_instance->get_uuid(), m_mycnf_path, m_mycnf_path);
186+
}
187+
}
188+
189+
shcore::Value Check_instance::do_run() {
172190
auto console = mysqlsh::current_console();
173191

174192
// Establish a session to the target instance
@@ -184,12 +202,12 @@ void Check_instance::prepare() {
184202
if (!local_target) {
185203
console->print_info("Validating MySQL instance at " +
186204
m_target_instance->descr() +
187-
" for use in an InnoDB cluster...");
205+
" for use in an InnoDB Cluster...");
188206
} else {
189207
console->print_info(
190208
"Validating local MySQL instance listening at port " +
191209
std::to_string(m_target_instance->get_canonical_port()) +
192-
" for use in an InnoDB cluster...");
210+
" for use in an InnoDB Cluster...");
193211
}
194212
}
195213

@@ -242,57 +260,11 @@ void Check_instance::prepare() {
242260
if (m_is_valid && !m_silent) {
243261
console->print_info();
244262
console->print_info("The instance '" + target +
245-
"' is valid to be used in an InnoDB cluster.");
263+
"' is valid for InnoDB Cluster usage.");
246264
}
247-
}
248265

249-
/*
250-
* Executes the API command.
251-
*
252-
* This is a purely check command, no changes are made, thus execute()
253-
* is a no-op.
254-
*/
255-
shcore::Value Check_instance::execute() {
256266
mysqlsh::current_console()->print_info();
257-
return m_ret_val;
258-
}
259-
260-
void Check_instance::rollback() {
261-
// nothing to rollback
262-
}
263-
264-
void Check_instance::finish() {}
265-
266-
void Check_instance::prepare_config_object() {
267-
bool use_cfg_handler = false;
268-
// if the configuration file was provided and exists, we add it to the
269-
// config object.
270-
if (!m_mycnf_path.empty()) {
271-
if (shcore::is_file(m_mycnf_path)) {
272-
use_cfg_handler = true;
273-
} else {
274-
mysqlsh::current_console()->print_error(
275-
"Configuration file " + m_mycnf_path +
276-
" doesn't exist. The verification of the file will be skipped.");
277267

278-
// Clear it up so we don't print any odd log message
279-
m_mycnf_path = "";
280-
}
281-
}
282-
// Add server configuration handler depending on SET PERSIST support.
283-
// NOTE: Add server handler first to set it has the default handler.
284-
m_cfg = mysqlsh::dba::create_server_config(
285-
m_target_instance.get(), mysqlshdk::config::k_dft_cfg_server_handler,
286-
true);
287-
288-
// Add configuration handle to update option file (if provided) and not to
289-
// be skipped
290-
if (use_cfg_handler) {
291-
mysqlsh::dba::add_config_file_handler(
292-
m_cfg.get(), mysqlshdk::config::k_dft_cfg_file_handler,
293-
m_target_instance->get_uuid(), m_mycnf_path, m_mycnf_path);
294-
}
268+
return m_ret_val;
295269
}
296-
297-
} // namespace dba
298-
} // namespace mysqlsh
270+
} // namespace mysqlsh::dba

modules/adminapi/dba/check_instance.h

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License, version 2.0,
@@ -24,30 +24,30 @@
2424
#ifndef MODULES_ADMINAPI_DBA_CHECK_INSTANCE_H_
2525
#define MODULES_ADMINAPI_DBA_CHECK_INSTANCE_H_
2626

27-
#include <memory>
28-
#include <optional>
29-
#include <string>
30-
3127
#include "modules/adminapi/common/instance_pool.h"
32-
#include "modules/adminapi/common/provisioning_interface.h"
33-
#include "modules/adminapi/dba/configure_instance.h"
34-
#include "modules/command_interface.h"
35-
#include "mysqlshdk/include/scripting/types_cpp.h"
28+
#include "mysqlshdk/libs/config/config.h"
3629

37-
namespace mysqlsh {
38-
namespace dba {
30+
namespace mysqlsh::dba {
3931

40-
class Check_instance : public Command_interface {
32+
class Check_instance {
4133
public:
42-
Check_instance(const mysqlshdk::db::Connection_options &instance_cnx_opts,
43-
const std::string &verify_mycnf_path, bool silent = false,
44-
bool skip_check_tables_pk = false);
45-
~Check_instance();
34+
Check_instance() = delete;
35+
36+
explicit Check_instance(
37+
const mysqlshdk::db::Connection_options &instance_cnx_opts,
38+
const std::string &verify_mycnf_path, bool silent = false,
39+
bool skip_check_tables_pk = false);
40+
41+
Check_instance(const Check_instance &) = delete;
42+
Check_instance(Check_instance &&) = delete;
43+
Check_instance &operator=(const Check_instance &) = delete;
44+
Check_instance &operator=(Check_instance &&) = delete;
45+
46+
~Check_instance() = default;
4647

47-
void prepare() override;
48-
shcore::Value execute() override;
49-
void rollback() override;
50-
void finish() override;
48+
protected:
49+
shcore::Value do_run();
50+
static constexpr bool supports_undo() noexcept { return false; }
5151

5252
private:
5353
void check_instance_address();
@@ -79,7 +79,6 @@ class Check_instance : public Command_interface {
7979
std::unique_ptr<mysqlshdk::config::Config> m_cfg;
8080
};
8181

82-
} // namespace dba
83-
} // namespace mysqlsh
82+
} // namespace mysqlsh::dba
8483

8584
#endif // MODULES_ADMINAPI_DBA_CHECK_INSTANCE_H_

0 commit comments

Comments
 (0)