void MoveValuesContent(AbstractBufferedWriter writer, uint wastefullFileId) { const uint blockSize = 128 * 1024; var wasteFullStream = _keyValueDB.FileCollection.GetFile(wastefullFileId); var totalSize = wasteFullStream.GetSize(); var blocks = (int)((totalSize + blockSize - 1) / blockSize); var wasteInMemory = new byte[blocks][]; var pos = 0UL; for (var i = 0; i < blocks; i++) { _cancellation.ThrowIfCancellationRequested(); wasteInMemory[i] = new byte[blockSize]; var readSize = totalSize - pos; if (readSize > blockSize) { readSize = blockSize; } wasteFullStream.RandomRead(wasteInMemory[i], 0, (int)readSize, pos, true); pos += readSize; } _root.Iterate((valueFileId, valueOfs, valueSize) => { if (valueFileId != wastefullFileId) { return; } var size = (uint)Math.Abs(valueSize); _newPositionMap.Add(((ulong)wastefullFileId << 32) | valueOfs, (uint)writer.GetCurrentPosition()); pos = valueOfs; while (size > 0) { _cancellation.ThrowIfCancellationRequested(); var blockId = pos / blockSize; var blockStart = pos % blockSize; var writeSize = (uint)(blockSize - blockStart); if (writeSize > size) { writeSize = size; } writer.WriteBlock(wasteInMemory[blockId], (int)blockStart, (int)writeSize); size -= writeSize; pos += writeSize; } }); }
void CalculateFileUsefullness(IBTreeRootNode root) { root.Iterate((valueFileId, valueOfs, valueSize) => { _cancellation.ThrowIfCancellationRequested(); _fileStats.GetOrFakeValueRef(valueFileId).AddLength((uint)Math.Abs(valueSize)); }); }
void ForbidDeleteOfFilesUsedByStillRunningOldTransaction(IBTreeRootNode root) { root.Iterate((valueFileId, valueOfs, valueSize) => { _cancellation.ThrowIfCancellationRequested(); _fileStats.GetOrFakeValueRef(valueFileId).MarkForbidToDelete(); }); }
void CalculateFileUsefullness(IBTreeRootNode root, bool uptodate) { root.Iterate((valueFileId, valueOfs, valueSize) => { var id = valueFileId; var fileStats = _fileStats; _cancellation.ThrowIfCancellationRequested(); if (id < fileStats.Length) { fileStats[id].AddLength((uint)Math.Abs(valueSize), uptodate); } }); }
private void ForbidDeleteOfFilesUsedByStillRunningOldTransaction(IBTreeRootNode root) { root.Iterate((valueFileId, valueOfs, valueSize) => { var id = valueFileId; var fileStats = _fileStats; _cancellation.ThrowIfCancellationRequested(); if (id < fileStats.Length) { fileStats[id].MarkForbidToDelete(); } }); }