Skip to content

Commit 543d04d

Browse files
authored
feat(storage): enhance RocksDB sync and compression options (#1492)
Signed-off-by: Gaius <gaius.qi@gmail.com>
1 parent 69f5167 commit 543d04d

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

dragonfly-client-storage/src/content_linux.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ impl Content {
361361
writer.flush().await.inspect_err(|err| {
362362
error!("flush {:?} failed: {}", task_path, err);
363363
})?;
364+
debug!("finish to write piece to {:?}", task_path);
364365

365366
if length != expected_length {
366367
return Err(Error::Unknown(format!(
@@ -590,6 +591,7 @@ impl Content {
590591
writer.flush().await.inspect_err(|err| {
591592
error!("flush {:?} failed: {}", task_path, err);
592593
})?;
594+
debug!("finish to write piece to {:?}", task_path);
593595

594596
if length != expected_length {
595597
return Err(Error::Unknown(format!(

dragonfly-client-storage/src/content_macos.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ impl Content {
361361
writer.flush().await.inspect_err(|err| {
362362
error!("flush {:?} failed: {}", task_path, err);
363363
})?;
364+
debug!("finish to write piece to {:?}", task_path);
364365

365366
if length != expected_length {
366367
return Err(Error::Unknown(format!(
@@ -590,6 +591,7 @@ impl Content {
590591
writer.flush().await.inspect_err(|err| {
591592
error!("flush {:?} failed: {}", task_path, err);
592593
})?;
594+
debug!("finish to write piece to {:?}", task_path);
593595

594596
if length != expected_length {
595597
return Err(Error::Unknown(format!(

dragonfly-client-storage/src/server/tcp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ impl TCPServerHandler {
520520
writer.flush().await.inspect_err(|err| {
521521
error!("flush failed: {}", err);
522522
})?;
523+
debug!("finished writing stream to tcp writer");
523524

524525
Ok(())
525526
}

dragonfly-client-storage/src/storage_engine/rocksdb.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ impl RocksdbStorageEngine {
6666
/// DEFAULT_LOG_MAX_FILES is the default max log files for rocksdb.
6767
const DEFAULT_LOG_MAX_FILES: usize = 10;
6868

69+
/// DEFAULT_BYTES_PER_SYNC is the default bytes per sync for rocksdb.
70+
const DEFAULT_BYTES_PER_SYNC: u64 = 2 * 1024 * 1024;
71+
6972
/// open opens a rocksdb storage engine with the given directory and column families.
7073
pub fn open(dir: &Path, log_dir: &PathBuf, cf_names: &[&str], keep: bool) -> Result<Self> {
7174
info!("initializing metadata directory: {:?} {:?}", dir, cf_names);
@@ -76,7 +79,7 @@ impl RocksdbStorageEngine {
7679

7780
// Optimize compression.
7881
options.set_compression_type(rocksdb::DBCompressionType::Lz4);
79-
options.set_bottommost_compression_type(rocksdb::DBCompressionType::Zstd);
82+
options.set_bottommost_compression_type(rocksdb::DBCompressionType::Lz4);
8083

8184
// Improved parallelism.
8285
options.increase_parallelism(num_cpus::get() as i32);
@@ -85,6 +88,10 @@ impl RocksdbStorageEngine {
8588
Self::DEFAULT_MAX_BACKGROUND_JOBS,
8689
));
8790

91+
// Set rocksdb sync options.
92+
options.set_use_fsync(false);
93+
options.set_bytes_per_sync(Self::DEFAULT_BYTES_PER_SYNC);
94+
8895
// Set rocksdb log options.
8996
options.set_db_log_dir(log_dir);
9097
options.set_log_level(rocksdb::LogLevel::Info);
@@ -155,7 +162,10 @@ impl Operations for RocksdbStorageEngine {
155162
/// put puts the object by key.
156163
fn put<O: DatabaseObject>(&self, key: &[u8], value: &O) -> Result<()> {
157164
let cf = cf_handle::<O>(self)?;
158-
self.put_cf(cf, key, value.serialized()?)
165+
let mut options = rocksdb::WriteOptions::default();
166+
options.set_sync(false);
167+
168+
self.put_cf_opt(cf, key, value.serialized()?, &options)
159169
.or_err(ErrorType::StorageError)?;
160170
Ok(())
161171
}

0 commit comments

Comments
 (0)