Пример #1
0
        /// <summary>
        ///     Erase the file at position `pos` and replace it with a
        ///     brand new, empty file ; enqueue the writer for that empty
        ///     file into the new writers queue.
        /// </summary>
        private void ReplaceFile(int pos)
        {
            // Notify that files are about to be destroyed
            if (_readFiles[pos] is BlockFile bf)
            {
                foreach (var(r, h, a) in bf.EnumerateBlocks())
                {
                    try
                    {
                        _onDeletion(r, h, a);
                    }
                    catch
                    {
                        // Don't let exceptions prevent the actual file replacement.
                        // TODO: log this exception
                    }
                }

                // Disposing will release the memory-map, and allow
                // "DeleteAndCreate" to erase the underlying file.
                bf.Dispose();
            }

            var mma = _fs.DeleteAndCreate(pos);

            var(read, write) = FileWriter.CreateReaderWriterPair(
                mma, (uint)(pos + 1));

            _readFiles[pos] = read;
            _writer.CompleteRecycle(write);
        }