static void Main(string[] args) { var log = Devices.CreateLogDevice(Path.GetTempPath() + "hybridlog"); var objlog = Devices.CreateObjectLogDevice(Path.GetTempPath() + "hybridlog"); var h = new FasterKV <MyKey, MyValue, MyInput, MyOutput, MyContext, MyFunctions> (128, new MyFunctions(), new LogSettings { LogDevice = log, ObjectLogDevice = objlog, MemorySizeBits = 29 }, null, new SerializerSettings <MyKey, MyValue> { keySerializer = () => new MyKeySerializer(), valueSerializer = () => new MyValueSerializer() } ); var context = default(MyContext); h.StartSession(); for (int i = 0; i < 20000; i++) { var _key = new MyKey { key = i }; var value = new MyValue { value = i }; h.Upsert(ref _key, ref value, context, 0); if (i % 32 == 0) { h.Refresh(); } } var key = new MyKey { key = 23 }; var input = default(MyInput); MyOutput g1 = new MyOutput(); h.Read(ref key, ref input, ref g1, context, 0); h.CompletePending(true); MyOutput g2 = new MyOutput(); key = new MyKey { key = 46 }; h.Read(ref key, ref input, ref g2, context, 0); h.CompletePending(true); Console.WriteLine("Success!"); Console.ReadLine(); }
static void Main(string[] args) { // This sample uses class key and value types, which are not blittable (i.e., they // require a pointer to heap objects). Such datatypes include variable length types // such as strings. You can override the default key equality comparer in two ways; // (1) Make Key implement IFasterEqualityComparer<Key> interface // (2) Provide IFasterEqualityComparer<Key> instance as param to constructor // FASTER stores the actual objects in a separate object log. // Note that serializers are required for class types, see below. var log = Devices.CreateLogDevice(Path.GetTempPath() + "hlog.log"); var objlog = Devices.CreateLogDevice(Path.GetTempPath() + "hlog.obj.log"); var h = new FasterKV <MyKey, MyValue, MyInput, MyOutput, MyContext, MyFunctions> (1L << 20, new MyFunctions(), new LogSettings { LogDevice = log, ObjectLogDevice = objlog, MemorySizeBits = 29 }, null, new SerializerSettings <MyKey, MyValue> { keySerializer = () => new MyKeySerializer(), valueSerializer = () => new MyValueSerializer() } ); var context = default(MyContext); // Each thread calls StartSession to register itself with FASTER h.StartSession(); for (int i = 0; i < 20000; i++) { var _key = new MyKey { key = i }; var value = new MyValue { value = i }; h.Upsert(ref _key, ref value, context, 0); // Each thread calls Refresh periodically for thread coordination if (i % 1024 == 0) { h.Refresh(); } } var key = new MyKey { key = 23 }; var input = default(MyInput); MyOutput g1 = new MyOutput(); var status = h.Read(ref key, ref input, ref g1, context, 0); if (status == Status.OK && g1.value.value == key.key) { Console.WriteLine("Success!"); } else { Console.WriteLine("Error!"); } MyOutput g2 = new MyOutput(); key = new MyKey { key = 46 }; status = h.Read(ref key, ref input, ref g2, context, 0); if (status == Status.OK && g2.value.value == key.key) { Console.WriteLine("Success!"); } else { Console.WriteLine("Error!"); } /// Delete key, read to verify deletion var output = new MyOutput(); h.Delete(ref key, context, 0); status = h.Read(ref key, ref input, ref output, context, 0); if (status == Status.NOTFOUND) { Console.WriteLine("Success!"); } else { Console.WriteLine("Error!"); } // Each thread ends session when done h.StopSession(); // Dispose FASTER instance and log h.Dispose(); log.Close(); objlog.Close(); Console.WriteLine("Press <ENTER> to end"); Console.ReadLine(); }