Skip to main content

WriteOptions

Struct WriteOptions 

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

Optionally disable WAL or sync for this write.

§Examples

Making an unsafe write of a batch:

use rust_rocksdb::{DB, Options, WriteBatch, WriteOptions};

let tempdir = tempfile::Builder::new()
    .prefix("_path_for_rocksdb_storageY1")
    .tempdir()
    .expect("Failed to create temporary path for the _path_for_rocksdb_storageY1");
let path = tempdir.path();
{
    let db = DB::open_default(path).unwrap();
    let mut batch = WriteBatch::default();
    batch.put(b"my key", b"my value");
    batch.put(b"key2", b"value2");
    batch.put(b"key3", b"value3");

    let mut write_options = WriteOptions::default();
    write_options.set_sync(false);
    write_options.disable_wal(true);

    db.write_opt(&batch, &write_options);
}
let _ = DB::destroy(&Options::default(), path);

Implementations§

Source§

impl WriteOptions

Source

pub fn new() -> WriteOptions

Source

pub fn set_sync(&mut self, sync: bool)

Sets the sync mode. If true, the write will be flushed from the operating system buffer cache before the write is considered complete. If this flag is true, writes will be slower.

Default: false

Source

pub fn disable_wal(&mut self, disable: bool)

Sets whether WAL should be active or not. If true, writes will not first go to the write ahead log, and the write may got lost after a crash.

Default: false

Source

pub fn set_ignore_missing_column_families(&mut self, ignore: bool)

If true and if user is trying to write to column families that don’t exist (they were dropped), ignore the write (don’t return an error). If there are multiple writes in a WriteBatch, other writes will succeed.

Default: false

Source

pub fn set_no_slowdown(&mut self, no_slowdown: bool)

If true and we need to wait or sleep for the write request, fails immediately with Status::Incomplete().

Default: false

Source

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

If true, this write request is of lower priority if compaction is behind. In this case, no_slowdown = true, the request will be cancelled immediately with Status::Incomplete() returned. Otherwise, it will be slowed down. The slowdown value is determined by RocksDB to guarantee it introduces minimum impacts to high priority writes.

Default: false

Source

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

If true, writebatch will maintain the last insert positions of each memtable as hints in concurrent write. It can improve write performance in concurrent writes if keys in one writebatch are sequential. In non-concurrent writes (when concurrent_memtable_writes is false) this option will be ignored.

Default: false

Source

pub fn set_io_activity(&mut self, val: c_int)

EXPERIMENTAL

Source

pub fn get_io_activity(&self) -> c_int

Returns the value of the io_activity option.

Source

pub fn set_protection_bytes_per_key(&mut self, val: usize)

protection_bytes_per_key is the number of bytes used to store protection information for each key entry. Currently supported values are zero (disabled) and eight.

Default: zero (disabled).

Source

pub fn get_protection_bytes_per_key(&self) -> usize

Returns the value of the protection_bytes_per_key option.

Source

pub fn set_rate_limiter_priority(&mut self, val: c_int)

For file reads associated with this option, charge the internal rate limiter (see DBOptions::rate_limiter) at the specified priority. The special value Env::IO_TOTAL disables charging the rate limiter.

The rate limiting is bypassed no matter this option’s value for file reads on plain tables (these can exist when ColumnFamilyOptions::table_factory is a PlainTableFactory) and cuckoo tables (these can exist when ColumnFamilyOptions::table_factory is a CuckooTableFactory).

The bytes charged to rate limiter may not exactly match the file read bytes since there are some seemingly insignificant reads, like for file headers/footers, that we currently do not charge to rate limiter.

Source

pub fn get_rate_limiter_priority(&self) -> c_int

Returns the value of the rate_limiter_priority option.

Source

pub fn get_disable_wal(&self) -> bool

Returns the current disable_wal setting.

See Self::disable_wal for what this controls.

Source

pub fn get_ignore_missing_column_families(&self) -> bool

Returns the current ignore_missing_column_families setting.

See Self::set_ignore_missing_column_families for what this controls.

Source

pub fn get_low_pri(&self) -> bool

Returns the current low_pri setting.

See Self::set_low_pri for what this controls.

Source

pub fn get_memtable_insert_hint_per_batch(&self) -> bool

Returns the current memtable_insert_hint_per_batch setting.

See Self::set_memtable_insert_hint_per_batch for what this controls.

Source

pub fn get_no_slowdown(&self) -> bool

Returns the current no_slowdown setting.

See Self::set_no_slowdown for what this controls.

Source

pub fn get_sync(&self) -> bool

Returns the current sync setting.

See Self::set_sync for what this controls.

Trait Implementations§

Source§

impl Default for WriteOptions

Source§

fn default() -> Self

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

impl Drop for WriteOptions

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 WriteOptions

Source§

impl Sync for WriteOptions

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.