Skip to content
Closed
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
86 changes: 69 additions & 17 deletions crates/storage/provider/src/either_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,16 @@ impl<'a> EitherWriter<'a, (), ()> {
P: DBProvider + NodePrimitivesProvider + StorageSettingsCache,
P::Tx: DbTxMut,
{
#[cfg(all(unix, feature = "rocksdb"))]
if provider.cached_storage_settings().storages_history_in_rocksdb {
return Ok(EitherWriter::RocksDB(_rocksdb_batch));
match EitherWriterDestination::storages_history(provider) {
EitherWriterDestination::Database => Ok(EitherWriter::Database(
provider.tx_ref().cursor_write::<tables::StoragesHistory>()?,
)),
#[cfg(all(unix, feature = "rocksdb"))]
EitherWriterDestination::RocksDB => Ok(EitherWriter::RocksDB(_rocksdb_batch)),
#[cfg(not(all(unix, feature = "rocksdb")))]
EitherWriterDestination::RocksDB => Err(ProviderError::UnsupportedProvider),
EitherWriterDestination::StaticFile => Err(ProviderError::UnsupportedProvider),
}

Ok(EitherWriter::Database(provider.tx_ref().cursor_write::<tables::StoragesHistory>()?))
}

/// Creates a new [`EitherWriter`] for transaction hash numbers based on storage settings.
Expand All @@ -234,14 +238,16 @@ impl<'a> EitherWriter<'a, (), ()> {
P: DBProvider + NodePrimitivesProvider + StorageSettingsCache,
P::Tx: DbTxMut,
{
#[cfg(all(unix, feature = "rocksdb"))]
if provider.cached_storage_settings().transaction_hash_numbers_in_rocksdb {
return Ok(EitherWriter::RocksDB(_rocksdb_batch));
match EitherWriterDestination::transaction_hash_numbers(provider) {
EitherWriterDestination::Database => Ok(EitherWriter::Database(
provider.tx_ref().cursor_write::<tables::TransactionHashNumbers>()?,
)),
#[cfg(all(unix, feature = "rocksdb"))]
EitherWriterDestination::RocksDB => Ok(EitherWriter::RocksDB(_rocksdb_batch)),
#[cfg(not(all(unix, feature = "rocksdb")))]
EitherWriterDestination::RocksDB => Err(ProviderError::UnsupportedProvider),
EitherWriterDestination::StaticFile => Err(ProviderError::UnsupportedProvider),
}

Ok(EitherWriter::Database(
provider.tx_ref().cursor_write::<tables::TransactionHashNumbers>()?,
))
}

/// Creates a new [`EitherWriter`] for account history based on storage settings.
Expand All @@ -253,12 +259,16 @@ impl<'a> EitherWriter<'a, (), ()> {
P: DBProvider + NodePrimitivesProvider + StorageSettingsCache,
P::Tx: DbTxMut,
{
#[cfg(all(unix, feature = "rocksdb"))]
if provider.cached_storage_settings().account_history_in_rocksdb {
return Ok(EitherWriter::RocksDB(_rocksdb_batch));
match EitherWriterDestination::accounts_history(provider) {
EitherWriterDestination::Database => Ok(EitherWriter::Database(
provider.tx_ref().cursor_write::<tables::AccountsHistory>()?,
)),
#[cfg(all(unix, feature = "rocksdb"))]
EitherWriterDestination::RocksDB => Ok(EitherWriter::RocksDB(_rocksdb_batch)),
#[cfg(not(all(unix, feature = "rocksdb")))]
EitherWriterDestination::RocksDB => Err(ProviderError::UnsupportedProvider),
EitherWriterDestination::StaticFile => Err(ProviderError::UnsupportedProvider),
}

Ok(EitherWriter::Database(provider.tx_ref().cursor_write::<tables::AccountsHistory>()?))
}
}

Expand Down Expand Up @@ -944,6 +954,48 @@ impl EitherWriterDestination {
Self::Database
}
}

/// Returns the destination for writing transaction hash numbers based on storage settings.
#[allow(clippy::missing_const_for_fn)]
pub fn transaction_hash_numbers<P>(_provider: &P) -> Self
where
P: StorageSettingsCache,
{
#[cfg(all(unix, feature = "rocksdb"))]
if _provider.cached_storage_settings().transaction_hash_numbers_in_rocksdb {
return Self::RocksDB;
}

Self::Database
}

/// Returns the destination for writing storage history based on storage settings.
#[allow(clippy::missing_const_for_fn)]
pub fn storages_history<P>(_provider: &P) -> Self
where
P: StorageSettingsCache,
{
#[cfg(all(unix, feature = "rocksdb"))]
if _provider.cached_storage_settings().storages_history_in_rocksdb {
return Self::RocksDB;
}

Self::Database
}

/// Returns the destination for writing account history based on storage settings.
#[allow(clippy::missing_const_for_fn)]
pub fn accounts_history<P>(_provider: &P) -> Self
where
P: StorageSettingsCache,
{
#[cfg(all(unix, feature = "rocksdb"))]
if _provider.cached_storage_settings().account_history_in_rocksdb {
return Self::RocksDB;
}

Self::Database
}
}

#[cfg(test)]
Expand Down
Loading