Skip to content

Commit 3457535

Browse files
committed
Added cmdline option to provdb_admin to use an in-memory unqlite database for testing
1 parent c1089ee commit 3457535

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

app/provdb_admin.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct ProvdbArgs{
130130
std::string db_type;
131131
unsigned long db_commit_freq;
132132
std::string db_write_dir;
133+
bool db_in_mem; //database is in-memory not written to disk, for testing
133134

134135
ProvdbArgs(): engine("ofi+tcp"), autoshutdown(true), nshards(1), db_type("unqlite"), nthreads(1), db_commit_freq(10000), db_write_dir("."){}
135136
};
@@ -157,6 +158,8 @@ int main(int argc, char** argv) {
157158
addOptionalCommandLineArg(parser, db_type, "Specify the Sonata database type (default \"unqlite\")");
158159
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.");
159160
addOptionalCommandLineArg(parser, db_write_dir, "Specify the directory in which the database shards will be written (default \".\")");
161+
addOptionalCommandLineArg(parser, db_in_mem, "Use an in-memory database rather than writing to disk (*unqlite backend only*) (default false)");
162+
160163

161164
if(argc-1 < parser.nMandatoryArgs() || (argc == 2 && std::string(argv[1]) == "-help")){
162165
parser.help(std::cout);
@@ -167,6 +170,9 @@ int main(int argc, char** argv) {
167170
parser.parseCmdLineArgs(args, argc, argv);
168171

169172
if(args.nshards < 1) throw std::runtime_error("Must have at least 1 database shard");
173+
if(args.db_in_mem && args.db_type != "unqlite") throw std::runtime_error("-db_in_mem option not valid for backends other than unqlite");
174+
175+
if(args.db_in_mem){ progressStream << "Using in-memory database" << std::endl; }
170176

171177
std::string eng_opt = args.engine;
172178
if(args.ip.size() > 0){
@@ -223,15 +229,21 @@ int main(int argc, char** argv) {
223229
sonata::Admin admin(engine);
224230
progressStream << "ProvDB Admin: creating global data database" << std::endl;
225231
std::string glob_db_name = "provdb.global";
232+
226233
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:\" }";
235+
227236
admin.createDatabase(addr, 0, glob_db_name, args.db_type, glob_db_config);
228237

229238
progressStream << "ProvDB Admin: creating " << args.nshards << " database shards" << std::endl;
230239

231240
std::vector<std::string> db_shard_names(args.nshards);
232241
for(int s=0;s<args.nshards;s++){
233242
std::string db_name = stringize("provdb.%d",s);
243+
234244
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:\" }";
246+
235247
progressStream << "ProvDB Admin: Shard " << s << ": " << db_name << " " << config << " " << args.db_type << std::endl;
236248
admin.createDatabase(addr, 0, db_name, args.db_type, config);
237249
db_shard_names[s] = db_name;

0 commit comments

Comments
 (0)