Skip to content

Commit 069fedc

Browse files
Bug#32651203: MYSQL_MIGRATE_KEYRING --ONLINE-MIGRATION CRASH
Description: Error handling needed improvements when insufficient details are provided to execute migration utility. Fix: Update Keyring_migration class to handle connection errors better. RB: 26222
1 parent 9af8429 commit 069fedc

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

client/migrate_keyring/components.cc

+5-7
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,9 @@ Destination_keyring_services::~Destination_keyring_services() {
181181
Keyring_migrate::Keyring_migrate(Source_keyring_services &src,
182182
Destination_keyring_services &dst,
183183
bool online_migration)
184-
: src_(src),
185-
dst_(dst),
186-
iterator_(nullptr),
187-
mysql_connection_(online_migration),
188-
ok_(false),
189-
maximum_size_(16384) {
184+
: src_(src), dst_(dst), mysql_connection_(online_migration) {
190185
if (!src_.ok() || !dst_.ok()) return;
186+
if (online_migration && !mysql_connection_.ok()) return;
191187
if (lock_source_keyring() == false) {
192188
log_error << "Failed to lock source keyring" << std::endl;
193189
return;
@@ -202,12 +198,14 @@ Keyring_migrate::Keyring_migrate(Source_keyring_services &src,
202198

203199
bool Keyring_migrate::lock_source_keyring() {
204200
if (Options::s_online_migration == false) return true;
201+
if (!mysql_connection_.ok()) return false;
205202
std::string lock_statement("SET GLOBAL KEYRING_OPERATIONS=0");
206203
return mysql_connection_.execute(lock_statement);
207204
}
208205

209206
bool Keyring_migrate::unlock_source_keyring() {
210-
if (Options::s_online_migration == false) return true;
207+
if (Options::s_online_migration == false || !mysql_connection_.ok())
208+
return true;
211209
std::string unlock_statement("SET GLOBAL KEYRING_OPERATIONS=1");
212210
return mysql_connection_.execute(unlock_statement);
213211
}

client/migrate_keyring/components.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ class Keyring_migrate final {
137137
private:
138138
Source_keyring_services &src_;
139139
Destination_keyring_services &dst_;
140-
my_h_keyring_keys_metadata_iterator iterator_;
140+
my_h_keyring_keys_metadata_iterator iterator_{nullptr};
141141
options::Mysql_connection mysql_connection_;
142-
bool ok_;
143-
const size_t maximum_size_;
142+
bool ok_{false};
143+
const size_t maximum_size_{16384};
144144
};
145145

146146
} // namespace components

client/migrate_keyring/options.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ Mysql_connection::Mysql_connection(bool connect) : ok_(false), mysql(nullptr) {
329329
Options::s_password, NullS, Options::s_port,
330330
Options::s_socket, CLIENT_REMEMBER_OPTIONS)) {
331331
mysql->reconnect = true;
332-
log_error << "Failed to connect to server at " << Options::s_hostname
333-
<< ": " << mysql_error(mysql) << std::endl;
332+
log_error << "Failed to connect to server. Received error: "
333+
<< mysql_error(mysql) << std::endl;
334334
return;
335335
}
336336
log_info << "Successfully connected to MySQL server" << std::endl;
@@ -350,7 +350,7 @@ Mysql_connection::~Mysql_connection() {
350350

351351
bool Mysql_connection::execute(std::string command) {
352352
if (!ok_) {
353-
log_error << " Connection to MySQL server is not initialized." << std::endl;
353+
log_error << "Connection to MySQL server is not initialized." << std::endl;
354354
return false;
355355
}
356356
if (mysql_real_query(mysql, command.c_str(), command.length())) {

0 commit comments

Comments
 (0)