Skip to content

Commit f6ef49f

Browse files
author
Tiago Alves
committed
WL#12209 SUPPORT ATRT CLUSTER CONFIG VIA .INI FILE
Add option to [atrt] group configuration to enable cluster configuration to read from config.ini files. When configuring this option, *.cnf options are read by atrt (to know which procsses to start), config.ini files existence is checked, and cluster is started with a config.ini instead of my.cnf. Note that ndb_mgmd, ndb_api, mysqld, and client can still read settings from my.cnf. To choose from cnf or ini files a new [atrt] group setting 'config_type' was introduced. Possible values are: 'cnf' (default) or 'ini'. When 'ini' is used, atrt checks that config files for all defined clusters exist. Config files must have both configuration name and cluster name as file name, and .ini extension. Example, for someconf.cnf having: [atrt] config_type = ini clusters = .2node atrt will check for someconf.2node.ini file in the same path as someconf.cnf (i.e. $MYSQL_DIR/mysql-test/ndb) and generate appropriate command-line arguments to start cluster processes using file config.2node.ini. When using config.ini files, atrt will not automatically append settings for ndb, mysqld, or client processes as it does when using my.cnf files. Settings generation for my.cnf is as simple as appending them to the end of the file. For config.ini files, however, we need to parse the file, detect beginning and ending for each configuration group, handle duplicate settings, and only then add settings. To make matters worse, mysqld, clients, custom processes all read my.cnf. Generating my.cnf configurations could also make config.ini settings to be inconsistent. Because of all that, when using config.ini files both .cnf and .ini files must include all settings: * define ports for all processes (overriding atrt's baseport command line argument). This applies to [cluster_config.ndb_mgmd.NSUFFIX] and [mysqldSUFFIX] and [clientSUFFIX] configuration options. * define mysqld datadir (can be specified using CHOOSE_dir placeholder) * define ndb-connectstring under [mysql_cluster] configuration group * define any other [mysqld] and [client] settings whenever appropriate (applies to .atrt cluster as well). * define [ndb] FileSystemPath setting. * enable [atrt] configuration group's full qualified path names An minimal configuration example someconf.cnf is: [atrt] basedir = CHOOSE_dir # base path replaced by autotest-run.sh clusters = .2node # cluster name suffix fqpn = 1 # use full qualified path names config_type = ini # configure cluster using .ini file mysqld = CHOOSE_host1 # configure atrt database under .atrt cluster mt = 2 # Use ndbmt (0 = never, 1 = round-robin, 2 = only) fix-nodeid = 0 # management server decides NodeId order [cluster_config.2node] ndb_mgmd=CHOOSE_host1 ndbd=CHOOSE_host1,CHOOSE_host1 mysqld=CHOOSE_host1 ndbapi=CHOOSE_host1,CHOOSE_host1,CHOOSE_host1 [cluster_config.ndb_mgmd.1.2node] PortNumber=14000 [cluster_config.ndb_mgmd.2.2node] PortNumber=14001 [mysqld.1.2node] port=14002 datadir=CHOOSE_dir/cluster.2node/mysqld.1/data [client.1.2node] host=CHOOSE_host1 # must match what was defined in [cluster_config] port=14002 # must match what was defined in [mysqld.1.2node] Then, someconf.2node.ini must contain: [ndb default] NoOfReplicas=2 DataMemory=512M BackupMemory=64M [ndb_mgmd] NodeId=1 # atrt starts defining id numbers from ndb_mgmd HostName=CHOOSE_host1 # must match definition in cluster_config PortNumber=14000 # must match definition in cluster_config.ndb_mgmd.1 [ndb_mgmd] NodeId=2 HostName=CHOOSE_host1 PortNumber=14001 [ndbd] NodeId=3 # Sequential number after all ndb_mgmd ids HostName=CHOOSE_host1 # must match definiton in cluster_config FileSystemPath=CHOOSE_dir/cluster.2node/ndbd.1 [ndbd] NodeId=4 HostName=CHOOSE_host1 FileSystemPath=CHOOSE_dir/cluster.2node/ndbd.2
1 parent e36c7db commit f6ef49f

File tree

4 files changed

+93
-9
lines changed

4 files changed

+93
-9
lines changed

storage/ndb/test/run-test/atrt.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct atrt_cluster {
106106

107107
struct atrt_config {
108108
bool m_generated;
109+
enum { CNF, INI } m_config_type;
109110
BaseString m_key;
110111
BaseString m_replication;
111112
BaseString m_site;

storage/ndb/test/run-test/files.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,33 @@ bool setup_files(atrt_config& config, int setup, int sshx) {
242242
}
243243
}
244244

245+
if (config.m_config_type == atrt_config::INI) {
246+
for (unsigned i = 0; i < config.m_clusters.size(); i++) {
247+
atrt_cluster& cluster = *config.m_clusters[i];
248+
const char* cluster_name = cluster.m_name.c_str();
249+
250+
if (strcmp(cluster_name, ".atrt") == 0) {
251+
continue;
252+
}
253+
254+
BaseString dst_config_ini;
255+
dst_config_ini.assfmt("%s/config%s.ini", g_basedir, cluster_name);
256+
to_native(dst_config_ini);
257+
258+
if (!delete_file_if_exists(dst_config_ini.c_str())) {
259+
return false;
260+
}
261+
262+
BaseString src_config_ini;
263+
src_config_ini.assfmt("%s/config%s.ini", g_cwd, cluster_name);
264+
to_native(src_config_ini);
265+
266+
if (!copy_file(src_config_ini.c_str(), dst_config_ini.c_str())) {
267+
return false;
268+
}
269+
}
270+
}
271+
245272
if (setup == 2 || config.m_generated) {
246273
bool use_mysqld = (g_mysql_install_db_bin_path == NULL);
247274
if (!use_mysqld) {
@@ -319,7 +346,9 @@ bool setup_files(atrt_config& config, int setup, int sshx) {
319346
}
320347
}
321348

322-
if (config.m_generated == false) {
349+
bool skip_my_cnf_generation =
350+
config.m_config_type == atrt_config::INI || config.m_generated == false;
351+
if (skip_my_cnf_generation) {
323352
g_logger.info("Skipping my.cnf generation...");
324353
} else {
325354
bool ok = generate_my_cnf(mycnf, config);

storage/ndb/test/run-test/main.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const char *g_prefix = NULL;
7070
const char *g_prefix0 = NULL;
7171
const char *g_prefix1 = NULL;
7272
const char *g_clusters = 0;
73+
const char *g_config_type = NULL; // "cnf" or "ini"
7374
const char *g_site = NULL;
7475
BaseString g_replicate;
7576
const char *save_file = 0;
@@ -104,6 +105,7 @@ static struct {
104105
const char *g_search_path[] = {"bin", "libexec", "sbin", "scripts",
105106
"lib", "lib/mysql", 0};
106107
static bool find_binaries();
108+
static bool find_config_ini_files();
107109

108110
static struct my_option g_options[] = {
109111
{"help", '?', "Display this help and exit.", (uchar **)&g_help,
@@ -114,6 +116,8 @@ static struct my_option g_options[] = {
114116
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
115117
{"clusters", 256, "Cluster", (uchar **)&g_clusters, (uchar **)&g_clusters,
116118
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
119+
{"config-type", 256, "cnf (default) or ini", (uchar **)&g_config_type,
120+
(uchar **)&g_config_type, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
117121
{"mysqld", 256, "atrt mysqld", (uchar **)&g_mysqld_host,
118122
(uchar **)&g_mysqld_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
119123
{"replicate", 1024, "replicate", (uchar **)&g_dummy, (uchar **)&g_dummy, 0,
@@ -202,6 +206,17 @@ int main(int argc, char **argv) {
202206
goto end;
203207
}
204208

209+
g_config.m_config_type = atrt_config::CNF;
210+
if (g_config_type != NULL && strcmp(g_config_type, "ini") == 0) {
211+
g_logger.info("Using config.ini for cluster configuration");
212+
g_config.m_config_type = atrt_config::INI;
213+
214+
if (!find_config_ini_files()) {
215+
g_logger.critical("Failed to find required config.ini files");
216+
goto end;
217+
}
218+
}
219+
205220
g_config.m_generated = false;
206221
g_config.m_replication = g_replicate;
207222
if (!setup_config(g_config, g_mysqld_host)) {
@@ -1659,6 +1674,29 @@ static bool find_binaries() {
16591674
return ok;
16601675
}
16611676

1677+
static bool find_config_ini_files() {
1678+
g_logger.info("Locating config.ini files...");
1679+
1680+
BaseString tmp(g_clusters);
1681+
Vector<BaseString> clusters;
1682+
tmp.split(clusters, ",");
1683+
1684+
bool found = true;
1685+
for (unsigned int i = 0; i < clusters.size(); i++) {
1686+
BaseString config_ini_path(g_cwd);
1687+
const char *cluster_name = clusters[i].c_str();
1688+
config_ini_path.appfmt("%sconfig%s.ini", PATH_SEPARATOR, cluster_name);
1689+
to_native(config_ini_path);
1690+
1691+
if (!exists_file(config_ini_path.c_str())) {
1692+
g_logger.critical("Failed to locate '%s'", config_ini_path.c_str());
1693+
found = false;
1694+
}
1695+
}
1696+
1697+
return found;
1698+
}
1699+
16621700
template class Vector<Vector<SimpleCpcClient::Process> >;
16631701
template class Vector<atrt_host *>;
16641702
template class Vector<atrt_cluster *>;

storage/ndb/test/run-test/setup.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,39 +506,55 @@ static bool load_process(atrt_config& config, atrt_cluster& cluster,
506506
switch (type) {
507507
case atrt_process::AP_NDB_MGMD: {
508508
proc.m_proc.m_name.assfmt("%u-%s", proc_no, "ndb_mgmd");
509+
proc.m_proc.m_cwd.assfmt("%sndb_mgmd.%u", dir.c_str(), proc.m_index);
509510
proc.m_proc.m_path.assign(g_ndb_mgmd_bin_path);
511+
proc.m_proc.m_env.appfmt(" MYSQL_GROUP_SUFFIX=%s",
512+
cluster.m_name.c_str());
510513
proc.m_proc.m_args.assfmt("--defaults-file=%s/my.cnf",
511514
proc.m_host->m_basedir.c_str());
512515
proc.m_proc.m_args.appfmt(" --defaults-group-suffix=%s",
513516
cluster.m_name.c_str());
514-
proc.m_proc.m_args.append(" --nodaemon --mycnf");
517+
518+
switch (config.m_config_type) {
519+
case atrt_config::CNF: {
520+
proc.m_proc.m_args.append(" --mycnf");
521+
break;
522+
}
523+
case atrt_config::INI: {
524+
proc.m_proc.m_args.assfmt("--config-file=%s/config%s.ini",
525+
proc.m_host->m_basedir.c_str(),
526+
cluster.m_name.c_str());
527+
break;
528+
}
529+
}
530+
proc.m_proc.m_args.append(" --nodaemon");
515531
proc.m_proc.m_args.appfmt(" --ndb-nodeid=%u", proc.m_nodeid);
516-
proc.m_proc.m_cwd.assfmt("%sndb_mgmd.%u", dir.c_str(), proc.m_index);
517532
proc.m_proc.m_args.appfmt(" --configdir=%s", proc.m_proc.m_cwd.c_str());
518-
proc.m_proc.m_env.appfmt(" MYSQL_GROUP_SUFFIX=%s",
519-
cluster.m_name.c_str());
520533
break;
521534
}
522535
case atrt_process::AP_NDBD: {
536+
proc.m_proc.m_name.assfmt("%u-%s", proc_no, "ndbd");
537+
proc.m_proc.m_cwd.assfmt("%sndbd.%u", dir.c_str(), proc.m_index);
538+
523539
if (g_mt == 0 || (g_mt == 1 && ((g_mt_rr++) & 1) == 0) ||
524540
g_ndbmtd_bin_path == 0) {
525541
proc.m_proc.m_path.assign(g_ndbd_bin_path);
526542
} else {
527543
proc.m_proc.m_path.assign(g_ndbmtd_bin_path);
528544
}
529545

530-
proc.m_proc.m_name.assfmt("%u-%s", proc_no, "ndbd");
546+
proc.m_proc.m_env.appfmt(" MYSQL_GROUP_SUFFIX=%s",
547+
cluster.m_name.c_str());
548+
531549
proc.m_proc.m_args.assfmt("--defaults-file=%s/my.cnf",
532550
proc.m_host->m_basedir.c_str());
533551
proc.m_proc.m_args.appfmt(" --defaults-group-suffix=%s",
534552
cluster.m_name.c_str());
535553
proc.m_proc.m_args.append(" --nodaemon -n");
554+
536555
if (!g_restart) proc.m_proc.m_args.append(" --initial");
537556
if (g_fix_nodeid)
538557
proc.m_proc.m_args.appfmt(" --ndb-nodeid=%u", proc.m_nodeid);
539-
proc.m_proc.m_cwd.assfmt("%sndbd.%u", dir.c_str(), proc.m_index);
540-
proc.m_proc.m_env.appfmt(" MYSQL_GROUP_SUFFIX=%s",
541-
cluster.m_name.c_str());
542558
break;
543559
}
544560
case atrt_process::AP_MYSQLD: {

0 commit comments

Comments
 (0)