1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 21:35:45 +02:00

main: single BeesContext instance per process

After weeks of testing I copied part of a change to main without copying
the rest of the change, leading to an immediate segfault on startup.

So here is the rest of the change:  limit the number of
BeesContexts per process to 1.  This change was discussed at
https://github.com/Zygo/bees/issues/54#issuecomment-360332529 but there
are more reasons to do it now:  the candidates to replace the current
hash table format are less forgiving of sharing hash tables, and it may
even become necessary to have more than one hash table per BeesContext
instance (e.g. to keep datasum and nodatasum data separate).

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2018-10-31 16:42:46 -04:00
parent e0c8df6809
commit cdca2bcdcd

View File

@ -32,7 +32,7 @@ using namespace std;
int bees_log_level = 8; int bees_log_level = 8;
int void
do_cmd_help(char *argv[]) do_cmd_help(char *argv[])
{ {
// 80col 01234567890123456789012345678901234567890123456789012345678901234567890123456789 // 80col 01234567890123456789012345678901234567890123456789012345678901234567890123456789
@ -73,7 +73,6 @@ do_cmd_help(char *argv[])
"\n" "\n"
// 80col 01234567890123456789012345678901234567890123456789012345678901234567890123456789 // 80col 01234567890123456789012345678901234567890123456789012345678901234567890123456789
<< endl; << endl;
return 0;
} }
// tracing ---------------------------------------- // tracing ----------------------------------------
@ -655,11 +654,11 @@ bees_main(int argc, char *argv[])
BeesNote::set_name("bees"); BeesNote::set_name("bees");
BEESNOTE("main"); BEESNOTE("main");
list<shared_ptr<BeesContext>> all_contexts;
shared_ptr<BeesContext> bc;
THROW_CHECK1(invalid_argument, argc, argc >= 0); THROW_CHECK1(invalid_argument, argc, argc >= 0);
// Create a context so we can apply configuration to it
shared_ptr<BeesContext> bc = make_shared<BeesContext>();
string cwd(readlink_or_die("/proc/self/cwd")); string cwd(readlink_or_die("/proc/self/cwd"));
// Defaults // Defaults
@ -705,7 +704,7 @@ bees_main(int argc, char *argv[])
// Parse options // Parse options
int c; int c;
while (1) { while (true) {
int option_index = 0; int option_index = 0;
c = getopt_long(argc, argv, getopt_list.c_str(), long_options, &option_index); c = getopt_long(argc, argv, getopt_list.c_str(), long_options, &option_index);
@ -756,12 +755,17 @@ bees_main(int argc, char *argv[])
break; break;
case 'h': case 'h':
do_cmd_help(argv); // fallthrough
default: default:
return 2; do_cmd_help(argv);
return EXIT_FAILURE;
} }
} }
if (optind + 1 != argc) {
BEESLOGERR("Only one filesystem path per bees process");
return EXIT_FAILURE;
}
Chatter::enable_timestamp(chatter_prefix_timestamp); Chatter::enable_timestamp(chatter_prefix_timestamp);
if (!relative_path().empty()) { if (!relative_path().empty()) {
@ -807,18 +811,7 @@ bees_main(int argc, char *argv[])
bc->roots()->set_workaround_btrfs_send(workaround_btrfs_send); bc->roots()->set_workaround_btrfs_send(workaround_btrfs_send);
// Create a context and start crawlers // Create a context and start crawlers
bool did_subscription = false;
while (optind < argc) {
catch_all([&]() {
bc = make_shared<BeesContext>(bc);
bc->set_root_path(argv[optind++]); bc->set_root_path(argv[optind++]);
did_subscription = true;
});
}
if (!did_subscription) {
BEESLOGWARN("WARNING: no filesystems added");
}
BeesThread status_thread("status", [&]() { BeesThread status_thread("status", [&]() {
bc->dump_status(); bc->dump_status();
@ -828,7 +821,7 @@ bees_main(int argc, char *argv[])
bc->show_progress(); bc->show_progress();
// That is all. // That is all.
return 0; return EXIT_SUCCESS;
} }
int int
@ -838,7 +831,7 @@ main(int argc, char *argv[])
if (argc < 2) { if (argc < 2) {
do_cmd_help(argv); do_cmd_help(argv);
return 2; return EXIT_FAILURE;
} }
int rv = 1; int rv = 1;