Skip to main content

EnvOptions

Struct EnvOptions 

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

Per-file I/O settings handed to an Env when it opens a file.

A fresh instance carries the values a default DBOptions would produce. Each setter below names the default it starts from.

See rocksdb/include/rocksdb/env.h.

Implementations§

Source§

impl EnvOptions

Source

pub fn set_use_mmap_reads(&mut self, v: bool)

If true, reads go through mmap instead of read.

Not recommended on a 32-bit OS, where address space runs out well before the data does.

The POSIX file system ignores set_use_direct_reads while this is on.

Default: false

Source

pub fn get_use_mmap_reads(&self) -> bool

Returns the current use_mmap_reads setting.

See Self::set_use_mmap_reads for what this controls.

Source

pub fn set_use_mmap_writes(&mut self, v: bool)

If true, writes go through mmap instead of write.

The POSIX file system ignores set_use_direct_writes while this is on.

Default: false

Source

pub fn get_use_mmap_writes(&self) -> bool

Returns the current use_mmap_writes setting.

See Self::set_use_mmap_writes for what this controls.

Source

pub fn set_use_direct_reads(&mut self, v: bool)

If true, read this file with direct I/O, bypassing the page cache.

This is the file-level flag, not Options::set_use_direct_reads. The DB option decides what RocksDB puts into the EnvOptions it builds for its own files. This one applies to whatever the caller opens with these options, and nothing propagates between the two.

On POSIX, Linux and friends pass O_DIRECT at open time while macOS sets F_NOCACHE on the descriptor instead. Either way the flag is ignored while set_use_mmap_reads is on.

Default: false

Source

pub fn get_use_direct_reads(&self) -> bool

Returns the current use_direct_reads setting.

See Self::set_use_direct_reads for what this controls.

Source

pub fn set_use_direct_writes(&mut self, v: bool)

If true, write this file with direct I/O, bypassing the page cache.

This is the file-level flag, not Options::set_use_direct_io_for_flush_and_compaction. The DB option decides what RocksDB puts into the EnvOptions it builds for its own files. This one applies to whatever the caller opens with these options, and nothing propagates between the two.

On POSIX, Linux and friends pass O_DIRECT at open time while macOS sets F_NOCACHE on the descriptor instead. Either way the flag is ignored while set_use_mmap_writes is on.

Default: false

Source

pub fn get_use_direct_writes(&self) -> bool

Returns the current use_direct_writes setting.

See Self::set_use_direct_writes for what this controls.

Source

pub fn set_allow_fallocate(&mut self, v: bool)

If false, RocksDB skips the fallocate calls it would otherwise make to preallocate space for a file.

Linux only. Builds without fallocate compile the calls out, so the setting has no effect there.

Default: true

Source

pub fn get_allow_fallocate(&self) -> bool

Returns the current allow_fallocate setting.

See Self::set_allow_fallocate for what this controls.

Source

pub fn set_fd_cloexec(&mut self, v: bool)

If true, opened descriptors get FD_CLOEXEC so they are not inherited across exec.

This maps to EnvOptions::set_fd_cloexec. POSIX only, ignored on Windows.

Default: true

Source

pub fn get_fd_cloexec(&self) -> bool

Returns the current fd_cloexec setting.

See Self::set_fd_cloexec for what this controls.

Source

pub fn set_bytes_per_sync(&mut self, v: u64)

Asks the OS to write the file back to disk incrementally, one request per this many bytes written. 0 turns it off.

This spreads writeback out instead of leaving it all for the final sync. It is not a durability guarantee on its own.

Default: 0

Source

pub fn get_bytes_per_sync(&self) -> u64

Returns the current bytes_per_sync setting in bytes.

See Self::set_bytes_per_sync for what this controls.

Source

pub fn set_strict_bytes_per_sync(&mut self, v: bool)

When true, guarantees at most bytes_per_sync bytes are queued for writeback at any moment.

On Linux this waits for the previous sync_file_range to finish before issuing the next one, so compression and other processing keep running in the gap and only I/O falling behind blocks. Everywhere else it falls back to a blocking WritableFile::Sync, which stops processing and I/O from overlapping at all.

This adds no durability guarantee, because sync_file_range does not write out metadata.

Default: false

Source

pub fn get_strict_bytes_per_sync(&self) -> bool

Returns the current strict_bytes_per_sync setting.

See Self::set_strict_bytes_per_sync for what this controls.

Source

pub fn set_fallocate_with_keep_size(&mut self, v: bool)

If true, preallocation passes FALLOC_FL_KEEP_SIZE, so the reported file size does not grow with the preallocated space. If false, preallocation grows the file size too, which is faster for workloads that sync on every write.

Linux only, and only when allow_fallocate is on. RocksDB itself uses true for MANIFEST writes and false for WAL writes.

Default: true

Source

pub fn get_fallocate_with_keep_size(&self) -> bool

Returns the current fallocate_with_keep_size setting.

See Self::set_fallocate_with_keep_size for what this controls.

Source

pub fn set_compaction_readahead_size(&mut self, v: usize)

If non-zero, compaction reads this many bytes at a time. On spinning disks this turns compaction’s random reads into sequential ones.

Default: 2 MiB

Source

pub fn get_compaction_readahead_size(&self) -> usize

Returns the current compaction_readahead_size setting in bytes.

See Self::set_compaction_readahead_size for what this controls.

Source

pub fn set_writable_file_max_buffer_size(&mut self, v: usize)

Caps the buffer WritableFileWriter uses.

With buffered I/O the buffer grows up to this limit. With direct I/O it is fixed at this size, so that write requests stay aligned even when the logical sector size is unusual.

Default: 1 MiB

Source

pub fn get_writable_file_max_buffer_size(&self) -> usize

Returns the current writable_file_max_buffer_size setting in bytes.

See Self::set_writable_file_max_buffer_size for what this controls.

Source

pub fn set_ratelimiter( &mut self, rate_bytes_per_sec: i64, refill_period_us: i64, fairness: i32, )

Rate limits writes to files opened with these options.

The arguments match Options::set_ratelimiter, and so does the handling: the C API’s rocksdb_ratelimiter_t is only a handle around a shared_ptr<RateLimiter>, and rocksdb_envoptions_set_rate_limiter copies that shared_ptr into the options object (see rocksdb_envoptions_t::rate_limiter in db/c.cc). The limiter stays alive as long as these options do, so the handle is destroyed right after the call.

There is no getter and no way to clear this. The C API exposes only the setter.

Default: no limit

Trait Implementations§

Source§

impl Default for EnvOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for EnvOptions

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 EnvOptions

Source§

impl Sync for EnvOptions

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.