public void TestManifestSnapshot() { var path = Path.GetFullPath("TestData\\TestManifestSnapshot"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // Remove the file if it exists var filename = Config.ManifestFile(path); if (File.Exists(filename)) { File.Delete(filename); } var mf = new Manifest(path); // Add pages and dummy files to represent their contents mf.AddPage(1, 5, Key.FromBytes(new byte[] { 5 }), Key.FromBytes(new byte[] { 5, 1 })); using (var file = new StreamWriter(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 5))) { file.Write("Test"); } mf.AddPage(1, 6, Key.FromBytes(new byte[] { 6 }), Key.FromBytes(new byte[] { 6, 1 })); using (var file = new StreamWriter(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 6))) { file.Write("Test"); } mf.AddPage(1, 4, Key.FromBytes(new byte[] { 4 }), Key.FromBytes(new byte[] { 4, 1 })); using (var file = new StreamWriter(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 4))) { file.Write("Test"); } using (var manifestSnapshot = mf.GetLatestManifest()) { mf.ModifyPages(new List <PageRecord> { new PageRecord(1, 8, Key.FromBytes(new byte[] { 16 }), Key.FromBytes(new byte[] { 16, 1 })), new PageRecord(1, 9, Key.FromBytes(new byte[] { 1 }), Key.FromBytes(new byte[] { 1, 1 })), new PageRecord(1, 16, Key.FromBytes(new byte[] { 10 }), Key.FromBytes(new byte[] { 10, 1 })) }, new List <PageRef> { new PageRef { Level = 1, Version = 6 }, new PageRef { Level = 1, Version = 4 }, }); PageRecord[] pg = manifestSnapshot.GetPagesAtLevel(1); Assert.AreEqual(1, pg[0].Level); Assert.AreEqual(4, pg[0].Version); Assert.AreEqual(1, pg[1].Level); Assert.AreEqual(5, pg[1].Version); Assert.AreEqual(1, pg[2].Level); Assert.AreEqual(6, pg[2].Version); // The files should still exist for now Assert.IsTrue(File.Exists(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 4))); Assert.IsTrue(File.Exists(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 5))); Assert.IsTrue(File.Exists(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 6))); } // The files should be deleted now since we closed the snapshot Assert.IsFalse(File.Exists(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 4))); Assert.IsTrue(File.Exists(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 5))); Assert.IsFalse(File.Exists(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 6))); }
public void CreateManifestFile() { var path = Path.GetFullPath("TestData\\ManifestFileV1"); if (!Directory.Exists(path)) Directory.CreateDirectory(path); // Remove the file if it exists var filename = Config.ManifestFile(path); if (File.Exists(filename)) File.Delete(filename); var mf = new Manifest(path); mf.AddPage(1, 5, new KeyEx(new byte[] { 5 }, 5), new KeyEx(new byte[] { 5, 1 }, 5)); mf.AddPage(1, 6, new KeyEx(new byte[] { 6 }, 6), new KeyEx(new byte[] { 6, 1 }, 6)); mf.AddPage(1, 4, new KeyEx(new byte[] { 4 }, 4), new KeyEx(new byte[] { 4, 1 }, 4)); using (var mfSnap = mf.GetLatestManifest()) { PageRecord[] pg = mfSnap.GetPagesAtLevel(1); Assert.AreEqual(1, pg[0].Level); Assert.AreEqual(4, pg[0].Version); Assert.AreEqual(1, pg[1].Level); Assert.AreEqual(5, pg[1].Version); Assert.AreEqual(1, pg[2].Level); Assert.AreEqual(6, pg[2].Version); } mf = new Manifest(path); mf.ModifyPages(new List<PageRecord>{ new PageRecord(1, 8, new KeyEx( new byte[] { 16 }, 16), new KeyEx(new byte[] { 16, 1 }, 16) ), new PageRecord(1, 9, new KeyEx( new byte[] { 1 }, 1), new KeyEx(new byte[] { 1, 1 }, 1) ), new PageRecord(1, 16, new KeyEx( new byte[] { 10 }, 10), new KeyEx(new byte[] { 10, 1 }, 10) ) }, new List<PageRef>{ new PageRef{ Level = 1, Version = 6}, new PageRef{ Level = 1, Version = 4}, }); mf = new Manifest(path); using (var mfSnap = mf.GetLatestManifest()) { var pg = mfSnap.GetPagesAtLevel(1); Assert.AreEqual(1, pg[0].Level); Assert.AreEqual(9, pg[0].Version); Assert.AreEqual(1, pg[1].Level); Assert.AreEqual(5, pg[1].Version); Assert.AreEqual(1, pg[2].Level); Assert.AreEqual(16, pg[2].Version); Assert.AreEqual(1, pg[3].Level); Assert.AreEqual(8, pg[3].Version); } }
public void WriteToSortedBlockTable(Manifest manifest) { // Closes journal file, we don't need it anymore. _journal.Close (); // Writes out the contents of the memtable to the level-0 sbt log. _memTable.WriteToSortedBlockTable (_baseFileName, 0, _version); // Commit the new pages to the manifest. manifest.AddPage (0, _version, FirstKey, LastKey); // Removes the journal file. _journal.Delete (); }
public void ManifestAddPages() { var path = Path.GetFullPath("TestData\\ManifestAddPages"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // Remove the file if it exists var filename = Config.ManifestFile(path); if (File.Exists(filename)) { File.Delete(filename); } var mf = new Manifest(path); mf.AddPage(1, 5, Key.FromBytes(new byte[] { 5 }), Key.FromBytes(new byte[] { 5, 1 })); mf.AddPage(1, 6, Key.FromBytes(new byte[] { 6 }), Key.FromBytes(new byte[] { 6, 1 })); mf.AddPage(1, 4, Key.FromBytes(new byte[] { 4 }), Key.FromBytes(new byte[] { 4, 1 })); using (var mfSnap = mf.GetLatestManifest()) { PageRecord[] pg = mfSnap.GetPagesAtLevel(1); Assert.AreEqual(1, pg[0].Level); Assert.AreEqual(4, pg[0].Version); Assert.AreEqual(1, pg[1].Level); Assert.AreEqual(5, pg[1].Version); Assert.AreEqual(1, pg[2].Level); Assert.AreEqual(6, pg[2].Version); } mf = new Manifest(path); mf.ModifyPages(new List <PageRecord> { new PageRecord(1, 8, Key.FromBytes(new byte[] { 16 }), Key.FromBytes(new byte[] { 16, 1 })), new PageRecord(1, 9, Key.FromBytes(new byte[] { 1 }), Key.FromBytes(new byte[] { 1, 1 })), new PageRecord(1, 16, Key.FromBytes(new byte[] { 10 }), Key.FromBytes(new byte[] { 10, 1 })) }, new List <PageRef> { new PageRef { Level = 1, Version = 6 }, new PageRef { Level = 1, Version = 4 }, }); mf = new Manifest(path); using (var mfSnap = mf.GetLatestManifest()) { var pg = mfSnap.GetPagesAtLevel(1); Assert.AreEqual(1, pg[0].Level); Assert.AreEqual(9, pg[0].Version); Assert.AreEqual(1, pg[1].Level); Assert.AreEqual(5, pg[1].Version); Assert.AreEqual(1, pg[2].Level); Assert.AreEqual(16, pg[2].Version); Assert.AreEqual(1, pg[3].Level); Assert.AreEqual(8, pg[3].Version); } }
public void TestManifestSnapshot() { var path = Path.GetFullPath ("TestData\\TestManifestSnapshot"); if (!Directory.Exists (path)) Directory.CreateDirectory (path); // Remove the file if it exists var filename = Config.ManifestFile (path); if (File.Exists (filename)) File.Delete (filename); var mf = new Manifest (path); // Add pages and dummy files to represent their contents mf.AddPage (1, 5, Key.FromBytes (new byte[] { 5 }), Key.FromBytes (new byte[] { 5, 1 })); using (var file = new StreamWriter(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 5))) file.Write ("Test"); mf.AddPage (1, 6, Key.FromBytes (new byte[] { 6 }), Key.FromBytes (new byte[] { 6, 1 })); using (var file = new StreamWriter(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 6))) file.Write ("Test"); mf.AddPage (1, 4, Key.FromBytes (new byte[] { 4 }), Key.FromBytes (new byte[] { 4, 1 })); using (var file = new StreamWriter(Config.SortedBlockTableFile("TestData\\TestManifestSnapshot", 1, 4))) file.Write ("Test"); using (var manifestSnapshot = mf.GetLatestManifest()) { mf.ModifyPages (new List<PageRecord> { new PageRecord(1, 8, Key.FromBytes( new byte[] { 16 }), Key.FromBytes(new byte[] { 16, 1 }) ), new PageRecord(1, 9, Key.FromBytes( new byte[] { 1 }), Key.FromBytes(new byte[] { 1, 1 }) ), new PageRecord(1, 16, Key.FromBytes( new byte[] { 10 }), Key.FromBytes(new byte[] { 10, 1 }) ) }, new List<PageRef> { new PageRef{ Level = 1, Version = 6}, new PageRef{ Level = 1, Version = 4}, }); PageRecord[] pg = manifestSnapshot.GetPagesAtLevel (1); Assert.AreEqual (1, pg [0].Level); Assert.AreEqual (4, pg [0].Version); Assert.AreEqual (1, pg [1].Level); Assert.AreEqual (5, pg [1].Version); Assert.AreEqual (1, pg [2].Level); Assert.AreEqual (6, pg [2].Version); // The files should still exist for now Assert.IsTrue (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 4))); Assert.IsTrue (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 5))); Assert.IsTrue (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 6))); } // The files should be deleted now since we closed the snapshot Assert.IsFalse (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 4))); Assert.IsTrue (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 5))); Assert.IsFalse (File.Exists (Config.SortedBlockTableFile ("TestData\\TestManifestSnapshot", 1, 6))); }