Update Store.cs

pull/4/head
Ogoun 1 year ago
parent c9cbad6d33
commit 96dce84019

@ -39,12 +39,24 @@ namespace ZeroLevel.Services.PartitionStorage
public void RemovePartition(TMeta info) public void RemovePartition(TMeta info)
{ {
var partition = CreateAccessor(info); var partition = CreateAccessor(info);
partition.DropData(); if (partition != null)
FSUtils.RemoveFolder(partition.GetCatalogPath()); {
string path;
using (partition)
{
path = partition.GetCatalogPath();
partition.DropData();
}
FSUtils.RemoveFolder(path);
}
} }
public IStorePartitionAccessor<TKey, TInput, TValue> CreateAccessor(TMeta info) public IStorePartitionAccessor<TKey, TInput, TValue> CreateAccessor(TMeta info)
{ {
if (false == Directory.Exists(_options.GetCatalogPath(info)))
{
return null;
}
return new StorePartitionAccessor<TKey, TInput, TValue, TMeta>(_options, info, _serializer, _fileAccessorCachee); return new StorePartitionAccessor<TKey, TInput, TValue, TMeta>(_options, info, _serializer, _fileAccessorCachee);
} }
@ -79,11 +91,15 @@ namespace ZeroLevel.Services.PartitionStorage
}; };
Parallel.ForEach(partitionsSearchInfo, options, (pair, _) => Parallel.ForEach(partitionsSearchInfo, options, (pair, _) =>
{ {
using (var accessor = CreateAccessor(pair.Key)) var accessor = CreateAccessor(pair.Key);
if (accessor != null)
{ {
results[pair.Key] = accessor using (accessor)
.Find(pair.Value) {
.ToArray(); results[pair.Key] = accessor
.Find(pair.Value)
.ToArray();
}
} }
}); });
} }
@ -99,16 +115,29 @@ namespace ZeroLevel.Services.PartitionStorage
public void Bypass(TMeta meta, Action<TKey, TValue> handler) public void Bypass(TMeta meta, Action<TKey, TValue> handler)
{ {
var accessor = CreateAccessor(meta); 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) public bool Exists(TMeta meta, TKey key)
{ {
var accessor = CreateAccessor(meta); 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;
} }
} }
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.