Skip to content

Commit 7af245a

Browse files
committed
Restore the environment variable to enable write sync (#24974)
Default fsync to false, but allow enabling it with an env var. Deployment
1 parent dd1daa5 commit 7af245a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

crates/typed-store/src/rocks/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use std::{
3939
marker::PhantomData,
4040
ops::RangeBounds,
4141
path::{Path, PathBuf},
42-
sync::Arc,
42+
sync::{Arc, OnceLock},
4343
time::Duration,
4444
};
4545
use std::{collections::HashSet, ffi::CStr};
@@ -54,6 +54,13 @@ use tracing::{debug, error, instrument, warn};
5454
const ROCKSDB_PROPERTY_TOTAL_BLOB_FILES_SIZE: &CStr =
5555
unsafe { CStr::from_bytes_with_nul_unchecked("rocksdb.total-blob-file-size\0".as_bytes()) };
5656

57+
static WRITE_SYNC_ENABLED: OnceLock<bool> = OnceLock::new();
58+
59+
fn write_sync_enabled() -> bool {
60+
*WRITE_SYNC_ENABLED
61+
.get_or_init(|| std::env::var("SUI_DB_SYNC_TO_DISK").is_ok_and(|v| v == "1" || v == "true"))
62+
}
63+
5764
#[cfg(test)]
5865
mod tests;
5966

@@ -1201,7 +1208,11 @@ impl DBBatch {
12011208
#[instrument(level = "trace", skip_all, err)]
12021209
pub fn write(self) -> Result<(), TypedStoreError> {
12031210
let mut write_options = rocksdb::WriteOptions::default();
1204-
write_options.set_sync(true);
1211+
1212+
if write_sync_enabled() {
1213+
write_options.set_sync(true);
1214+
}
1215+
12051216
self.write_opt(write_options)
12061217
}
12071218

crates/typed-store/src/rocks/options.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ pub struct ReadWriteOptions {
3838
/// When set, debug log the hash of the key and value bytes when inserting to
3939
/// this table.
4040
pub log_value_hash: bool,
41-
/// Whether to sync to disk on every write.
42-
pub sync_writes: bool,
4341
}
4442

4543
impl ReadWriteOptions {
@@ -65,7 +63,6 @@ impl Default for ReadWriteOptions {
6563
Self {
6664
ignore_range_deletions: true,
6765
log_value_hash: false,
68-
sync_writes: false,
6966
}
7067
}
7168
}

0 commit comments

Comments
 (0)