Skip to content

Commit 06c4853

Browse files
author
Paweł Andruszkiewicz
committed
BUG#35830920 mysqlsh util.loadDump should exclude the same tables as util.dumpInstance
When loading (or copying) a dump, and the target is an MHS instance, mysql_audit and mysql_firewall schemas are automatically excluded, Change-Id: Iabdbe2a8d08bc4ba72e47a096c4456b522dd457f (cherry picked from commit 9ae5b4c82491bcdf402f5acf8421b3e6c5a6f560)
1 parent 0d57947 commit 06c4853

File tree

4 files changed

+110
-28
lines changed

4 files changed

+110
-28
lines changed

modules/util/common/dump/constants.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License, version 2.0,
6+
* as published by the Free Software Foundation.
7+
*
8+
* This program is also distributed with certain software (including
9+
* but not limited to OpenSSL) that is licensed under separate terms, as
10+
* designated in a particular file or component or in included license
11+
* documentation. The authors of MySQL hereby grant you an additional
12+
* permission to link the program and your derivative works with the
13+
* separately licensed software that they have included with MySQL.
14+
* This program is distributed in the hope that it will be useful, but
15+
* WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17+
* the GNU General Public License, version 2.0, for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program; if not, write to the Free Software Foundation, Inc.,
21+
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*/
23+
24+
#ifndef MODULES_UTIL_COMMON_DUMP_CONSTANTS_H_
25+
#define MODULES_UTIL_COMMON_DUMP_CONSTANTS_H_
26+
27+
#include <array>
28+
29+
namespace mysqlsh {
30+
namespace dump {
31+
namespace common {
32+
33+
constexpr inline std::array k_excluded_users = {
34+
"mysql.infoschema",
35+
"mysql.session",
36+
"mysql.sys",
37+
};
38+
39+
constexpr inline std::array k_mhs_excluded_users = {
40+
"administrator",
41+
"ociadmin",
42+
"ocimonitor",
43+
"ocirpl",
44+
};
45+
46+
constexpr inline std::array k_excluded_schemas = {
47+
"information_schema", "mysql", "ndbinfo", "performance_schema", "sys",
48+
};
49+
50+
constexpr inline std::array k_mhs_excluded_schemas = {
51+
// stores the audit plugin's configuration
52+
"mysql_audit",
53+
// stores the firewall's configuration
54+
"mysql_firewall",
55+
};
56+
57+
} // namespace common
58+
} // namespace dump
59+
} // namespace mysqlsh
60+
61+
#endif // MODULES_UTIL_COMMON_DUMP_CONSTANTS_H_

modules/util/dump/dump_instance_options.cc

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <utility>
2727
#include <vector>
2828

29+
#include "modules/util/common/dump/constants.h"
2930
#include "modules/util/common/dump/utils.h"
3031

