Skip to content

Commit

Permalink
[C#] Support FasterLog commit dir specification in settings (#519)
Browse files Browse the repository at this point in the history
* Support log commit path specification to FasterLog.

* updates

* Convert serialized SpanByte into its non-serialized form (safe to heap-copy as long as underlying payload is fixed)
  • Loading branch information
badrishc authored Jul 9, 2021
1 parent 0504248 commit 57b17d7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions cs/src/core/Device/LocalMemoryDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public unsafe sealed class LocalMemoryDevice : StorageDeviceBase
/// <param name="parallelism">Number of IO processing threads</param>
/// <param name="latencyMs">Induced callback latency in ms (for testing purposes)</param>
/// <param name="sector_size">Sector size for device (default 64)</param>
public LocalMemoryDevice(long capacity, long sz_segment, int parallelism, int latencyMs = 0, uint sector_size = 64)
: base("/userspace/ram/storage", sector_size, capacity)
/// <param name="fileName">Virtual path for the device</param>
public LocalMemoryDevice(long capacity, long sz_segment, int parallelism, int latencyMs = 0, uint sector_size = 64, string fileName = "/userspace/ram/storage")
: base(fileName, sector_size, capacity)
{
if (capacity == Devices.CAPACITY_UNSPECIFIED) throw new Exception("Local memory device must have a capacity!");
Console.WriteLine("LocalMemoryDevice: Creating a " + capacity + " sized local memory device.");
Expand Down
1 change: 1 addition & 0 deletions cs/src/core/Index/FasterLog/FasterLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ private FasterLog(FasterLogSettings logSettings, bool oldCommitManager)
new DeviceLogCommitCheckpointManager
(new LocalStorageNamedDeviceFactory(),
new DefaultCheckpointNamingScheme(
logSettings.LogCommitDir ??
new FileInfo(logSettings.LogDevice.FileName).Directory.FullName));

if (logSettings.LogCommitManager == null)
Expand Down
7 changes: 4 additions & 3 deletions cs/src/core/Index/FasterLog/FasterLogSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ public class FasterLogSettings
public ILogCommitManager LogCommitManager = null;

/// <summary>
/// Use specified directory for storing and retrieving checkpoints
/// Use specified directory (path) as base for storing and retrieving log commits. By default,
/// commits will be stored in a folder named log-commits under this directory. If not provided,
/// we use the base path of the log device by default.
/// </summary>
[Obsolete("This field is obsolete. The default log commit manager uses its own naming system. To use the old commit manager, set FasterLogSettings.LogCommitManager = new LocalLogCommitManager(LogCommitFile).", false)]
public string LogCommitFile = null;
public string LogCommitDir = null;

/// <summary>
/// User callback to allocate memory for read entries
Expand Down
11 changes: 11 additions & 0 deletions cs/src/core/VarLen/SpanByte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ public ReadOnlySpan<byte> AsReadOnlySpan()
return new ReadOnlySpan<byte>((void*)payload, Length);
}

/// <summary>
/// If SpanByte is in a serialized form, return a non-serialized SpanByte wrapper that points to the same payload.
/// The resulting SpanByte is safe to heap-copy, as long as the underlying payload remains fixed.
/// </summary>
/// <returns></returns>
public SpanByte Deserialize()
{
if (!Serialized) return this;
return new SpanByte(Length, (IntPtr)Unsafe.AsPointer(ref payload));
}

/// <summary>
/// Reinterpret a fixed Span&lt;byte&gt; as a serialized SpanByte. Automatically adds Span length to the first 4 bytes.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions cs/src/core/VarLen/SpanByteAndMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public unsafe struct SpanByteAndMemory : IHeapConvertible
/// <param name="spanByte"></param>
public SpanByteAndMemory(SpanByte spanByte)
{
if (spanByte.Serialized) throw new Exception("Cannot create new SpanByteAndMemory using serialized SpanByte");
SpanByte = spanByte;
Memory = default;
}
Expand Down

0 comments on commit 57b17d7

Please sign in to comment.