public void RemoveUpdatedValuesFromIndex2() { string path = Path.GetFullPath ("TestData\\RemoveUpdatedValuesFromIndex2"); var timer = new Stopwatch (); using (var db = new KeyValueStore(path)) { db.Truncate (); int totalSize = 0; db.Manifest.Logger = msg => Console.WriteLine (msg); var indexed = new SortedDictionary<string, byte[]> (); int num_items = 1000; timer.Start (); for (int i = 0; i < num_items; i++) { indexed ["Mod"] = BitConverter.GetBytes (i % 100); db.Set (BitConverter.GetBytes (i), BitConverter.GetBytes (i), indexed); totalSize += 8 + 4; } timer.Stop (); Console.WriteLine ("Wrote data (with indexing) at a throughput of {0} MB/s", (double)totalSize / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0)); timer.Reset (); timer.Start (); var ctModZeros = db.Find ("Mod", BitConverter.GetBytes ((int)0)).Count (); timer.Stop (); Assert.AreEqual (10, ctModZeros); Console.WriteLine ("Scanned index at a throughput of {0} items/s", (double)ctModZeros / timer.Elapsed.TotalSeconds); } // Open the index directly and see if the data is there using (var db = new KeyValueStore(Path.Combine(path, "Mod"))) { int num_vals = db.EnumerateFromKey (BitConverter.GetBytes ((int)0)).Count (pair => pair.Key.Take (4).All (b => b == 0)); Assert.AreEqual (10, num_vals); } // Re-open the main key-value store and update the value at 30 using (var db = new KeyValueStore(path)) { var indexed = new SortedDictionary<string, byte[]> (); indexed ["Mod"] = BitConverter.GetBytes (201 % 100); db.Set (BitConverter.GetBytes (200), BitConverter.GetBytes (200), indexed); // Clean the data from the index db.RemoveFromIndex (BitConverter.GetBytes (200), new Dictionary<string, byte[]> { { "Mod", BitConverter.GetBytes(200 % 100) } }); } // Open the index again directly and confirm that the lookup key is gone now as well using (var db = new KeyValueStore(Path.Combine(path, "Mod"))) { int num_vals = db.EnumerateFromKey (BitConverter.GetBytes ((int)0)).Count (pair => pair.Key.Take (4).All (b => b == 0)); Assert.AreEqual (9, num_vals); } }
public void LookupOldDataFromIndex() { string path = Path.GetFullPath ("TestData\\LookupOldDataFromIndex"); using (var db = new KeyValueStore(path)) { db.Truncate (); db.Manifest.Logger = msg => Console.WriteLine (msg); db.Set (Encoding.UTF8.GetBytes ("KeyA"), Encoding.UTF8.GetBytes ("ValueA:1"), new Dictionary<string, byte[]> { { "Idx", Encoding.UTF8.GetBytes("1") } }); db.Set (Encoding.UTF8.GetBytes ("KeyB"), Encoding.UTF8.GetBytes ("ValueB:2"), new Dictionary<string, byte[]> { { "Idx", Encoding.UTF8.GetBytes("2") } }); db.Set (Encoding.UTF8.GetBytes ("KeyC"), Encoding.UTF8.GetBytes ("ValueC:3"), new Dictionary<string, byte[]> { { "Idx", Encoding.UTF8.GetBytes("3") } }); var lookupValue = db.Find ("Idx", Encoding.UTF8.GetBytes ("3")).Single (); Assert.AreEqual ("ValueC:3", Encoding.UTF8.GetString (lookupValue.Value)); Assert.AreEqual ("KeyC", Encoding.UTF8.GetString (lookupValue.Key)); db.Set (Encoding.UTF8.GetBytes ("KeyC"), Encoding.UTF8.GetBytes ("ValueC:4"), new Dictionary<string, byte[]> { { "Idx", Encoding.UTF8.GetBytes("4") } }); lookupValue = db.Find ("Idx", Encoding.UTF8.GetBytes ("4")).Single (); Assert.AreEqual ("ValueC:4", Encoding.UTF8.GetString (lookupValue.Value)); Assert.AreEqual ("KeyC", Encoding.UTF8.GetString (lookupValue.Key)); Assert.True (db.Find ("Idx", Encoding.UTF8.GetBytes ("3")).Any ()); db.RemoveFromIndex (Encoding.UTF8.GetBytes ("KeyC"), new Dictionary<string, byte[]> { { "Idx", Encoding.UTF8.GetBytes("3") } }); Assert.False (db.Find ("Idx", Encoding.UTF8.GetBytes ("3")).Any ()); } }