Skip to main content

TraceReader

Struct TraceReader 

Source
pub struct TraceReader { /* private fields */ }
Expand description

Reads the raw, still-encoded records of a trace file one at a time.

This is the low level half of tracing: it hands back the bytes RocksDB wrote, header and footer records included, and does not decode them into queries. Use Replayer to run a trace against a DB instead.

Reading is sequential. reset rewinds to the start of the file.

Implementations§

Source§

impl TraceReader

Source

pub fn open<P: AsRef<Path>>(env: &Env, trace_path: P) -> Result<Self, Error>

Opens an existing trace file for reading through env.

Fails if the file does not exist. Reads use a default EnvOptions. Use open_with_env_options to control how the file is read.

Source

pub fn open_with_env_options<P: AsRef<Path>>( env: &Env, env_opts: &EnvOptions, trace_path: P, ) -> Result<Self, Error>

Opens an existing trace file for reading through env and env_opts.

env_opts only has to live for the call. RocksDB reads the options while opening the file and does not carry a rate limiter into the reader, so unlike SstFileWriter::create_with_env_options there is nothing here that outlives the borrow.

Source

pub fn read(&mut self) -> Result<Option<Vec<u8>>, Error>

Reads the next record, or Ok(None) at the end of the file.

End of stream is unambiguous here. FileTraceReader::Read reports it as Status::Incomplete, and rocksdb_trace_reader_read in db/c.cc translates that specific status into a null return with no error string set, which is the only way a successful call can produce null: a record always carries a fixed size header, so a real record is never zero bytes, and a short read is reported as Corruption instead. Any other failure comes back as Err.

Returns an error if the reader has been closed, because the C++ Read dereferences the file handle that close released without checking it first.

Source

pub fn reset(&mut self) -> Result<(), Error>

Rewinds to the start of the trace file so it can be read again.

Fails if the reader has been closed.

Source

pub fn close(&mut self) -> Result<(), Error>

Releases the underlying file handle and reports any error doing so.

Dropping the reader closes it too, so this is only needed to see a close failure. Calling it more than once is a no-op, and reading afterwards returns an error.

Trait Implementations§

Source§

impl Drop for TraceReader

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for TraceReader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.