public LogRecordStream(Stream inner, bool checksum, BufferPool bufferPool) { _inner = inner; _checksum = checksum; _bufferPool = bufferPool; _binaryReader = new BinaryReader(inner); _buffer = _bufferPool.Take(LogWriter.BlockSize); try { var type = ReadPhysicalRecord(); switch (type) { case LogRecordType.FullType: _completedRecord = true; break; case LogRecordType.StartType: _inFragmentedRecord = true; break; case LogRecordType.MiddleType: case LogRecordType.EndType: throw new CorruptedDataException("missing start of fragmented record(3)"); default: throw new ArgumentOutOfRangeException("Don't know how to handle record type: " + type); } } catch (Exception) { _bufferPool.Return(_buffer); throw; } }
public InMemoryFileStream(BufferPool bufferPool, string name, InMemoryLowLevelStorage storage) : base(bufferPool) { _name = name; _storage = storage; Tuple<byte[], long> value; if(_storage._files.TryRemove(name, out value)) _storage._bufferPool.Return(value.Item1); }
public MemTable(int writeBatchSize, InternalKeyComparator internalKeyComparator, BufferPool bufferPool) { CreatedAt = DateTime.UtcNow; _bufferPool = bufferPool; _memoryAccessor = new UnamangedMemoryAccessor(writeBatchSize); _internalKeyComparator = internalKeyComparator; _table = new SkipList<InternalKey, UnamangedMemoryAccessor.MemoryHandle>(_internalKeyComparator); }
public LogWriter(FileSystem fileSystem, Stream stream, BufferPool bufferPool) { _isFileSteam = stream is FileStream; _fileSystem = fileSystem; _bufferPool = bufferPool; _buffer = bufferPool.Take(BlockSize); _binaryWriter = new BinaryWriter(stream); _bufferPos = HeaderSize; _lastCompletedRecordStreamLength = 0; }
/// <summary> /// If checksum is true, verify checksums if available. /// The reader will start reading at the first record located at physical /// position >= initialOffset within the file. /// </summary> public LogReader(Stream inner, bool checksum, long initialOffset, BufferPool bufferPool) { _inner = inner; _checksum = checksum; _initialOffset = initialOffset; _bufferPool = bufferPool; if (inner.Position >= _initialOffset) return; if (SkipToInitialBlock() == false) throw new CorruptedDataException("Cannot get to initial offset"); }
public Slice(ref byte[] externalBuffer, Slice other, BufferPool bufferPool) { if (externalBuffer.Length < other.Count) { bufferPool.Return(externalBuffer); externalBuffer = bufferPool.Take(other.Count); } _array = externalBuffer; _count = other._count; _offset = 0; Buffer.BlockCopy(other.Array, other.Offset, externalBuffer, 0, other.Count); }
internal static IEnumerable<LogReadResult> ReadFromLog(Stream logFile, BufferPool bufferPool) { var logReader = new LogReader(logFile, true, 0, bufferPool); Stream logRecordStream; while (logReader.TryReadRecord(out logRecordStream)) { var batch = new WriteBatch(); ulong seq; using (logRecordStream) { var buffer = new byte[8]; logRecordStream.ReadExactly(buffer, 8); seq = BitConverter.ToUInt64(buffer, 0); logRecordStream.ReadExactly(buffer, 4); var opCount = BitConverter.ToInt32(buffer, 0); for (var i = 0; i < opCount; i++) { logRecordStream.ReadExactly(buffer, 1); var op = (Operations)buffer[0]; var keyCount = logRecordStream.Read7BitEncodedInt(); var array = new byte[keyCount]; logRecordStream.ReadExactly(array, keyCount); var key = new Slice(array); switch (op) { case Operations.Delete: batch.Delete(key); break; case Operations.Put: logRecordStream.ReadExactly(buffer, 4); var size = BitConverter.ToInt64(buffer, 0); var value = new MemoryStream(); logRecordStream.CopyTo(value, size, LogWriter.BlockSize); batch.Put(key, value); break; default: throw new ArgumentException("Invalid operation type: " + op); } } } yield return new LogReadResult { WriteSequence = seq, WriteBatch = batch }; } }
public BufferPoolMemoryStream(BufferPool bufferPool) { _bufferPool = bufferPool; _buffer = _bufferPool.Take(8 * 1024); }
public InMemoryLowLevelStorage(BufferPool bufferPool) { _bufferPool = bufferPool; }
public StorageOptions() { CreateIfMissing = true; BlockSize = 1024 * 4; MaxBlockCacheSizePerTableFile = 2048; MaxTablesCacheSize = 2048; BlockRestartInterval = 16; Comparator = new CaseInsensitiveComparator(); FilterPolicy = new BloomFilterPolicy(); MaximumExpectedKeySize = 2048; WriteBatchSize = 1024 * 1024 * 12; CacheSizeInMegabytes = 256; BufferPool = new BufferPool(); }