コード例 #1
0
ファイル: KeyValueDBTestBase.cs プロジェクト: lanicon/BTDB
        public void OpeningDbWithLenientOpenWithMissingFirstTrlAndKviWarnsAndRecoversData()
        {
            using var fileCollection = new InMemoryFileCollection();
            var options = new KeyValueDBOptions
            {
                FileCollection = fileCollection, Compression = new NoCompressionStrategy(), FileSplitSize = 1024,
                LenientOpen    = true,
                Logger         = new LoggerMock()
            };

            Create2TrlFiles(options);
            fileCollection.GetFile(1) !.Remove();
            using var db = NewKeyValueDB(options);
            Assert.Equal("No valid Kvi and lowest Trl in chain is not first. Missing 1. LenientOpen is true, recovering data.", ((LoggerMock)options.Logger).LastWarning);
            using var tr = db.StartTransaction();
            Assert.Equal(1, tr.GetKeyValueCount());
            Assert.Equal(1u, fileCollection.GetCount());
        }
コード例 #2
0
ファイル: KeyValueDBTestBase.cs プロジェクト: lanicon/BTDB
        public void OpeningDbWithMissingFirstTrlAndKviWarnsAndOpenEmptyDb()
        {
            using var fileCollection = new InMemoryFileCollection();
            var options = new KeyValueDBOptions
            {
                FileCollection = fileCollection, Compression = new NoCompressionStrategy(), FileSplitSize = 1024,
                Logger         = new LoggerMock()
            };

            Create2TrlFiles(options);
            fileCollection.GetFile(1) !.Remove();
            using var db = NewKeyValueDB(options);
            Assert.Equal("No valid Kvi and lowest Trl in chain is not first. Missing 1", ((LoggerMock)options.Logger).LastWarning);
            using var tr = db.StartTransaction();
            Assert.Equal(0, tr.GetKeyValueCount());
            Assert.Equal(0u, fileCollection.GetCount());
            tr.CreateOrUpdateKeyValue(_key1, new byte[1024]);
            tr.Commit();
        }
コード例 #3
0
ファイル: KeyValueDBRollbackTest.cs プロジェクト: srsman/BTDB
        public void ComplexTrlRollbackWhenKviLost()
        {
            using (var fileCollection = new InMemoryFileCollection())
            {
                var options = new KeyValueDBOptions
                {
                    Compression                    = new SnappyCompressionStrategy(),
                    FileCollection                 = fileCollection,
                    FileSplitSize                  = 100 * 1024 * 1024,
                    OpenUpToCommitUlong            = null,
                    PreserveHistoryUpToCommitUlong = null,
                    CompactorScheduler             = CompactorScheduler.Instance,
                };

                using (var kvDb = new KeyValueDB(options))
                    using (var objDb = new ObjectDB())
                    {
                        objDb.Open(kvDb, false);

                        for (ulong i = 0; i < 100; i += 3)
                        {
                            using (var tr = objDb.StartWritingTransaction().Result)
                            {
                                var person = tr.Singleton <Person>();
                                person.Age = (uint)i;
                                tr.Store(person);
                                tr.SetCommitUlong(i);
                                tr.Commit();
                            }
                        }
                    }

                options = new KeyValueDBOptions
                {
                    Compression                    = new SnappyCompressionStrategy(),
                    FileCollection                 = fileCollection,
                    FileSplitSize                  = 100 * 1024 * 1024,
                    OpenUpToCommitUlong            = 9UL,
                    PreserveHistoryUpToCommitUlong = 9UL,
                    CompactorScheduler             = CompactorScheduler.Instance,
                };
                using (var kvDb = new KeyValueDB(options))
                    using (var objDb = new ObjectDB())
                    {
                        objDb.Open(kvDb, false);

                        using (var tr = objDb.StartReadOnlyTransaction())
                        {
                            Assert.Equal(9UL, tr.GetCommitUlong());
                        }
                    }

                // Delete KVI file
                fileCollection.GetFile(3).Remove();

                options = new KeyValueDBOptions
                {
                    Compression                    = new SnappyCompressionStrategy(),
                    FileCollection                 = fileCollection,
                    OpenUpToCommitUlong            = 9UL,
                    PreserveHistoryUpToCommitUlong = 9UL,
                    FileSplitSize                  = 100 * 1024 * 1024,
                    CompactorScheduler             = CompactorScheduler.Instance,
                };
                using (var kvDb = new KeyValueDB(options))
                    using (var objDb = new ObjectDB())
                    {
                        objDb.Open(kvDb, false);

                        using (var tr = objDb.StartReadOnlyTransaction())
                        {
                            Assert.Equal(9UL, tr.GetCommitUlong());
                        }
                        for (ulong i = 10; i < 200; i += 5)
                        {
                            using (var tr = objDb.StartWritingTransaction().Result)
                            {
                                var person = tr.Singleton <Person>();
                                person.Age = (uint)i;
                                tr.Store(person);
                                tr.SetCommitUlong(i);
                                tr.Commit();
                            }
                        }
                    }

                options = new KeyValueDBOptions
                {
                    Compression                    = new SnappyCompressionStrategy(),
                    FileCollection                 = fileCollection,
                    FileSplitSize                  = 100 * 1024 * 1024,
                    OpenUpToCommitUlong            = 50UL,
                    PreserveHistoryUpToCommitUlong = 50UL,
                    CompactorScheduler             = CompactorScheduler.Instance,
                };
                using (var kvDb = new KeyValueDB(options))
                    using (var objDb = new ObjectDB())
                    {
                        objDb.Open(kvDb, false);

                        using (var tr = objDb.StartReadOnlyTransaction())
                        {
                            Assert.Equal(50UL, tr.GetCommitUlong());
                        }
                    }
            }
        }