Skip to content

Commit

Permalink
Expose io-timeout/deadline read options
Browse files Browse the repository at this point in the history
  • Loading branch information
zaidoon1 committed Mar 4, 2024
1 parent 11d2fac commit 9453573
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/db_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3831,6 +3831,30 @@ impl ReadOptions {
ffi::rocksdb_readoptions_set_async_io(self.inner, c_uchar::from(v));
}
}

/// Deadline for completing an API call (Get/MultiGet/Seek/Next for now)
/// in microseconds.
/// It should be set to microseconds since epoch, i.e, gettimeofday or
/// equivalent plus allowed duration in microseconds.
/// This is best effort. The call may exceed the deadline if there is IO
/// involved and the file system doesn't support deadlines, or due to
/// checking for deadline periodically rather than for every key if
/// processing a batch
pub fn set_deadline(&mut self, microseconds: u64) {
unsafe {
ffi::rocksdb_readoptions_set_deadline(self.inner, microseconds);
}
}

/// A timeout in microseconds to be passed to the underlying FileSystem for
/// reads. As opposed to deadline, this determines the timeout for each
/// individual file read request. If a MultiGet/Get/Seek/Next etc call
/// results in multiple reads, each read can last up to io_timeout us.
pub fn set_io_timeout(&mut self, microseconds: u64) {
unsafe {
ffi::rocksdb_readoptions_set_io_timeout(self.inner, microseconds);
}
}
}

impl Default for ReadOptions {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ fn test_block_based_options() {
fn test_read_options() {
let mut read_opts = ReadOptions::default();
read_opts.set_verify_checksums(false);
read_opts.set_deadline(121);
read_opts.set_io_timeout(343);
}

#[test]
Expand Down

0 comments on commit 9453573

Please sign in to comment.