|
|
|
@ -49,7 +49,9 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
var offset = index.GetOffset(key);
|
|
|
|
|
startOffset = offset.Offset;
|
|
|
|
|
}
|
|
|
|
|
using (var reader = GetReadStream(fileName))
|
|
|
|
|
if (TryGetReadStream(fileName, out var reader))
|
|
|
|
|
{
|
|
|
|
|
using (reader)
|
|
|
|
|
{
|
|
|
|
|
if (startOffset > 0)
|
|
|
|
|
{
|
|
|
|
@ -64,7 +66,7 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
{
|
|
|
|
|
Key = key,
|
|
|
|
|
Value = v,
|
|
|
|
|
Found = true
|
|
|
|
|
Status = SearchResult.Success
|
|
|
|
|
};
|
|
|
|
|
if (c == -1)
|
|
|
|
|
{
|
|
|
|
@ -73,10 +75,20 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new StorePartitionKeyValueSearchResult<TKey, TValue>
|
|
|
|
|
{
|
|
|
|
|
Key = key,
|
|
|
|
|
Status = SearchResult.FileLocked,
|
|
|
|
|
Value = default
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new StorePartitionKeyValueSearchResult<TKey, TValue>
|
|
|
|
|
{
|
|
|
|
|
Key = key,
|
|
|
|
|
Found = false,
|
|
|
|
|
Status = SearchResult.NotFound,
|
|
|
|
|
Value = default
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
@ -101,13 +113,16 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
{
|
|
|
|
|
foreach (var file in files)
|
|
|
|
|
{
|
|
|
|
|
using (var reader = GetReadStream(Path.GetFileName(file)))
|
|
|
|
|
if (TryGetReadStream(file, out var reader))
|
|
|
|
|
{
|
|
|
|
|
using (reader)
|
|
|
|
|
{
|
|
|
|
|
while (reader.EOS == false)
|
|
|
|
|
{
|
|
|
|
|
var k = _keyDeserializer.Invoke(reader);
|
|
|
|
|
var v = _valueDeserializer.Invoke(reader);
|
|
|
|
|
yield return new StorePartitionKeyValueSearchResult<TKey, TValue> { Key = k, Value = v, Found = true };
|
|
|
|
|
yield return new StorePartitionKeyValueSearchResult<TKey, TValue> { Key = k, Value = v, Status = SearchResult.Success };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -118,13 +133,16 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
var fileName = _options.GetFileName(key, _info);
|
|
|
|
|
if (File.Exists(Path.Combine(_catalog, fileName)))
|
|
|
|
|
{
|
|
|
|
|
using (var reader = GetReadStream(fileName))
|
|
|
|
|
if (TryGetReadStream(fileName, out var reader))
|
|
|
|
|
{
|
|
|
|
|
using (reader)
|
|
|
|
|
{
|
|
|
|
|
while (reader.EOS == false)
|
|
|
|
|
{
|
|
|
|
|
var k = _keyDeserializer.Invoke(reader);
|
|
|
|
|
var v = _valueDeserializer.Invoke(reader);
|
|
|
|
|
yield return new StorePartitionKeyValueSearchResult<TKey, TValue> { Key = k, Value = v, Found = true };
|
|
|
|
|
yield return new StorePartitionKeyValueSearchResult<TKey, TValue> { Key = k, Value = v, Status = SearchResult.Success };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -197,7 +215,9 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
Directory.CreateDirectory(_indexCatalog);
|
|
|
|
|
}
|
|
|
|
|
var dict = new Dictionary<TKey, long>();
|
|
|
|
|
using (var reader = GetReadStream(Path.GetFileName(file)))
|
|
|
|
|
if (TryGetReadStream(file, out var reader))
|
|
|
|
|
{
|
|
|
|
|
using (reader)
|
|
|
|
|
{
|
|
|
|
|
while (reader.EOS == false)
|
|
|
|
|
{
|
|
|
|
@ -207,6 +227,7 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
_valueDeserializer.Invoke(reader);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (dict.Count > _options.Index.FileIndexCount * 8)
|
|
|
|
|
{
|
|
|
|
|
var step = (int)Math.Round(((float)dict.Count / (float)_options.Index.FileIndexCount), MidpointRounding.ToZero);
|
|
|
|
@ -237,7 +258,9 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
{
|
|
|
|
|
var index = new StorePartitionSparseIndex<TKey, TMeta>(_catalog, _info, _options.FilePartition, _options.KeyComparer);
|
|
|
|
|
var offsets = index.GetOffset(keys, true);
|
|
|
|
|
using (var reader = GetReadStream(fileName))
|
|
|
|
|
if (TryGetReadStream(fileName, out var reader))
|
|
|
|
|
{
|
|
|
|
|
using (reader)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < keys.Length; i++)
|
|
|
|
|
{
|
|
|
|
@ -255,7 +278,7 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
{
|
|
|
|
|
Key = searchKey,
|
|
|
|
|
Value = v,
|
|
|
|
|
Found = true
|
|
|
|
|
Status = SearchResult.Success
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -267,9 +290,12 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (var reader = GetReadStream(fileName))
|
|
|
|
|
if (TryGetReadStream(fileName, out var reader))
|
|
|
|
|
{
|
|
|
|
|
using (reader)
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
|
|
|
|
var keys_arr = keys.OrderBy(k => k).ToArray();
|
|
|
|
@ -284,7 +310,7 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
{
|
|
|
|
|
Key = keys_arr[index],
|
|
|
|
|
Value = v,
|
|
|
|
|
Found = true
|
|
|
|
|
Status = SearchResult.Success
|
|
|
|
|
};
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
@ -304,6 +330,7 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveKeyGroup(string fileName, TKey[] keys, bool inverseRemove, bool autoReindex)
|
|
|
|
|
{
|
|
|
|
@ -316,7 +343,9 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
{
|
|
|
|
|
var index = new StorePartitionSparseIndex<TKey, TMeta>(_catalog, _info, _options.FilePartition, _options.KeyComparer);
|
|
|
|
|
var offsets = index.GetOffset(keys, true);
|
|
|
|
|
using (var reader = GetReadStream(fileName))
|
|
|
|
|
if (TryGetReadStream(fileName, out var reader))
|
|
|
|
|
{
|
|
|
|
|
using (reader)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < keys.Length; i++)
|
|
|
|
|
{
|
|
|
|
@ -342,9 +371,12 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (var reader = GetReadStream(fileName))
|
|
|
|
|
if (TryGetReadStream(fileName, out var reader))
|
|
|
|
|
{
|
|
|
|
|
using (reader)
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
|
|
|
|
var keys_arr = keys.OrderBy(k => k).ToArray();
|
|
|
|
@ -374,6 +406,7 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Temporary file from ranges
|
|
|
|
|
var tempPath = Path.GetTempPath();
|
|
|
|
@ -414,11 +447,21 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MemoryStreamReader GetReadStream(string fileName)
|
|
|
|
|
private bool TryGetReadStream(string fileName, out MemoryStreamReader reader)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var filePath = Path.Combine(_catalog, fileName);
|
|
|
|
|
var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096 * 1024);
|
|
|
|
|
return new MemoryStreamReader(stream);
|
|
|
|
|
reader = new MemoryStreamReader(stream);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.SystemError(ex, "[StorePartitionAccessor.TryGetReadStream]");
|
|
|
|
|
}
|
|
|
|
|
reader = null;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|