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 long Value;
- }
- public class FugFunctions : IFunctions<FugObject, FugObject, long, long, Empty>
- {
- public void SingleReader(ref FugObject key, ref long input, ref FugObject value, ref long dst)
- {
- dst = value.Value;
- }
- public void ConcurrentReader(ref FugObject key, ref long input, ref FugObject value, ref long 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 long input, ref FugObject oldValue, ref FugObject newValue)
- {
- }
- public void DeleteCompletionCallback(ref FugObject key, Empty ctx)
- {
- }
- public void InitialUpdater(ref FugObject key, ref long input, ref FugObject value)
- {
- }
- public void InPlaceUpdater(ref FugObject key, ref long input, ref FugObject value)
- {
- }
- public void ReadCompletionCallback(ref FugObject key, ref long input, ref long output, Empty ctx, Status status)
- {
- }
- public void RMWCompletionCallback(ref FugObject key, ref long 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)
- {
- return k1.Value == k2.Value;
- }
- public long GetHashCode64(ref FugObject k)
- {
- return Utility.GetHashCode(k.Value);
- }
- }
- public class Program
- {
- public static void Main(string[] args)
- {
- var mainLogPath = Path.Combine(Directory.GetCurrentDirectory(), @"logs\main.hlog");
- var checkpointPath = Path.Combine(Directory.GetCurrentDirectory(), @"logs");
- var isSecond = Directory.Exists(checkpointPath);
- var mainLog = Devices.CreateLogDevice(mainLogPath);
- var faster = new FasterKV<FugObject, FugObject, long, long, Empty, FugFunctions>(
- 1 << 21,
- new FugFunctions(),
- new LogSettings() { LogDevice = mainLog },
- new CheckpointSettings() { CheckpointDir = checkpointPath, CheckPointType = CheckpointType.FoldOver },
- null,
- new FugEqualityComparer(),
- null);
- if (isSecond)
- faster.Recover();
- faster.StartSession();
- var key = new FugObject() { Value = 10000L };
- var value = new FugObject() { Value = 20000L };
- if (!isSecond)
- {
- faster.Upsert(ref key, ref value, Empty.Default, 0);
- }
- else
- {
- var input = default(long);
- var output = default(long);
- faster.Read(ref key, ref input, ref output, Empty.Default, 0);
- }
- faster.TakeFullCheckpoint(out var _);
- faster.CompleteCheckpoint(true);
- faster.StopSession();
- faster.Dispose();
- mainLog.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement