public void TestCommitRollback() { using (BPlusTree <int, string> tree = Create(Options)) { tree.EnableCount(); Assert.AreEqual(0, tree.Count); tree.Rollback(); Assert.AreEqual(0, tree.Count); tree.Commit(); Assert.AreEqual(0, tree.Count); tree.Add(1, "A"); tree.Rollback(); Assert.AreEqual(0, tree.Count); tree.Commit(); Assert.AreEqual(0, tree.Count); tree.Add(1, "A"); tree.Commit(); Assert.AreEqual(1, tree.Count); tree.Rollback(); Assert.AreEqual(1, tree.Count); tree.Add(2, "B"); tree.Rollback(); Assert.AreEqual(1, tree.Count); tree[1] = "abc"; tree.Commit(); Assert.AreEqual(1, tree.Count); tree.Rollback(); Assert.AreEqual("abc", tree[1]); Assert.IsFalse(tree.ContainsKey(2)); } }
public void TestAutoCommit() { var options = (BPlusTree <int, string> .OptionsV2)Options; options.TransactionLogLimit = 30; using (BPlusTree <int, string> tree = Create(options)) { tree.EnableCount(); Assert.AreEqual(0, tree.Count); tree.Add(1, "A"); tree.Rollback(); Assert.AreEqual(0, tree.Count); tree.Add(1, "A"); tree.Add(2, "B"); //The second write exceeds 30 bytes and auto-commits tree.Rollback(); Assert.AreEqual(2, tree.Count); tree.Add(3, "C"); tree.Add(4, "D"); //The second write will commit, but not the last tree.Add(5, "E"); tree.Rollback(); Assert.AreEqual(4, tree.Count); Assert.IsFalse(tree.ContainsKey(5)); } }
public void Rollback(ITransaction transaction) { try { _tree.Rollback(); appliedOps.Clear(); } catch (Exception ex) { if (LoggerManager.Instance.IndexLogger != null) { LoggerManager.Instance.IndexLogger.Error("BPlusIndex", "Error Code: " + ErrorCodes.Indexes.TREE_ROLLBACK_FAILURE + " - " + ex.ToString()); throw new IndexException(ErrorCodes.Indexes.TREE_ROLLBACK_FAILURE); } } }
public void TestRestoreLargeLog() { using (TempFile savelog = new TempFile()) using (TempFile temp = new TempFile()) { var options = GetOptions(temp); options.FileBlockSize = 512; options.StoragePerformance = StoragePerformance.Fastest; options.CalcBTreeOrder(Marshal.SizeOf(typeof(Guid)), Marshal.SizeOf(typeof(TestInfo))); options.TransactionLog = new TransactionLog <Guid, TestInfo>( new TransactionLogOptions <Guid, TestInfo>( options.TransactionLogFileName, options.KeySerializer, options.ValueSerializer ) ); //Now recover... Dictionary <Guid, TestInfo> first = new Dictionary <Guid, TestInfo>(); Dictionary <Guid, TestInfo> sample; using (var tree = new BPlusTree <Guid, TestInfo>(options)) { tree.EnableCount(); Insert(tree, first, 1, 100, TimeSpan.FromMinutes(1)); tree.Commit(); Assert.AreEqual(100, tree.Count); sample = new Dictionary <Guid, TestInfo>(first); Insert(tree, sample, 7, 5000, TimeSpan.FromMinutes(1)); Assert.AreEqual(35100, tree.Count); for (int i = 0; i < 1; i++) { foreach (var rec in tree) { var value = rec.Value; value.UpdateCount++; value.ReadCount++; tree[rec.Key] = value; } } File.Copy(options.TransactionLog.FileName, savelog.TempPath, true); tree.Rollback(); TestInfo.AssertEquals(first, tree); } //file still has initial committed data TestInfo.AssertEquals(first, BPlusTree <Guid, TestInfo> .EnumerateFile(options)); //restore the log and verify all data. File.Copy(savelog.TempPath, options.TransactionLog.FileName, true); using (var tree = new BPlusTree <Guid, TestInfo>(options)) { TestInfo.AssertEquals(sample, tree); } //file still has initial committed data TestInfo.AssertEquals(sample, BPlusTree <Guid, TestInfo> .EnumerateFile(options)); } }
public void TestRestoreLargeLog() { using (TempFile savelog = new TempFile()) using (TempFile temp = new TempFile()) { var options = GetOptions(temp); options.FileBlockSize = 512; options.StoragePerformance = StoragePerformance.Fastest; options.CalcBTreeOrder(Marshal.SizeOf(typeof(Guid)), Marshal.SizeOf(typeof(TestInfo))); options.TransactionLog = new TransactionLog<Guid, TestInfo>( new TransactionLogOptions<Guid, TestInfo>( options.TransactionLogFileName, options.KeySerializer, options.ValueSerializer ) ); //Now recover... Dictionary<Guid, TestInfo> first = new Dictionary<Guid, TestInfo>(); Dictionary<Guid, TestInfo> sample; using (var tree = new BPlusTree<Guid, TestInfo>(options)) { tree.EnableCount(); Insert(tree, first, 1, 100, TimeSpan.FromMinutes(1)); tree.Commit(); Assert.AreEqual(100, tree.Count); sample = new Dictionary<Guid, TestInfo>(first); Insert(tree, sample, 7, 5000, TimeSpan.FromMinutes(1)); Assert.AreEqual(35100, tree.Count); for (int i = 0; i < 1; i++) { foreach (var rec in tree) { var value = rec.Value; value.UpdateCount++; value.ReadCount++; tree[rec.Key] = value; } } File.Copy(options.TransactionLog.FileName, savelog.TempPath, true); tree.Rollback(); TestInfo.AssertEquals(first, tree); } //file still has initial committed data TestInfo.AssertEquals(first, BPlusTree<Guid, TestInfo>.EnumerateFile(options)); //restore the log and verify all data. File.Copy(savelog.TempPath, options.TransactionLog.FileName, true); using (var tree = new BPlusTree<Guid, TestInfo>(options)) { TestInfo.AssertEquals(sample, tree); } //file still has initial committed data TestInfo.AssertEquals(sample, BPlusTree<Guid, TestInfo>.EnumerateFile(options)); } }