Skip to content

Commit 2b816bc

Browse files
committed
provdb_admin:
Fixed missing intialization of db_in_mem argument to false Added a cmdline option to load a base configuration for the unqlite databases from a JSON file Please enter the commit message for your changes. Lines starting
1 parent 81801e2 commit 2b816bc

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

app/provdb_admin.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <iostream>
1818
#include <csignal>
1919
#include <cassert>
20+
#include <nlohmann/json.hpp>
2021

2122
#include <spdlog/spdlog.h>
2223
#include "chimbuko/verbose.hpp"
@@ -131,8 +132,9 @@ struct ProvdbArgs{
131132
unsigned long db_commit_freq;
132133
std::string db_write_dir;
133134
bool db_in_mem; //database is in-memory not written to disk, for testing
134-
135-
ProvdbArgs(): engine("ofi+tcp"), autoshutdown(true), nshards(1), db_type("unqlite"), nthreads(1), db_commit_freq(10000), db_write_dir("."){}
135+
std::string db_base_config;
136+
137+
ProvdbArgs(): engine("ofi+tcp"), autoshutdown(true), nshards(1), db_type("unqlite"), nthreads(1), db_commit_freq(10000), db_write_dir("."), db_in_mem(false), db_base_config(""){}
136138
};
137139

138140

@@ -159,7 +161,7 @@ int main(int argc, char** argv) {
159161
addOptionalCommandLineArg(parser, db_commit_freq, "Specify the frequency at which the database flushes to disk in ms (default 10000). 0 disables the flush until the end.");
160162
addOptionalCommandLineArg(parser, db_write_dir, "Specify the directory in which the database shards will be written (default \".\")");
161163
addOptionalCommandLineArg(parser, db_in_mem, "Use an in-memory database rather than writing to disk (*unqlite backend only*) (default false)");
162-
164+
addOptionalCommandLineArg(parser, db_base_config, "Provide the *absolute path* to a JSON file to use as the base configuration of the Sonata databases. The database path will be appended automatically (default \"\" - not used)");
163165

164166
if(argc-1 < parser.nMandatoryArgs() || (argc == 2 && std::string(argv[1]) == "-help")){
165167
parser.help(std::cout);
@@ -179,6 +181,13 @@ int main(int argc, char** argv) {
179181
eng_opt += std::string("://") + args.ip;
180182
}
181183

184+
nlohmann::json base_config;
185+
if(args.db_base_config.size() > 0){
186+
std::ifstream in(args.db_base_config);
187+
if(in.fail()){ throw std::runtime_error("Failed to read db config file " + args.db_base_config); }
188+
base_config = nlohmann::json::parse(in);
189+
}
190+
182191
progressStream << "ProvDB Admin: initializing thallium with address: " << eng_opt << std::endl;
183192

184193
//Disable loopback so that RPC calls from this process are forced to go through the net interface
@@ -227,25 +236,25 @@ int main(int argc, char** argv) {
227236

228237
{ //Scope in which admin object is active
229238
sonata::Admin admin(engine);
230-
progressStream << "ProvDB Admin: creating global data database" << std::endl;
231239
std::string glob_db_name = "provdb.global";
232240

233-
std::string glob_db_config = stringize("{ \"path\" : \"%s/%s.unqlite\" }", args.db_write_dir.c_str(), glob_db_name.c_str());
234-
if(args.db_in_mem) glob_db_config = "{ \"path\" : \":mem:\" }";
241+
nlohmann::json glob_db_config = base_config;
242+
glob_db_config["path"] = args.db_in_mem ? ":mem:" : stringize("%s/%s.unqlite", args.db_write_dir.c_str(), glob_db_name.c_str());
235243

236-
admin.createDatabase(addr, 0, glob_db_name, args.db_type, glob_db_config);
244+
progressStream << "ProvDB Admin: creating global data database: " << glob_db_name << " " << glob_db_config.dump() << " " << args.db_type << std::endl;
245+
admin.createDatabase(addr, 0, glob_db_name, args.db_type, glob_db_config.dump());
237246

238247
progressStream << "ProvDB Admin: creating " << args.nshards << " database shards" << std::endl;
239248

240249
std::vector<std::string> db_shard_names(args.nshards);
241250
for(int s=0;s<args.nshards;s++){
242251
std::string db_name = stringize("provdb.%d",s);
243252

244-
std::string config = stringize("{ \"path\" : \"%s/%s.unqlite\" }", args.db_write_dir.c_str(), db_name.c_str());
245-
if(args.db_in_mem) config = "{ \"path\" : \":mem:\" }";
253+
nlohmann::json config = base_config;
254+
config["path"] = args.db_in_mem ? ":mem:" : stringize("%s/%s.unqlite", args.db_write_dir.c_str(), db_name.c_str());
246255

247-
progressStream << "ProvDB Admin: Shard " << s << ": " << db_name << " " << config << " " << args.db_type << std::endl;
248-
admin.createDatabase(addr, 0, db_name, args.db_type, config);
256+
progressStream << "ProvDB Admin: Shard " << s << ": " << db_name << " " << config.dump() << " " << args.db_type << std::endl;
257+
admin.createDatabase(addr, 0, db_name, args.db_type, config.dump());
249258
db_shard_names[s] = db_name;
250259
}
251260

0 commit comments

Comments
 (0)