From 57b17d7cbb9b7c2b7f47cf9380f594df1f8b0e85 Mon Sep 17 00:00:00 2001 From: Badrish Chandramouli Date: Fri, 9 Jul 2021 07:54:19 -0700 Subject: [PATCH] [C#] Support FasterLog commit dir specification in settings (#519) * 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) --- cs/src/core/Device/LocalMemoryDevice.cs | 5 +++-- cs/src/core/Index/FasterLog/FasterLog.cs | 1 + cs/src/core/Index/FasterLog/FasterLogSettings.cs | 7 ++++--- cs/src/core/VarLen/SpanByte.cs | 11 +++++++++++ cs/src/core/VarLen/SpanByteAndMemory.cs | 1 + 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/cs/src/core/Device/LocalMemoryDevice.cs b/cs/src/core/Device/LocalMemoryDevice.cs index 17473d0a8..66c2ca0ef 100644 --- a/cs/src/core/Device/LocalMemoryDevice.cs +++ b/cs/src/core/Device/LocalMemoryDevice.cs @@ -43,8 +43,9 @@ public unsafe sealed class LocalMemoryDevice : StorageDeviceBase /// Number of IO processing threads /// Induced callback latency in ms (for testing purposes) /// Sector size for device (default 64) - public LocalMemoryDevice(long capacity, long sz_segment, int parallelism, int latencyMs = 0, uint sector_size = 64) - : base("/userspace/ram/storage", sector_size, capacity) + /// Virtual path for the device + 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."); diff --git a/cs/src/core/Index/FasterLog/FasterLog.cs b/cs/src/core/Index/FasterLog/FasterLog.cs index c7980b70b..78dbb2a6c 100644 --- a/cs/src/core/Index/FasterLog/FasterLog.cs +++ b/cs/src/core/Index/FasterLog/FasterLog.cs @@ -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) diff --git a/cs/src/core/Index/FasterLog/FasterLogSettings.cs b/cs/src/core/Index/FasterLog/FasterLogSettings.cs index ecb035f74..9fe7cc8e5 100644 --- a/cs/src/core/Index/FasterLog/FasterLogSettings.cs +++ b/cs/src/core/Index/FasterLog/FasterLogSettings.cs @@ -63,10 +63,11 @@ public class FasterLogSettings public ILogCommitManager LogCommitManager = null; /// - /// 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. /// - [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; /// /// User callback to allocate memory for read entries diff --git a/cs/src/core/VarLen/SpanByte.cs b/cs/src/core/VarLen/SpanByte.cs index 78114e651..30f709379 100644 --- a/cs/src/core/VarLen/SpanByte.cs +++ b/cs/src/core/VarLen/SpanByte.cs @@ -107,6 +107,17 @@ public ReadOnlySpan AsReadOnlySpan() return new ReadOnlySpan((void*)payload, Length); } + /// + /// 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. + /// + /// + public SpanByte Deserialize() + { + if (!Serialized) return this; + return new SpanByte(Length, (IntPtr)Unsafe.AsPointer(ref payload)); + } + /// /// Reinterpret a fixed Span<byte> as a serialized SpanByte. Automatically adds Span length to the first 4 bytes. /// diff --git a/cs/src/core/VarLen/SpanByteAndMemory.cs b/cs/src/core/VarLen/SpanByteAndMemory.cs index da957ce97..1afb6de8b 100644 --- a/cs/src/core/VarLen/SpanByteAndMemory.cs +++ b/cs/src/core/VarLen/SpanByteAndMemory.cs @@ -28,6 +28,7 @@ public unsafe struct SpanByteAndMemory : IHeapConvertible /// public SpanByteAndMemory(SpanByte spanByte) { + if (spanByte.Serialized) throw new Exception("Cannot create new SpanByteAndMemory using serialized SpanByte"); SpanByte = spanByte; Memory = default; }