void CompactOnePureValueFileIteration(List <uint> toRemoveFileIds) { _cancellation.ThrowIfCancellationRequested(); var writer = _keyValueDB.StartPureValuesFile(out var valueFileId); while (true) { var wastefullFileId = FindMostWastefullFile(_keyValueDB.MaxTrLogFileSize - writer.GetCurrentPosition()); if (wastefullFileId == 0) { break; } MoveValuesContent(writer, wastefullFileId, valueFileId); if (_fileStats.GetOrFakeValueRef(wastefullFileId).IsFreeToDelete()) { toRemoveFileIds.Add(wastefullFileId); } _fileStats.GetOrFakeValueRef(wastefullFileId) = new FileStat(0); } var valueFile = _keyValueDB.FileCollection.GetFile(valueFileId); valueFile.HardFlush(); valueFile.Truncate(); _keyValueDB.Logger?.CompactionCreatedPureValueFile(valueFileId, valueFile.GetSize(), (uint)_newPositionMap.Count, 28 * #if NETFRAMEWORK (ulong)_newPositionMap.Count #else (ulong) _newPositionMap.EnsureCapacity(0) #endif ); }
void CompactOnePureValueFileIteration(ref StructList <uint> toRemoveFileIds) { _cancellation.ThrowIfCancellationRequested(); _writerBytesPerSecondLimiter = new BytesPerSecondLimiter(_keyValueDB.CompactorWriteBytesPerSecondLimit); var writer = _keyValueDB.StartPureValuesFile(out var valueFileId); var firstIteration = true; while (true) { var wastefulFileId = FindMostWastefulFile(firstIteration ? uint.MaxValue : _keyValueDB.MaxTrLogFileSize - writer.GetCurrentPositionWithoutWriter()); firstIteration = false; if (wastefulFileId == 0) { break; } MoveValuesContent(writer, wastefulFileId, valueFileId); if (_fileStats.GetOrFakeValueRef(wastefulFileId).IsFreeToDelete()) { toRemoveFileIds.Add(wastefulFileId); } _fileStats.GetOrFakeValueRef(wastefulFileId) = new FileStat(0); } var valueFile = _keyValueDB.FileCollection.GetFile(valueFileId); valueFile !.HardFlushTruncateSwitchToReadOnlyMode(); _keyValueDB.Logger?.CompactionCreatedPureValueFile(valueFileId, valueFile.GetSize(), (uint)_newPositionMap.Count, 28 * (ulong)_newPositionMap.EnsureCapacity(0) ); }