3132
#include "mysqlshdk/include/scripting/type_info/custom.h"
@@ -35,22 +36,12 @@
3536
namespace mysqlsh {
3637
namespace dump {
3738

38-
namespace {
39-
40-
const char *k_excluded_users[] = {"mysql.infoschema", "mysql.session",
41-
"mysql.sys"};
42-
43-
const char *k_excluded_schemas[] = {"information_schema", "mysql", "ndbinfo",
44-
"performance_schema", "sys"};
45-
46-
} // namespace
47-
4839
Dump_instance_options::Dump_instance_options() {
4940
// some users are always excluded
50-
filters().users().exclude(k_excluded_users);
41+
filters().users().exclude(common::k_excluded_users);
5142

5243
// some schemas are always excluded
53-
filters().schemas().exclude(k_excluded_schemas);
44+
filters().schemas().exclude(common::k_excluded_schemas);
5445
}
5546

5647
const shcore::Option_pack_def<Dump_instance_options>
@@ -71,8 +62,7 @@ const shcore::Option_pack_def<Dump_instance_options>
7162

7263
void Dump_instance_options::on_unpacked_options() {
7364
if (!m_dump_users) {
74-
if (filters().users().excluded().size() >
75-
shcore::array_size(k_excluded_users)) {
65+
if (filters().users().excluded().size() > common::k_excluded_users.size()) {
7666
throw std::invalid_argument(
7767
"The 'excludeUsers' option cannot be used if the 'users' option is "
7868
"set to false.");
@@ -86,13 +76,9 @@ void Dump_instance_options::on_unpacked_options() {
8676
}
8777

8878
if (mds_compatibility()) {
89-
auto &schemas = filters().schemas();
90-
// if MDS compatibility option is set, the following schemas should be
91-
// excluded automatically:
92-
// - stores the audit plugin's configuration
93-
schemas.exclude("mysql_audit");
94-
// - stores the firewall's configuration
95-
schemas.exclude("mysql_firewall");
79+
// if MHS compatibility option is set, some schemas should be excluded
80+
// automatically
81+
filters().schemas().exclude(common::k_mhs_excluded_schemas);
9682
}
9783

9884
m_filter_conflicts |= filters().schemas().error_on_conflicts();

modules/util/load/load_dump_options.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <utility>
3232

3333
#include "modules/mod_utils.h"
34+
#include "modules/util/common/dump/constants.h"
3435
#include "modules/util/common/dump/utils.h"
3536
#include "modules/util/dump/dump_manifest_config.h"
3637
#include "modules/util/load/load_errors.h"
@@ -51,11 +52,6 @@ namespace {
5152

5253
using Version = mysqlshdk::utils::Version;
5354

54-
const char *k_excluded_users[] = {"mysql.infoschema", "mysql.session",
55-
"mysql.sys"};
56-
const char *k_oci_excluded_users[] = {"administrator", "ociadmin", "ocimonitor",
57-
"ocirpl"};
58-
5955
constexpr auto k_minimum_max_bytes_per_transaction = 4096;
6056

6157
} // namespace
@@ -247,10 +243,10 @@ void Load_dump_options::set_session(
247243

248244
if (m_load_users) {
249245
// some users are always excluded
250-
filters().users().exclude(k_excluded_users);
246+
filters().users().exclude(dump::common::k_excluded_users);
251247

252248
if (is_mds()) {
253-
filters().users().exclude(k_oci_excluded_users);
249+
filters().users().exclude(dump::common::k_mhs_excluded_users);
254250
}
255251

256252
shcore::Account account;
@@ -260,6 +256,10 @@ void Load_dump_options::set_session(
260256
filters().users().exclude(std::move(account));
261257
}
262258

259+
if (is_mds()) {
260+
filters().schemas().exclude(dump::common::k_mhs_excluded_schemas);
261+
}
262+
263263
if (m_target_server_version >= Version(8, 0, 27)) {
264264
// adding indexes in parallel was added in 8.0.27,
265265
// innodb_parallel_read_threads threads are used during the first stage,

unittest/scripts/auto/py_shell/scripts/util_dump_and_load_norecord.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,6 +3043,41 @@ def TEST_BOOL_OPTION(option):
30433043
shell.connect(__sandbox_uri1)
30443044
session.run_sql("DROP SCHEMA IF EXISTS !;", [schema_name])
30453045

3046+
#@<> BUG#35830920 mysql_audit and mysql_firewall schemas should be automatically excluded when loading a dump into MHS - setup {not __dbug_off}
3047+
# create schemas
3048+
schema_names = [ "mysql_audit", "mysql_firewall" ]
3049+
3050+
def create_mhs_schemas(s):
3051+
for schema_name in schema_names:
3052+
s.run_sql("DROP SCHEMA IF EXISTS !", [schema_name])
3053+
s.run_sql("CREATE SCHEMA !", [schema_name])
3054+
s.run_sql("CREATE TABLE !.! (a int)", [schema_name, "test_table"])
3055+
3056+
create_mhs_schemas(session1)
3057+
wipeout_server(session2)
3058+
create_mhs_schemas(session2)
3059+
3060+
# create a MHS-compatible dump but without 'ocimds' option
3061+
shell.connect(__sandbox_uri1)
3062+
dump_dir = os.path.join(outdir, "bug_35830920")
3063+
EXPECT_NO_THROWS(lambda: util.dump_schemas(schema_names, dump_dir, { "ddlOnly": True, "showProgress": False }), "Dumping the instance should not fail")
3064+
3065+
#@<> BUG#35830920 - test {not __dbug_off}
3066+
shell.connect(__sandbox_uri2)
3067+
3068+
# loading into non-MHS should fail, because schemas already exist
3069+
EXPECT_THROWS(lambda: util.load_dump(dump_dir, { "showProgress": False }), "Duplicate objects found in destination database")
3070+
testutil.rmfile(os.path.join(dump_dir, "load-progress*.json"))
3071+
3072+
# loading into MHS should automatically exclude the schemas and operation should succeed
3073+
testutil.dbug_set("+d,dump_loader_force_mds")
3074+
EXPECT_NO_THROWS(lambda: util.load_dump(dump_dir, { "ignoreVersion": True, "showProgress": False }), "Loading should not fail")
3075+
testutil.dbug_set("")
3076+
3077+
#@<> BUG#35830920 - cleanup {not __dbug_off}
3078+
for schema_name in schema_names:
3079+
session.run_sql("DROP SCHEMA !;", [schema_name])
3080+
30463081
#@<> Cleanup
30473082
testutil.destroy_sandbox(__mysql_sandbox_port1)
30483083
testutil.destroy_sandbox(__mysql_sandbox_port2)

0 commit comments

Comments
 (0)