public ulong GetSize() { ulong res = _positionLessStream.GetSize(); Log("get stream size:{0}", res); return(res); }
public bool Open(IPositionLessStream positionLessStream, bool dispose) { lock (_log) { _log.WriteUInt8((byte)KVReplayOperation.Open); ulong size = positionLessStream.GetSize(); _log.WriteVUInt64(size); ulong pos = 0; var buf = new byte[4096]; while (pos < size) { var read = positionLessStream.Read(buf, 0, buf.Length, pos); // Next 2 conditions should not happen or file is mutated when it should not if (read == 0) { break; } if ((ulong)read > size - pos) { read = (int)(size - pos); } _log.WriteBlock(buf, 0, read); pos += (ulong)read; } while (pos < size) { _log.WriteUInt8(0); pos++; } _log.FlushBuffer(); } return(_db.Open(positionLessStream, dispose)); }
public bool Open(IPositionLessStream positionLessStream, bool dispose) { lock (_log) { _log.WriteUInt8((byte)KVReplayOperation.Open); ulong size = positionLessStream.GetSize(); _log.WriteVUInt64(size); ulong pos = 0; var buf = new byte[4096]; while (pos < size) { var read = positionLessStream.Read(buf, 0, buf.Length, pos); // Next 2 conditions should not happen or file is mutated when it should not if (read == 0) break; if ((ulong)read > size - pos) read = (int)(size - pos); _log.WriteBlock(buf, 0, read); pos += (ulong)read; } while (pos < size) { _log.WriteUInt8(0); pos++; } _log.FlushBuffer(); } return _db.Open(positionLessStream, dispose); }
public PositionLessStreamReader(IPositionLessStream stream) { _stream = stream; _valueSize = _stream.GetSize(); _ofs = 0; Buf = new byte[4096]; FillBuffer(); }
public PositionLessStreamReader(IPositionLessStream stream) { _stream = stream; _valueSize = _stream.GetSize(); _ofs = 0; Buf = new byte[8192]; FillBuffer(); }
public PositionLessStreamReader(IPositionLessStream stream, int bufferSize) { if (bufferSize <= 0) { throw new ArgumentOutOfRangeException(nameof(bufferSize)); } _stream = stream; _valueSize = _stream.GetSize(); _ofs = 0; Buf = new byte[bufferSize]; FillBuffer(); }
public PositionLessStreamWriter(IPositionLessStream stream, Action?onDispose, bool atEnd = false) { _stream = stream; _onDispose = onDispose ?? DisposeStream; _buf = new byte[BufLength]; _pos = 0; if (atEnd) { _ofs = _stream.GetSize(); } else { _ofs = 0; _stream.SetSize(0); } }
public PositionLessStreamWriter(IPositionLessStream stream, Action onDispose, bool atEnd = false) { _stream = stream; if (onDispose == null) onDispose = DisposeStream; _onDispose = onDispose; Buf = new byte[8192]; End = Buf.Length; if (atEnd) { _ofs = _stream.GetSize(); } else { _ofs = 0; _stream.SetSize(0); } }
public PositionLessStreamWriter(IPositionLessStream stream, Action onDispose, bool atEnd = false) { _stream = stream; if (onDispose == null) { onDispose = DisposeStream; } _onDispose = onDispose; Buf = new byte[8192]; End = Buf.Length; if (atEnd) { _ofs = _stream.GetSize(); } else { _ofs = 0; _stream.SetSize(0); } }
public bool Open(IPositionLessStream positionLessStream, bool dispose) { if (positionLessStream == null) throw new ArgumentNullException("positionLessStream"); _positionLessStream = positionLessStream; _disposeStream = dispose; _spaceSoonReusable = null; _freeSpaceAllocatorOptimizer.GlobalInvalidate(); _wasAnyCommits = false; bool newDB = false; if (positionLessStream.GetSize() == 0) { InitEmptyDB(); newDB = true; } else { if (_positionLessStream.Read(_headerData, 0, TotalHeaderSize, 0) != TotalHeaderSize) { throw new BTDBException("Too short header"); } _totalBytesRead += TotalHeaderSize; if (_headerData[0] != (byte)'B' || _headerData[1] != (byte)'T' || _headerData[2] != (byte)'D' || _headerData[3] != (byte)'B' || _headerData[4] != (byte)'1' || _headerData[5] != (byte)'0' || _headerData[6] != (byte)'0' || _headerData[7] != (byte)'2') { throw new BTDBException("Wrong header"); } } _newState.Position = FirstRootOffset; _currentState.Position = SecondRootOffset; if (RetrieveStateFromHeaderBuffer(_newState)) { if (RetrieveStateFromHeaderBuffer(_currentState)) { if (_currentState.TransactionCounter != _newState.TransactionCounter) { if (_currentState.TransactionCounter > _newState.TransactionCounter) { SwapCurrentAndNewState(); } if (!CheckDB(_newState)) { if (CheckDB(_currentState)) { SwapCurrentAndNewState(); } else { ThrowDatabaseCorrupted(); } } } } else { if (!CheckDB(_newState)) { ThrowDatabaseCorrupted(); } } } else { SwapCurrentAndNewState(); if (RetrieveStateFromHeaderBuffer(_newState) == false) { throw new BTDBException("Both root headers corrupted"); } if (!CheckDB(_newState)) { ThrowDatabaseCorrupted(); } } TransferNewStateToCurrentState(); if (_currentState.TransactionAllocSize > 0) { throw new BTDBException("TransactionLog is not supported"); } return newDB; }