Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc committed Sep 30, 2019
2 parents bb4e357 + ec2a3b5 commit 4504937
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 260 deletions.
35 changes: 25 additions & 10 deletions cs/playground/FasterLogSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FasterLogSample
{
public class Program
{
const int entryLength = 96;
const int entryLength = 996;
static FasterLog log;

static void ReportThread()
Expand Down Expand Up @@ -50,15 +50,18 @@ static void AppendThread()

while (true)
{
// Sync append
log.Append(entry);

// We also support a Span-based version of Append

// We also support TryAppend to allow throttling/back-off:
// while (!log.TryAppend(entry, out long logicalAddress))
// {
// Thread.Sleep(10);
// }

// We also support a Span-based variant of Append

// We also support TryAppend to allow throttling/back-off
// (expect this to be slightly slower than the sync version)
// Make sure you supply a "starting" logical address of 0
// Retries must send back the current logical address.
//
// long logicalAddress = 0;
// while (!log.TryAppend(entry, ref logicalAddress)) ;
}
}

Expand All @@ -84,7 +87,7 @@ static void ScanThread()
Thread.Sleep(1000);
if (!result.SequenceEqual(entrySpan))
{
throw new Exception("Invalid entry found");
throw new Exception("Invalid entry found at offset " + FindDiff(result, entrySpan));
}

if (r.Next(100) < 10)
Expand All @@ -99,6 +102,18 @@ static void ScanThread()
}
}

static int FindDiff(Span<byte> b1, Span<byte> b2)
{
for (int i=0; i<b1.Length; i++)
{
if (b1[i] != b2[i])
{
return i;
}
}
return 0;
}

static void Main(string[] args)
{
var device = Devices.CreateLogDevice("D:\\logs\\hlog.log");
Expand Down
Loading

0 comments on commit 4504937

Please sign in to comment.