コード例 #1
0
ファイル: PlaneDBTests.cs プロジェクト: nmaier/PlaneDB
        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);
            }
        }
コード例 #2
0
ファイル: Compact.cs プロジェクト: nmaier/PlaneDB
        private static void CompactOne(DirectoryInfo db, PlaneDBOptions popts)
        {
            var id = $"{db.FullName}:{popts.TableSpace}";

            try {
                Options.Write($"{id} - Opening");
                using var plane           = new PlaneDB(db, FileMode.Open, popts);
                plane.OnFlushMemoryTable += (_, __) => Options.Error($"{id} - Flushed memory table");
                plane.OnMergedTables     += (_, __) => Options.Error($"{id} - Merged tables");
                Options.Write($"{id} - Starting compaction");
                plane.Compact();
                Options.Write($"{id} - Finished compaction");
            }
            catch (BadMagicException ex) {
                Options.Error($"{id} - {ex.Message}");
            }
            catch (AlreadyLockedException ex) {
                Options.Error($"{id} - {ex.Message}");
            }
        }