Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using FASTER.core;
- namespace Marius.Fug
- {
- public struct FugObject
- {
- public string Value;
- }
- public class FugSerializer : BinaryObjectSerializer<FugObject>
- {
- public override void Deserialize(ref FugObject obj)
- {
- obj.Value = reader.ReadString();
- }
- public override void Serialize(ref FugObject obj)
- {
- writer.Write(obj.Value);
- }
- }
- public class FugFunctions : IFunctions<FugObject, FugObject, string, string, Empty>
- {
- public void SingleReader(ref FugObject key, ref string input, ref FugObject value, ref string dst)
- {
- dst = value.Value;
- }
- public void ConcurrentReader(ref FugObject key, ref string input, ref FugObject value, ref string dst)
- {
- dst = value.Value;
- }
- public void SingleWriter(ref FugObject key, ref FugObject src, ref FugObject dst)
- {
- dst.Value = src.Value;
- }
- public void ConcurrentWriter(ref FugObject key, ref FugObject src, ref FugObject dst)
- {
- dst.Value = src.Value;
- }
- public void CheckpointCompletionCallback(Guid sessionId, long serialNum)
- {
- }
- public void CopyUpdater(ref FugObject key, ref string input, ref FugObject oldValue, ref FugObject newValue)
- {
- }
- public void DeleteCompletionCallback(ref FugObject key, Empty ctx)
- {
- }
- public void InitialUpdater(ref FugObject key, ref string input, ref FugObject value)
- {
- }
- public void InPlaceUpdater(ref FugObject key, ref string input, ref FugObject value)
- {
- }
- public void ReadCompletionCallback(ref FugObject key, ref string input, ref string output, Empty ctx, Status status)
- {
- }
- public void RMWCompletionCallback(ref FugObject key, ref string input, Empty ctx, Status status)
- {
- }
- public void UpsertCompletionCallback(ref FugObject key, ref FugObject value, Empty ctx)
- {
- }
- }
- public class FugEqualityComparer : IFasterEqualityComparer<FugObject>
- {
- public bool Equals(ref FugObject k1, ref FugObject k2)
- {
- if (k1.Value == null && k2.Value == null)
- return true;
- if (k1.Value == null || k2.Value == null)
- return false;
- return StringComparer.Ordinal.Compare(k1.Value, k2.Value) == 0;
- }
- public long GetHashCode64(ref FugObject k)
- {
- var hashCode = StringComparer.Ordinal.GetHashCode(k.Value);
- return Utility.GetHashCode(hashCode);
- }
- }
- public class Program
- {
- public static void Main(string[] args)
- {
- var mainLogPath = Path.Combine(Directory.GetCurrentDirectory(), @"logs\main.hlog");
- var objectLogPath = Path.Combine(Directory.GetCurrentDirectory(), @"logs\object.hlog");
- var checkpointPath = Path.Combine(Directory.GetCurrentDirectory(), @"logs");
- var mainLog = Devices.CreateLogDevice(mainLogPath);
- var objectLog = Devices.CreateLogDevice(objectLogPath);
- var faster = new FasterKV<FugObject, FugObject, string, string, Empty, FugFunctions>(
- 1 << 21,
- new FugFunctions(),
- new LogSettings() { LogDevice = mainLog, ObjectLogDevice = objectLog },
- new CheckpointSettings() { CheckpointDir = checkpointPath, CheckPointType = CheckpointType.Snapshot },
- new SerializerSettings<FugObject, FugObject>() { keySerializer = () => new FugSerializer(), valueSerializer = () => new FugSerializer() },
- new FugEqualityComparer(),
- null);
- faster.StartSession();
- var valueString = "3.14159265359";
- var sequence = 0L;
- for (var i = 0; i < 4000000; i++)
- {
- var key = new FugObject() { Value = i.ToString() };
- var value = new FugObject() { Value = valueString };
- faster.Upsert(ref key, ref value, Empty.Default, sequence);
- sequence++;
- }
- faster.TakeFullCheckpoint(out var _);
- faster.CompleteCheckpoint(true); // <- exception here
- faster.StopSession();
- faster.Dispose();
- objectLog.Close();
- mainLog.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement