|
|
@ -1,4 +1,5 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using ZeroLevel.Services.Cache;
|
|
|
|
using ZeroLevel.Services.Cache;
|
|
|
|
using ZeroLevel.Services.FileSystem;
|
|
|
|
using ZeroLevel.Services.FileSystem;
|
|
|
@ -12,6 +13,8 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
private readonly TimerCachee<ParallelFileReader> _indexReadersCachee;
|
|
|
|
private readonly TimerCachee<ParallelFileReader> _indexReadersCachee;
|
|
|
|
private readonly TimerCachee<ParallelFileReader> _dataReadersCachee;
|
|
|
|
private readonly TimerCachee<ParallelFileReader> _dataReadersCachee;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly HashSet<string> _lockedFiles = new HashSet<string>();
|
|
|
|
|
|
|
|
|
|
|
|
public PhisicalFileAccessorCachee(TimeSpan dataExpirationPeriod, TimeSpan indexExpirationPeriod)
|
|
|
|
public PhisicalFileAccessorCachee(TimeSpan dataExpirationPeriod, TimeSpan indexExpirationPeriod)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_dataReadersCachee = new TimerCachee<ParallelFileReader>(dataExpirationPeriod, s => new ParallelFileReader(s), i => i.Dispose(), 8192);
|
|
|
|
_dataReadersCachee = new TimerCachee<ParallelFileReader>(dataExpirationPeriod, s => new ParallelFileReader(s), i => i.Dispose(), 8192);
|
|
|
@ -31,6 +34,8 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
return _dataReadersCachee.Get(filePath);
|
|
|
|
return _dataReadersCachee.Get(filePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public IViewAccessor GetDataAccessor(string filePath, long offset)
|
|
|
|
public IViewAccessor GetDataAccessor(string filePath, long offset)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (false == _lockedFiles.Contains(filePath))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var reader = GetDataReader(filePath);
|
|
|
|
var reader = GetDataReader(filePath);
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -44,8 +49,12 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reader.GetAccessor(offset);
|
|
|
|
return reader.GetAccessor(offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IViewAccessor GetDataAccessor(string filePath, long offset, int length)
|
|
|
|
public IViewAccessor GetDataAccessor(string filePath, long offset, int length)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (false == _lockedFiles.Contains(filePath))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var reader = GetDataReader(filePath);
|
|
|
|
var reader = GetDataReader(filePath);
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -59,6 +68,8 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reader.GetAccessor(offset, length);
|
|
|
|
return reader.GetAccessor(offset, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
public void DropAllDataReaders()
|
|
|
|
public void DropAllDataReaders()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_dataReadersCachee.DropAll();
|
|
|
|
_dataReadersCachee.DropAll();
|
|
|
@ -78,6 +89,8 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
return _indexReadersCachee.Get(filePath);
|
|
|
|
return _indexReadersCachee.Get(filePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public IViewAccessor GetIndexAccessor(string filePath, long offset)
|
|
|
|
public IViewAccessor GetIndexAccessor(string filePath, long offset)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (false == _lockedFiles.Contains(filePath))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var reader = GetIndexReader(filePath);
|
|
|
|
var reader = GetIndexReader(filePath);
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -91,8 +104,12 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reader.GetAccessor(offset);
|
|
|
|
return reader.GetAccessor(offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IViewAccessor GetIndexAccessor(string filePath, long offset, int length)
|
|
|
|
public IViewAccessor GetIndexAccessor(string filePath, long offset, int length)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (false == _lockedFiles.Contains(filePath))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var reader = GetIndexReader(filePath);
|
|
|
|
var reader = GetIndexReader(filePath);
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -106,12 +123,26 @@ namespace ZeroLevel.Services.PartitionStorage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reader.GetAccessor(offset, length);
|
|
|
|
return reader.GetAccessor(offset, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
public void DropAllIndexReaders()
|
|
|
|
public void DropAllIndexReaders()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_indexReadersCachee.DropAll();
|
|
|
|
_indexReadersCachee.DropAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void LockFile(string filePath)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_lockedFiles.Add(filePath);
|
|
|
|
|
|
|
|
DropDataReader(filePath);
|
|
|
|
|
|
|
|
DropIndexReader(filePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void UnlockFile(string filePath)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_lockedFiles.Remove(filePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_dataReadersCachee.Dispose();
|
|
|
|
_dataReadersCachee.Dispose();
|
|
|
|