Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions crates/storage/provider/src/providers/rocksdb/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ use std::{
};
use tracing::instrument;

/// Returns [`WriteOptions`] with WAL sync enabled for crash durability.
fn synced_write_options() -> WriteOptions {
let mut opts = WriteOptions::default();
opts.set_sync(true);
opts
}

/// Pending `RocksDB` batches type alias.
pub(crate) type PendingRocksDBBatches = Arc<Mutex<Vec<WriteBatchWithTransaction<true>>>>;

Expand Down Expand Up @@ -765,7 +772,7 @@ impl RocksDBProvider {
/// # Panics
/// Panics if the provider is in read-only mode.
pub fn tx(&self) -> RocksTx<'_> {
let write_options = WriteOptions::default();
let write_options = synced_write_options();
let txn_options = OptimisticTransactionOptions::default();
let inner = self.0.db_rw().transaction_opt(&write_options, &txn_options);
RocksTx { inner, provider: self }
Expand Down Expand Up @@ -1268,7 +1275,7 @@ impl RocksDBProvider {
/// Panics if the provider is in read-only mode.
#[instrument(level = "debug", target = "providers::rocksdb", skip_all, fields(batch_len = batch.len(), batch_size = batch.size_in_bytes()))]
pub fn commit_batch(&self, batch: WriteBatchWithTransaction<true>) -> ProviderResult<()> {
self.0.db_rw().write_opt(batch, &WriteOptions::default()).map_err(|e| {
self.0.db_rw().write_opt(batch, &synced_write_options()).map_err(|e| {
ProviderError::Database(DatabaseError::Commit(DatabaseErrorInfo {
message: e.to_string().into(),
code: -1,
Expand Down Expand Up @@ -1751,14 +1758,12 @@ impl<'a> RocksDBBatch<'a> {
"Auto-committing RocksDB batch"
);
let old_batch = std::mem::take(&mut self.inner);
self.provider.0.db_rw().write_opt(old_batch, &WriteOptions::default()).map_err(
|e| {
ProviderError::Database(DatabaseError::Commit(DatabaseErrorInfo {
message: e.to_string().into(),
code: -1,
}))
},
)?;
self.provider.0.db_rw().write_opt(old_batch, &synced_write_options()).map_err(|e| {
ProviderError::Database(DatabaseError::Commit(DatabaseErrorInfo {
message: e.to_string().into(),
code: -1,
}))
})?;
}
Ok(())
}
Expand All @@ -1771,7 +1776,7 @@ impl<'a> RocksDBBatch<'a> {
/// Panics if the provider is in read-only mode.
#[instrument(level = "debug", target = "providers::rocksdb", skip_all, fields(batch_len = self.inner.len(), batch_size = self.inner.size_in_bytes()))]
pub fn commit(self) -> ProviderResult<()> {
self.provider.0.db_rw().write_opt(self.inner, &WriteOptions::default()).map_err(|e| {
self.provider.0.db_rw().write_opt(self.inner, &synced_write_options()).map_err(|e| {
ProviderError::Database(DatabaseError::Commit(DatabaseErrorInfo {
message: e.to_string().into(),
code: -1,
Expand Down
Loading