From 96dce84019aad05f2137f48aaefd4ec18d7adc4f Mon Sep 17 00:00:00 2001 From: Ogoun Date: Fri, 21 Jul 2023 01:55:08 +0300 Subject: [PATCH] Update Store.cs --- ZeroLevel/Services/PartitionStorage/Store.cs | 47 ++++++++++++++++---- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/ZeroLevel/Services/PartitionStorage/Store.cs b/ZeroLevel/Services/PartitionStorage/Store.cs index c4883aa..d834aa0 100644 --- a/ZeroLevel/Services/PartitionStorage/Store.cs +++ b/ZeroLevel/Services/PartitionStorage/Store.cs @@ -39,12 +39,24 @@ namespace ZeroLevel.Services.PartitionStorage public void RemovePartition(TMeta info) { var partition = CreateAccessor(info); - partition.DropData(); - FSUtils.RemoveFolder(partition.GetCatalogPath()); + if (partition != null) + { + string path; + using (partition) + { + path = partition.GetCatalogPath(); + partition.DropData(); + } + FSUtils.RemoveFolder(path); + } } public IStorePartitionAccessor CreateAccessor(TMeta info) { + if (false == Directory.Exists(_options.GetCatalogPath(info))) + { + return null; + } return new StorePartitionAccessor(_options, info, _serializer, _fileAccessorCachee); } @@ -79,11 +91,15 @@ namespace ZeroLevel.Services.PartitionStorage }; Parallel.ForEach(partitionsSearchInfo, options, (pair, _) => { - using (var accessor = CreateAccessor(pair.Key)) + var accessor = CreateAccessor(pair.Key); + if (accessor != null) { - results[pair.Key] = accessor - .Find(pair.Value) - .ToArray(); + using (accessor) + { + results[pair.Key] = accessor + .Find(pair.Value) + .ToArray(); + } } }); } @@ -99,16 +115,29 @@ namespace ZeroLevel.Services.PartitionStorage public void Bypass(TMeta meta, Action handler) { var accessor = CreateAccessor(meta); - foreach (var kv in accessor.Iterate()) + if (accessor != null) { - handler.Invoke(kv.Key, kv.Value); + using (accessor) + { + foreach (var kv in accessor.Iterate()) + { + handler.Invoke(kv.Key, kv.Value); + } + } } } public bool Exists(TMeta meta, TKey key) { var accessor = CreateAccessor(meta); - return accessor.Find(key).Status == SearchResult.Success; + if (accessor != null) + { + using (accessor) + { + return accessor.Find(key).Status == SearchResult.Success; + } + } + return false; } } }