From 83f31af030e54ab741d4b0934156046ac2b89f6d Mon Sep 17 00:00:00 2001 From: InCerryGit Date: Fri, 23 Feb 2024 19:58:48 +0800 Subject: [PATCH 1/2] Support FasterKv options: 1. pre allocate file 2. delete file on close 3. try recover latest --- .../Configurations/FasterKvCachingOptions.cs | 20 ++++++++++++++--- .../DefaultFasterKvCachingProvider.cs | 22 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/EasyCaching.FasterKv/Configurations/FasterKvCachingOptions.cs b/src/EasyCaching.FasterKv/Configurations/FasterKvCachingOptions.cs index 325ff15f..95f25ca8 100644 --- a/src/EasyCaching.FasterKv/Configurations/FasterKvCachingOptions.cs +++ b/src/EasyCaching.FasterKv/Configurations/FasterKvCachingOptions.cs @@ -47,7 +47,21 @@ public class FasterKvCachingOptions : BaseProviderOptions #else Path.Combine(Environment.CurrentDirectory, $"EasyCaching-FasterKv-{System.Diagnostics.Process.GetCurrentProcess().Id}"); #endif - + + /// + /// Preallocate file + /// + public bool PreallocateFile { get; set; } = false; + + /// + /// Delete file on close + /// + public bool DeleteFileOnClose { get; set; } = true; + + /// + /// Try recover latest + /// + public bool TryRecoverLatest { get; set; } = false; /// /// Set Custom Store @@ -59,8 +73,8 @@ internal LogSettings GetLogSettings(string name) return new LogSettings { LogDevice = Devices.CreateLogDevice(Path.Combine(LogPath, name), - preallocateFile: true, - deleteOnClose: true), + preallocateFile: PreallocateFile, + deleteOnClose: DeleteFileOnClose), PageSizeBits = PageSizeBit, MemorySizeBits = MemorySizeBit, ReadCacheSettings = new ReadCacheSettings diff --git a/src/EasyCaching.FasterKv/DefaultFasterKvCachingProvider.cs b/src/EasyCaching.FasterKv/DefaultFasterKvCachingProvider.cs index 5a2643dd..47e5f593 100644 --- a/src/EasyCaching.FasterKv/DefaultFasterKvCachingProvider.cs +++ b/src/EasyCaching.FasterKv/DefaultFasterKvCachingProvider.cs @@ -59,8 +59,16 @@ public DefaultFasterKvCachingProvider( { var logSetting = options.GetLogSettings(name); _logDevice = logSetting.LogDevice; - _fasterKv = new FasterKV(_options.IndexCount, logSetting, - loggerFactory: loggerFactory); + _fasterKv = new FasterKV( + _options.IndexCount, + logSetting, + loggerFactory: loggerFactory, + tryRecoverLatest: _options.TryRecoverLatest, + checkpointSettings: new CheckpointSettings() + { + CheckpointDir = options.LogPath + ".checkpoint" + } + ); } else { @@ -364,12 +372,18 @@ private void Dispose(bool _) { session.Dispose(); } - - _logDevice?.Dispose(); + if (_options.CustomStore != _fasterKv) { + if (_options.DeleteFileOnClose == false) + { + _fasterKv.TakeFullCheckpointAsync(CheckpointType.FoldOver).AsTask().GetAwaiter().GetResult(); + } _fasterKv.Dispose(); } + + _logDevice?.Dispose(); + _disposed = true; } From c21e893777ace9799cafdf652f0f9542b7db4858 Mon Sep 17 00:00:00 2001 From: InCerry Date: Fri, 23 Feb 2024 20:02:19 +0800 Subject: [PATCH 2/2] Pass-through options --- .../Configurations/FasterKvCachingOptionsExtensions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/EasyCaching.FasterKv/Configurations/FasterKvCachingOptionsExtensions.cs b/src/EasyCaching.FasterKv/Configurations/FasterKvCachingOptionsExtensions.cs index d1d770da..e9db89e8 100644 --- a/src/EasyCaching.FasterKv/Configurations/FasterKvCachingOptionsExtensions.cs +++ b/src/EasyCaching.FasterKv/Configurations/FasterKvCachingOptionsExtensions.cs @@ -60,6 +60,9 @@ void Configure(FasterKvCachingOptions x) x.ReadCacheMemorySizeBit = fasterKvOptions.ReadCacheMemorySizeBit; x.ReadCachePageSizeBit = fasterKvOptions.ReadCachePageSizeBit; x.LogPath = fasterKvOptions.LogPath; + x.PreallocateFile = fasterKvOptions.PreallocateFile; + x.DeleteFileOnClose = fasterKvOptions.DeleteFileOnClose; + x.TryRecoverLatest = fasterKvOptions.TryRecoverLatest; } options.RegisterExtension(new FasterKvOptionsExtension(name, Configure));