Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rocksdb): getter for inner database handle #2532

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2033](https://github.com/FuelLabs/fuel-core/pull/2033): Remove `Option<BlockHeight>` in favor of `BlockHeightQuery` where applicable.
- [2472](https://github.com/FuelLabs/fuel-core/pull/2472): Added the `amountU128` field to the `Balance` GraphQL schema, providing the total balance as a `U128`. The existing `amount` field clamps any balance exceeding `U64` to `u64::MAX`.
- [2526](https://github.com/FuelLabs/fuel-core/pull/2526): Add possibility to not have any cache set for RocksDB. Add an option to either load the RocksDB columns families on creation of the database or when the column is used.
- [2532](https://github.com/FuelLabs/fuel-core/pull/2532): Getters for inner rocksdb database handles.

### Fixed
- [2365](https://github.com/FuelLabs/fuel-core/pull/2365): Fixed the error during dry run in the case of race condition.
Expand Down
14 changes: 13 additions & 1 deletion crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ where
state_rewind_policy: StateRewindPolicy,
database_config: DatabaseConfig,
) -> Result<Self> {
let db =
Self::open_as_historical_rocksdb(path, state_rewind_policy, database_config)?;

Ok(Self::new(Arc::new(db)))
}

#[cfg(feature = "rocksdb")]
pub fn open_as_historical_rocksdb(
path: &Path,
state_rewind_policy: StateRewindPolicy,
database_config: DatabaseConfig,
) -> Result<HistoricalRocksDB<Description>> {
use anyhow::Context;

let db = HistoricalRocksDB::<Description>::default_open(
Expand All @@ -222,7 +234,7 @@ where
)
})?;

Ok(Self::new(Arc::new(db)))
Ok(db)
}

/// Converts the regular database to an unchecked database.
Expand Down
4 changes: 4 additions & 0 deletions crates/fuel-core/src/state/historical_rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ where
})
}

pub fn inner(&self) -> &RocksDb<Historical<Description>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with exposing it is that anyone can commit to the internal database bypassing the historical functionality. Maybe it is possible to just add backup functionality directly?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we can put it under the "test-helpers" feature flag?

Copy link
Member

@MitchTurner MitchTurner Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a read-only wrapper for this somehow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

draft pr: #2535

&self.db
}

pub fn default_open<P: AsRef<Path>>(
path: P,
state_rewind_policy: StateRewindPolicy,
Expand Down
5 changes: 5 additions & 0 deletions crates/fuel-core/src/state/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ impl<Description> RocksDb<Description>
where
Description: DatabaseDescription,
{
/// Allows consumers to get the inner db handle
pub fn inner(&self) -> &DB {
&self.db
}

pub fn default_open_temp(capacity: Option<usize>) -> DatabaseResult<Self> {
Self::default_open_temp_with_params(DatabaseConfig {
cache_capacity: capacity,
Expand Down
Loading