Skip to content

Commit

Permalink
Cleaned up sample contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc committed Jan 17, 2020
1 parent 1ab9434 commit 7516096
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 52 deletions.
18 changes: 10 additions & 8 deletions cs/FASTER.sln
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,21 @@ Global
{25C5C6B6-4A8A-46DD-88C1-EB247033FE58}.Release|x64.ActiveCfg = Release|x64
{25C5C6B6-4A8A-46DD-88C1-EB247033FE58}.Release|x64.Build.0 = Release|x64
{859F76F4-93D8-4D60-BF9A-363E217FA247}.Debug|Any CPU.ActiveCfg = Debug|x64
{859F76F4-93D8-4D60-BF9A-363E217FA247}.Debug|Any CPU.Build.0 = Debug|x64
{859F76F4-93D8-4D60-BF9A-363E217FA247}.Debug|x64.ActiveCfg = Debug|x64
{859F76F4-93D8-4D60-BF9A-363E217FA247}.Debug|x64.Build.0 = Debug|x64
{859F76F4-93D8-4D60-BF9A-363E217FA247}.Release|Any CPU.ActiveCfg = Release|x64
{859F76F4-93D8-4D60-BF9A-363E217FA247}.Release|Any CPU.Build.0 = Release|x64
{859F76F4-93D8-4D60-BF9A-363E217FA247}.Release|x64.ActiveCfg = Release|x64
{859F76F4-93D8-4D60-BF9A-363E217FA247}.Release|x64.Build.0 = Release|x64
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Debug|x64.ActiveCfg = Debug|Any CPU
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Debug|x64.Build.0 = Debug|Any CPU
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Release|Any CPU.Build.0 = Release|Any CPU
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Release|x64.ActiveCfg = Release|Any CPU
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Release|x64.Build.0 = Release|Any CPU
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Debug|Any CPU.ActiveCfg = Debug|x64
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Debug|Any CPU.Build.0 = Debug|x64
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Debug|x64.ActiveCfg = Debug|x64
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Debug|x64.Build.0 = Debug|x64
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Release|Any CPU.ActiveCfg = Release|x64
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Release|Any CPU.Build.0 = Release|x64
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Release|x64.ActiveCfg = Release|x64
{95AC8766-84F9-4E95-B2E9-2169B6375FB2}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>preview</LangVersion>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 15 additions & 13 deletions cs/playground/ClassRecoveryDurablity/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Linq;
using System.Threading.Tasks;
using FASTER.core;
Expand All @@ -8,12 +11,12 @@ namespace ClassRecoveryDurablity
class Program
{
static bool stop;

static int deleteWindown = 5;
static int deleteWindow = 5;
static int indexAhead = 10000000;
static int startDeletHeight = 20;
static int startDeleteHeight = 20;
static int addCount = 100;
static int deletePosition = 20;

static void Main(string[] args)
{
Task.Run(() =>
Expand Down Expand Up @@ -86,15 +89,15 @@ static void Filldb(int stopAfterIteration = 5)
Types.StoreContext context2 = new Types.StoreContext();
var addStatus = session.Upsert(ref upsertKey, ref upsertValue, context2, 1);
//Console.WriteLine("add=" + i);
// Console.WriteLine("add=" + i);
if (addStatus != Status.OK)
throw new Exception();
}
if (start > startDeletHeight)
if (start > startDeleteHeight)
{
var todelete = (start - deleteWindown) * indexAhead;
var todelete = (start - deleteWindow) * indexAhead;
for (long i = todelete; i < todelete + addCount; i++)
{
Expand All @@ -105,7 +108,7 @@ static void Filldb(int stopAfterIteration = 5)
var deteletKey = new Types.StoreKey { tableType = "C", key = data.key };
Types.StoreContext context2 = new Types.StoreContext();
var deleteStatus = session.Delete(ref deteletKey, context2, 1);
//Console.WriteLine("delete=" + i);
// Console.WriteLine("delete=" + i);
if (deleteStatus != Status.OK)
throw new Exception();
Expand Down Expand Up @@ -177,11 +180,11 @@ static void TestData(Storedb store, int count)
var start = from;
var toadd = start * indexAhead;
var todelete = start * indexAhead;
var deleteHegith = from > startDeletHeight - deleteWindown && from <= blockHeight - deleteWindown;
var deleteHeight = from > startDeleteHeight - deleteWindow && from <= blockHeight - deleteWindow;
for (long i = toadd, j = todelete; i < toadd + addCount; i++, j++)
{
if (deleteHegith && (j % deletePosition == 0))
if (deleteHeight && (j % deletePosition == 0))
{
var data = Generate(j);
Expand Down Expand Up @@ -251,9 +254,8 @@ static void TestData(Storedb store, int count)

public static byte[] Hash256(byte[] byteContents)
{
var hash = new System.Security.Cryptography.SHA256CryptoServiceProvider();
byte[] hased = hash.ComputeHash(byteContents);
return hased;
using var hash = new System.Security.Cryptography.SHA256CryptoServiceProvider();
return hash.ComputeHash(byteContents);
}
}
}
Expand Down
32 changes: 15 additions & 17 deletions cs/playground/ClassRecoveryDurablity/Storedb.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.IO;
using FASTER.core;

namespace ClassRecoveryDurablity
{
public class Storedb
{
private string dataFolder;
private readonly string dataFolder;

public FasterKV<Types.StoreKey, Types.StoreValue, Types.StoreInput, Types.StoreOutput, Types.StoreContext, Types.StoreFunctions> db;
public IDevice log;
public IDevice objLog;

public Storedb(string folder)
{
this.dataFolder = folder;
dataFolder = folder;
}

public bool InitAndRecover()
{
var logSize = 1L << 20;
this.log = Devices.CreateLogDevice(@$"{this.dataFolder}\data\Store-hlog.log", preallocateFile: false);
this.objLog = Devices.CreateLogDevice(@$"{this.dataFolder}\data\Store-hlog-obj.log", preallocateFile: false);
log = Devices.CreateLogDevice(@$"{this.dataFolder}\data\Store-hlog.log", preallocateFile: false);
objLog = Devices.CreateLogDevice(@$"{this.dataFolder}\data\Store-hlog-obj.log", preallocateFile: false);

this.db = new FasterKV
<Types.StoreKey, Types.StoreValue, Types.StoreInput, Types.StoreOutput, Types.StoreContext, Types.StoreFunctions>(
Expand All @@ -48,10 +51,8 @@ public bool InitAndRecover()

if (Directory.Exists($"{this.dataFolder}/data/checkpoints"))
{
Console.WriteLine("call rcover db");

this.db.Recover();

Console.WriteLine("call recover db");
db.Recover();
return false;
}

Expand All @@ -60,19 +61,16 @@ public bool InitAndRecover()

public Guid Checkpoint()
{
Guid token = default(Guid);

this.db.TakeFullCheckpoint(out token);
this.db.CompleteCheckpointAsync().GetAwaiter().GetResult();

db.TakeFullCheckpoint(out Guid token);
db.CompleteCheckpointAsync().GetAwaiter().GetResult();
return token;
}

public void Dispose()
{
this.db.Dispose();
this.log.Close();
this.objLog.Close();
db.Dispose();
log.Close();
objLog.Close();
}
}
}
Expand Down
29 changes: 16 additions & 13 deletions cs/playground/ClassRecoveryDurablity/Types.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Linq;
using FASTER.core;

Expand Down Expand Up @@ -36,29 +39,29 @@ public class StoreKeySerializer : BinaryObjectSerializer<StoreKey>
public override void Deserialize(ref StoreKey obj)
{
var bytesr = new byte[4];
this.reader.Read(bytesr, 0, 4);
reader.Read(bytesr, 0, 4);
var sizet = BitConverter.ToInt32(bytesr);
var bytes = new byte[sizet];
this.reader.Read(bytes, 0, sizet);
reader.Read(bytes, 0, sizet);
obj.tableType = System.Text.Encoding.UTF8.GetString(bytes);

bytesr = new byte[4];
this.reader.Read(bytesr, 0, 4);
reader.Read(bytesr, 0, 4);
var size = BitConverter.ToInt32(bytesr);
obj.key = new byte[size];
this.reader.Read(obj.key, 0, size);
reader.Read(obj.key, 0, size);
}

public override void Serialize(ref StoreKey obj)
{
var bytes = System.Text.Encoding.UTF8.GetBytes(obj.tableType);
var len = BitConverter.GetBytes(bytes.Length);
this.writer.Write(len);
this.writer.Write(bytes);
writer.Write(len);
writer.Write(bytes);

len = BitConverter.GetBytes(obj.key.Length);
this.writer.Write(len);
this.writer.Write(obj.key);
writer.Write(len);
writer.Write(obj.key);
}
}

Expand All @@ -75,16 +78,16 @@ public class StoreValueSerializer : BinaryObjectSerializer<StoreValue>
public override void Deserialize(ref StoreValue obj)
{
var bytesr = new byte[4];
this.reader.Read(bytesr, 0, 4);
reader.Read(bytesr, 0, 4);
int size = BitConverter.ToInt32(bytesr);
obj.value = this.reader.ReadBytes(size);
obj.value = reader.ReadBytes(size);
}

public override void Serialize(ref StoreValue obj)
{
var len = BitConverter.GetBytes(obj.value.Length);
this.writer.Write(len);
this.writer.Write(obj.value);
writer.Write(len);
writer.Write(obj.value);
}
}

Expand Down

0 comments on commit 7516096

Please sign in to comment.