static ObjectDB CreateDb(IFileCollection fc) { var lowDb = new KeyValueDB(fc); var db = new ObjectDB(); db.Open(lowDb, true); return db; }
static ObjectDB CreateInMemoryDb() { var lowDb = new InMemoryKeyValueDB(); var db = new ObjectDB(); db.Open(lowDb, true); return db; }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Need to have just one parameter with directory of ObjectDB"); return; } using (var dfc = new OnDiskFileCollection(args[0])) using (var kdb = new KeyValueDB(dfc)) using (var odb = new ObjectDB()) { odb.Open(kdb, false); using (var tr = odb.StartTransaction()) { var visitor = new ToStringVisitor(); var iterator = new ODBIterator(tr, visitor); iterator.Iterate(); var text = visitor.ToString(); Console.WriteLine(text); } } }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Need to have just one parameter with directory of ObjectDB"); return; } var action = "dump"; if (args.Length > 1) { action = args[1].ToLowerInvariant(); } switch (action) { case "dump": { using (var dfc = new OnDiskFileCollection(args[0])) using (var kdb = new KeyValueDB(dfc)) using (var odb = new ObjectDB()) { odb.Open(kdb, false); using (var tr = odb.StartTransaction()) { var visitor = new ToStringVisitor(); var iterator = new ODBIterator(tr, visitor); iterator.Iterate(); var text = visitor.ToString(); Console.WriteLine(text); } } break; } case "stat": { using (var dfc = new OnDiskFileCollection(args[0])) using (var kdb = new KeyValueDB(dfc)) { Console.WriteLine(kdb.CalcStats()); } break; } case "compact": { using (var dfc = new OnDiskFileCollection(args[0])) using (var kdb = new KeyValueDB(dfc, new SnappyCompressionStrategy(), 100 * 1024 * 1024, null)) { Console.WriteLine("Starting first compaction"); while (kdb.Compact(new CancellationToken())) { Console.WriteLine(kdb.CalcStats()); Console.WriteLine("Another compaction needed"); } Console.WriteLine(kdb.CalcStats()); } break; } case "export": { using (var dfc = new OnDiskFileCollection(args[0])) using (var kdb = new KeyValueDB(dfc)) using (var tr = kdb.StartReadOnlyTransaction()) using (var st = File.Create(Path.Combine(args[0], "export.dat"))) { KeyValueDBExportImporter.Export(tr, st); } break; } default: { Console.WriteLine($"Unknown action: {action}"); break; } } }