public void TestBasicIterators() { var di = new DirectoryInfo("testdb"); using (var db = new PlaneDB(di, FileMode.CreateNew, planeDBOptions.DisableJournal())) { var value = new byte[100]; for (var i = 0; i < 10000; ++i) { Assert.IsTrue(db.TryAdd(BitConverter.GetBytes(i), value)); } } using (var db = new PlaneDB(di, FileMode.Open, planeDBOptions.DisableJournal())) { db.Compact(); // XXX Verify table count and sequence are correct } int read; using (var db = new PlaneDB(di, FileMode.Open, planeDBOptions.DisableJournal())) { Assert.AreEqual(db.Count, 10000); Assert.IsTrue(db.TryRemove(BitConverter.GetBytes(1000), out _)); Assert.AreEqual(db.Count, 9999); Assert.IsFalse(db.TryRemove(BitConverter.GetBytes(1000), out _)); read = db.Select((e, i) => new KeyValuePair <byte[], int>(e.Key, i)).Count(); Assert.AreEqual(db.Count, read); } using (var db = new PlaneDB(di, FileMode.Open, planeDBOptions.DisableJournal())) { Assert.AreEqual(db.Count, 9999); Assert.IsFalse(db.TryRemove(BitConverter.GetBytes(1000), out _)); Assert.AreEqual(db.Count, 9999); read = db.KeysIterator.Select((e, i) => new KeyValuePair <byte[], int>(e, i)).Count(); Assert.AreEqual(db.Count, read); } using (var db = new PlaneDB(di, FileMode.Open, planeDBOptions.DisableJournal())) { Assert.AreEqual(db.Count, 9999); Assert.IsFalse(db.TryRemove(BitConverter.GetBytes(1000), out _)); Assert.AreEqual(db.Count, 9999); read = db.Keys.Select((e, i) => new KeyValuePair <byte[], int>(e, i)).Count(); Assert.AreEqual(db.Count, read); } using (var db = new PlaneDB(di, FileMode.Open, planeDBOptions.DisableJournal())) { Assert.AreEqual(db.Count, read); db.Clear(); Assert.AreEqual(db.Count, 0); } using (var db = new PlaneDB(di, FileMode.Open, planeDBOptions.DisableJournal())) { Assert.AreEqual(db.Count, 0); } }
public override void Execute() { var popts = new PlaneDBOptions().DisableJournal(); if (!string.IsNullOrEmpty(Owner.Passphrase)) { popts = popts.EnableEncryption(Owner.Passphrase); } else if (Owner.Compressed) { popts = popts.EnableCompression(); } if (!string.IsNullOrEmpty(Owner.Tablespace)) { popts = popts.UsingTableSpace(Owner.Tablespace); } if (From == null) { throw new GetOptException("No from"); } if (To == null) { throw new GetOptException("No to"); } using var rocks = RocksDb.OpenReadOnly(new DbOptions(), From.FullName, false); using var plane = new PlaneDB(To, FileMode.OpenOrCreate, popts); plane.OnFlushMemoryTable += (_, __) => Console.WriteLine("Flushed memory table"); plane.OnMergedTables += (_, __) => Console.WriteLine("Merged tables"); plane.Clear(); var iter = rocks.NewIterator(); plane.MassInsert(() => CopyFromRocks(plane, iter)); Console.WriteLine($"{copyCount:N0} entries copied in total"); }
public void TestLargeish() { var di = new DirectoryInfo("testdb"); var value = new byte[4096]; value[0] = 1; value[4095] = 0xff; using (var db = new PlaneDB(di, FileMode.CreateNew, planeDBOptions)) { for (var i = 0; i < 10000; ++i) { Assert.IsTrue(db.TryAdd(BitConverter.GetBytes(i), value)); } } using (var db = new PlaneDB(di, FileMode.Open, planeDBOptions)) { for (var i = 0; i < 10000; ++i) { Assert.IsTrue(db.TryGetValue(BitConverter.GetBytes(i), out var val)); Assert.IsTrue(value.AsSpan().SequenceEqual(val)); } } using (var db = new PlaneDB(di, FileMode.Open, planeDBOptions)) { Assert.AreEqual(db.Count, 10000); Assert.IsTrue(db.TryRemove(BitConverter.GetBytes(1000), out _)); Assert.AreEqual(db.Count, 9999); Assert.IsFalse(db.TryRemove(BitConverter.GetBytes(1000), out _)); var read = db.Select((e, i) => new KeyValuePair <byte[], int>(e.Key, i)).Count(); Assert.AreEqual(db.Count, read); db.Clear(); Assert.AreEqual(db.Count, 0); } using (var db = new PlaneDB(di, FileMode.Open, planeDBOptions)) { Assert.AreEqual(db.Count, 0); } }