public void Dispose() { lock (_lock) { if (_transactionSlice != null) { _transactionSlice.Dispose(); _transactionSlice = null; } } GC.SuppressFinalize(this); }
void Split(long blockId) { lock (_lock) { if (_transactionSlice.Length <= 0) { return; } if (_currentFirsBlockId == Protocol.InvalidBlockId) { _currentFirsBlockId = blockId; } _currentBlockId = blockId; _slices.Add(_currentSliceId, new TransactionSliceInfo(_currentSliceId, _currentFirsBlockId, _currentBlockId, true, _transactionSlice.Length, _transactionSlice.StartIndex, _transactionSlice.EndIndex)); } _transactionSlice.Close(); DiscStorage.BuildChecksum(_storage, Path.Combine(TransactionsPath, _currentSliceId.ToString())); lock (_lock) { _currentSliceId++; _currentBlockId = Protocol.InvalidBlockId; _currentFirsBlockId = Protocol.InvalidBlockId; _transactionSlice = new TransactionDiscStorage(_storage, Path.Combine(TransactionsPath, _currentSliceId.ToString()), _blockSize, _storageFlags) { FirstBlockId = _currentFirsBlockId, LastBlockId = _currentBlockId, Split = false }; } Save(); }
public TransactionStorage(Base.Storage storage, ChainType chainType, int chainId, uint chainIndex) { _blockSize = 0; _storageFlags = DiscStorageFlags.DynamicBlockSize; _storage = storage; ChainId = chainId; ChainIndex = chainIndex; TransactionsPath = GetTransactionStoragePath(chainType, chainId, chainIndex); FullTransactionsStoragePath = Path.Combine(storage.Root.FullName, TransactionsPath); CreateRequiredDirectories(storage, chainType, chainId, chainIndex); _currentSliceId = 0; _slices = GetTransactionSlices(storage, chainType, chainId, chainIndex, false); // remove the last "hot" slice if (_slices.Count > 0) { var last = _slices.Last().Value; if (last.Finalized) { _currentSliceId = last.SliceId + 1; } else { _currentSliceId = last.SliceId; _slices.RemoveAt(_slices.Count - 1); } } _transactionSlice = new TransactionDiscStorage(_storage, Path.Combine(TransactionsPath, _currentSliceId.ToString()), _blockSize, _storageFlags); _currentFirsBlockId = _transactionSlice.FirstBlockId; _currentBlockId = _transactionSlice.LastBlockId; }