Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using FASTER.core;
  8.  
  9. namespace Marius.Fug
  10. {
  11. public struct FugObject
  12. {
  13. public long Value;
  14. }
  15.  
  16.  
  17. public class FugFunctions : IFunctions<FugObject, FugObject, long, long, Empty>
  18. {
  19. public void SingleReader(ref FugObject key, ref long input, ref FugObject value, ref long dst)
  20. {
  21. dst = value.Value;
  22. }
  23.  
  24. public void ConcurrentReader(ref FugObject key, ref long input, ref FugObject value, ref long dst)
  25. {
  26. dst = value.Value;
  27. }
  28.  
  29. public void SingleWriter(ref FugObject key, ref FugObject src, ref FugObject dst)
  30. {
  31. dst.Value = src.Value;
  32. }
  33.  
  34. public void ConcurrentWriter(ref FugObject key, ref FugObject src, ref FugObject dst)
  35. {
  36. dst.Value = src.Value;
  37. }
  38.  
  39. public void CheckpointCompletionCallback(Guid sessionId, long serialNum)
  40. {
  41. }
  42.  
  43. public void CopyUpdater(ref FugObject key, ref long input, ref FugObject oldValue, ref FugObject newValue)
  44. {
  45. }
  46.  
  47. public void DeleteCompletionCallback(ref FugObject key, Empty ctx)
  48. {
  49. }
  50.  
  51. public void InitialUpdater(ref FugObject key, ref long input, ref FugObject value)
  52. {
  53. }
  54.  
  55. public void InPlaceUpdater(ref FugObject key, ref long input, ref FugObject value)
  56. {
  57. }
  58.  
  59. public void ReadCompletionCallback(ref FugObject key, ref long input, ref long output, Empty ctx, Status status)
  60. {
  61. }
  62.  
  63. public void RMWCompletionCallback(ref FugObject key, ref long input, Empty ctx, Status status)
  64. {
  65. }
  66.  
  67. public void UpsertCompletionCallback(ref FugObject key, ref FugObject value, Empty ctx)
  68. {
  69. }
  70. }
  71.  
  72. public class FugEqualityComparer : IFasterEqualityComparer<FugObject>
  73. {
  74. public bool Equals(ref FugObject k1, ref FugObject k2)
  75. {
  76. return k1.Value == k2.Value;
  77. }
  78.  
  79. public long GetHashCode64(ref FugObject k)
  80. {
  81. return Utility.GetHashCode(k.Value);
  82. }
  83. }
  84.  
  85. public class Program
  86. {
  87. public static void Main(string[] args)
  88. {
  89. var mainLogPath = Path.Combine(Directory.GetCurrentDirectory(), @"logs\main.hlog");
  90. var checkpointPath = Path.Combine(Directory.GetCurrentDirectory(), @"logs");
  91.  
  92. var isSecond = Directory.Exists(checkpointPath);
  93.  
  94. var mainLog = Devices.CreateLogDevice(mainLogPath);
  95. var faster = new FasterKV<FugObject, FugObject, long, long, Empty, FugFunctions>(
  96. 1 << 21,
  97. new FugFunctions(),
  98. new LogSettings() { LogDevice = mainLog },
  99. new CheckpointSettings() { CheckpointDir = checkpointPath, CheckPointType = CheckpointType.FoldOver },
  100. null,
  101. new FugEqualityComparer(),
  102. null);
  103.  
  104. if (isSecond)
  105. faster.Recover();
  106.  
  107. faster.StartSession();
  108.  
  109. var key = new FugObject() { Value = 10000L };
  110. var value = new FugObject() { Value = 20000L };
  111. if (!isSecond)
  112. {
  113. faster.Upsert(ref key, ref value, Empty.Default, 0);
  114. }
  115. else
  116. {
  117. var input = default(long);
  118. var output = default(long);
  119.  
  120. faster.Read(ref key, ref input, ref output, Empty.Default, 0);
  121. }
  122.  
  123. faster.TakeFullCheckpoint(out var _);
  124. faster.CompleteCheckpoint(true);
  125.  
  126. faster.StopSession();
  127.  
  128. faster.Dispose();
  129.  
  130. mainLog.Close();
  131. }
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement