Skip to content

Commit

Permalink
Updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc committed Sep 17, 2019
1 parent 16edd83 commit 3077f52
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
16 changes: 9 additions & 7 deletions cs/playground/FasterLogSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void ReportThread()

while (true)
{
Thread.Sleep(10000);
Thread.Sleep(5000);
var nowTime = sw.ElapsedMilliseconds;
var nowValue = log.TailAddress;

Expand All @@ -51,6 +51,8 @@ static void AppendThread()

static void ScanThread()
{
Random r = new Random();

Thread.Sleep(5000);

byte[] entry = new byte[entryLength];
Expand All @@ -72,6 +74,9 @@ static void ScanThread()
throw new Exception("Invalid entry found");
}

if (r.Next(100) < 10)
log.Append(result);

if (iter.CurrentAddress - lastAddress > 500000000)
{
log.TruncateUntil(iter.CurrentAddress);
Expand All @@ -83,14 +88,11 @@ static void ScanThread()

static void Main(string[] args)
{
var device = Devices.CreateLogDevice("E:\\logs\\hlog.log");
log = new FasterLog(new FasterLogSettings { LogDevice = device, MemorySizeBits = 26 });
var device = Devices.CreateLogDevice("D:\\logs\\hlog.log");
log = new FasterLog(new FasterLogSettings { LogDevice = device, MemorySizeBits = 29, PageSizeBits = 25 });

new Thread(new ThreadStart(AppendThread)).Start();
//new Thread(new ThreadStart(AppendThread)).Start();
//new Thread(new ThreadStart(AppendThread)).Start();
//new Thread(new ThreadStart(AppendThread)).Start();
// new Thread(new ThreadStart(ScanThread)).Start();
new Thread(new ThreadStart(ScanThread)).Start();
new Thread(new ThreadStart(ReportThread)).Start();

Thread.Sleep(500*1000);
Expand Down
26 changes: 24 additions & 2 deletions cs/src/core/Index/FasterLog/FasterLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
Expand Down Expand Up @@ -56,7 +57,7 @@ internal LogSettings GetLogSettings()
public class FasterLog
{
private readonly BlittableAllocator<Empty, byte> allocator;
private readonly LightEpoch epoch;
public readonly LightEpoch epoch;

/// <summary>
/// Beginning address of log
Expand Down Expand Up @@ -109,7 +110,6 @@ public unsafe long Append(Span<byte> entry)
/// <returns>Logical address of added entry</returns>
public unsafe long Append(byte[] entry)
{

epoch.Resume();
var length = entry.Length;
BlockAllocate(4 + length, out long logicalAddress);
Expand All @@ -121,6 +121,28 @@ public unsafe long Append(byte[] entry)
return logicalAddress;
}

/// <summary>
/// Append batch of entries to log
/// </summary>
/// <param name="entries"></param>
/// <returns>Logical address of last added entry</returns>
public unsafe long Append(List<byte[]> entries)
{
long logicalAddress = 0;
epoch.Resume();
foreach (var entry in entries)
{
var length = entry.Length;
BlockAllocate(4 + length, out logicalAddress);
var physicalAddress = allocator.GetPhysicalAddress(logicalAddress);
*(int*)physicalAddress = length;
fixed (byte* bp = entry)
Buffer.MemoryCopy(bp, (void*)(4 + physicalAddress), length, length);
}
epoch.Suspend();
return logicalAddress;
}

/// <summary>
/// Flush the log until tail
/// </summary>
Expand Down

0 comments on commit 3077f52

Please sign in to comment.