diff --git a/core/tarantool.c b/core/tarantool.c index 67c74a29fac8575e16ab409323dea99833b90d02..0e6e4cac55c4e088bc3d0f3bbe2c53affd4c76ed 100644 --- a/core/tarantool.c +++ b/core/tarantool.c @@ -62,6 +62,7 @@ char *cfg_filename_fullpath = NULL; struct tbuf *cfg_out = NULL; char *binary_filename; struct tarantool_cfg cfg; +struct recovery_state *recovery_state; bool init_storage, booting = true; @@ -416,27 +417,6 @@ main(int argc, char **argv) panic("can't load config:" "%.*s", cfg_out->len, (char *)cfg_out->data); -#ifdef STORAGE - if (gopt_arg(opt, 'C', &cat_filename)) { - initialize_minimal(); - if (access(cat_filename, R_OK) == -1) { - say_syserror("access(\"%s\")", cat_filename); - exit(EX_OSFILE); - } - return mod_cat(cat_filename); - } - - if (gopt(opt, 'I')) { - init_storage = true; - initialize_minimal(); - mod_init(); - next_lsn(recovery_state, 1); - confirm_lsn(recovery_state, 1); - snapshot_save(recovery_state, mod_snapshot); - exit(EXIT_SUCCESS); - } -#endif - if (gopt_arg(opt, 'g', &cfg_paramname)) { tarantool_cfg_iterator_t *i; char *key, *value; @@ -494,6 +474,27 @@ main(int argc, char **argv) #endif } +#ifdef STORAGE + if (gopt_arg(opt, 'C', &cat_filename)) { + initialize_minimal(); + if (access(cat_filename, R_OK) == -1) { + say_syserror("access(\"%s\")", cat_filename); + exit(EX_OSFILE); + } + return mod_cat(cat_filename); + } + + if (gopt(opt, 'I')) { + init_storage = true; + initialize_minimal(); + mod_init(); + next_lsn(recovery_state, 1); + confirm_lsn(recovery_state, 1); + snapshot_save(recovery_state, mod_snapshot); + exit(EXIT_SUCCESS); + } +#endif + if (gopt(opt, 'D')) daemonize(1, 1); diff --git a/include/log_io.h b/include/log_io.h index 64fe367f4230781f36a8d39d55c9192d07388a93..12809677c9660349055dc3cc4a743248a295afdd 100644 --- a/include/log_io.h +++ b/include/log_io.h @@ -96,7 +96,7 @@ struct recovery_state { bool finalize; - /* pointer to user supplied custom data */ + /* Points to module-specific state */ void *data; }; diff --git a/include/tarantool.h b/include/tarantool.h index 78b80b8c1fab950537f200c9dadd41c7d1c56d11..2e8d409d0977ae346349f0ad01b4e76b7237d59f 100644 --- a/include/tarantool.h +++ b/include/tarantool.h @@ -31,7 +31,7 @@ #include <util.h> #include <log_io.h> -struct recovery_state *recovery_state; +extern struct recovery_state *recovery_state; void mod_init(void); struct tarantool_cfg; i32 mod_check_config(struct tarantool_cfg *conf); diff --git a/test/box/args.result b/test/box/args.result index 68b984bcfecf67a955553e0f5ba2dc0afa317e3a..70ecd41660aaf359c6b270762a1885283b415417 100644 --- a/test/box/args.result +++ b/test/box/args.result @@ -65,3 +65,18 @@ tarantool_silverbox --version tarantool_silverbox -V 1.minor.patch-<rev>-<commit> +# +# A test case for Bug#726778 "Gopt broke wal_dir and snap_dir: they are no +# longer relative to work_dir". +# https://bugs.launchpad.net/tarantool/+bug/726778 +# After addition of gopt(), we started to chdir() to the working +# directory after option parsing. +# Verify that this is not the case, and snap_dir and xlog_dir +# can be relative to work_dir. + +tarantool_silverbox --config=bug726778.cfg --init-storage +tarantool_silverbox: namespace 0 successfully configured +tarantool_silverbox: creating `snapshots/00000000000000000001.snap.inprogress' +tarantool_silverbox: saving snapshot `snapshots/00000000000000000001.snap' +tarantool_silverbox: done + diff --git a/test/box/args.test b/test/box/args.test index fa2595804f4ed3fdf55572e6f2c929573f3a0867..5648a8704111a014690d6fe78f526970ea6d7fe0 100644 --- a/test/box/args.test +++ b/test/box/args.test @@ -13,3 +13,31 @@ sys.stdout.push_filter("(\d)\.\d\.\d(-\d+-\w+)?", "\\1.minor.patch-<rev>-<commit server.test_option("--version") server.test_option("-V ") sys.stdout.pop_filter() + +print """# +# A test case for Bug#726778 "Gopt broke wal_dir and snap_dir: they are no +# longer relative to work_dir". +# https://bugs.launchpad.net/tarantool/+bug/726778 +# After addition of gopt(), we started to chdir() to the working +# directory after option parsing. +# Verify that this is not the case, and snap_dir and xlog_dir +# can be relative to work_dir. +""" +import shutil +shutil.rmtree(os.path.join(vardir, "bug726778"), True) +cfg = os.path.join(vardir, "bug726778.cfg") +os.mkdir(os.path.join(vardir, "bug726778")) +os.mkdir(os.path.join(vardir, "bug726778/snapshots")) +os.mkdir(os.path.join(vardir, "bug726778/xlogs")) + +os.symlink(os.path.abspath("box/bug726778.cfg"), cfg) + +sys.stdout.push_filter("(/\S+)+/tarantool", "tarantool") +server.test_option("--config=bug726778.cfg --init-storage") +sys.stdout.pop_filter() + +os.unlink(cfg) +shutil.rmtree(os.path.join(vardir, "bug726778")) + +# Args filter cleanup +# vim: syntax=python diff --git a/test/box/bug726778.cfg b/test/box/bug726778.cfg new file mode 100644 index 0000000000000000000000000000000000000000..449c3986fec792578763065a20655a9131ee8ebf --- /dev/null +++ b/test/box/bug726778.cfg @@ -0,0 +1,27 @@ +# +# Used in args.test +# +slab_alloc_arena = 0.1 + +pid_file = "box.pid" + +work_dir = "bug726778" +snap_dir = "snapshots" +wal_dir = "xlogs" + +# Use -a not -a to work correctly on FreeBSD +# +logger="tee -a tarantool.log" + +primary_port = 33013 +secondary_port = 33014 +admin_port = 33015 + +rows_per_wal = 50 + +namespace[0].enabled = 1 +namespace[0].index[0].type = "HASH" +namespace[0].index[0].unique = 1 +namespace[0].index[0].key_field[0].fieldno = 0 +namespace[0].index[0].key_field[0].type = "NUM" +