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

Added handling of incorrect shutdown of the off-chain GraphQL worker #2004

Merged
merged 60 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
fea24a3
Extract `HistoricalView` trait from the `AtomicView`
xgreenx Jun 26, 2024
4c20273
Updated changelog
xgreenx Jun 26, 2024
5119dbe
Removed not related code to the chagne
xgreenx Jun 26, 2024
4b3aecb
Fixed tests
xgreenx Jun 26, 2024
b06c622
Fixed the column
xgreenx Jun 26, 2024
61f1059
Move all functionality from the `Database` to the views
xgreenx Jun 26, 2024
c5ec5bf
Moved `latest_height` to `HistoricalView` trait
xgreenx Jun 26, 2024
db90520
Merge branch 'refs/heads/feature/historical-view-trait' into feature/…
xgreenx Jun 26, 2024
2b9eadc
Improved readability
xgreenx Jun 26, 2024
c61477f
Merge branch 'refs/heads/master' into feature/iteratable-view
xgreenx Jun 26, 2024
c3d6f66
Merge branch 'master' into feature/iteratable-view
xgreenx Jun 26, 2024
29d543e
Updated CHANGELOG.md
xgreenx Jun 26, 2024
682d256
Simplify imports
xgreenx Jun 26, 2024
11d1d28
Make CI happy
xgreenx Jun 26, 2024
187ec91
Added the actual implementation for the `AtomicView::latest_view`
xgreenx Jun 26, 2024
ec86d61
Updated CHANGELOG.md
xgreenx Jun 26, 2024
22f6a63
Merge branch 'master' into feature/iteratable-view
xgreenx Jun 27, 2024
46d0eca
Merge branch 'master' into feature/iteratable-view
xgreenx Jun 27, 2024
19f7433
Merge branch 'feature/iteratable-view' into feature/atomic-latest-view
xgreenx Jun 27, 2024
f642a4a
Simplify signature of the constracutor
xgreenx Jun 27, 2024
c9f4ca2
Merge branch 'refs/heads/feature/iteratable-view' into feature/atomic…
xgreenx Jun 27, 2024
7ad0907
The actual implementation of the historical view for RocksDB
xgreenx Jun 27, 2024
58c698e
Renamed `IterableView` into `IterableKeyValueView`
xgreenx Jun 27, 2024
e06ca6e
Merge branch 'refs/heads/feature/atomic-latest-view' into feature/his…
xgreenx Jun 27, 2024
e6a02d6
Merged base branch
xgreenx Jun 27, 2024
d5b6535
Renamed `IterableView` to `IterableKeyValueView`
xgreenx Jun 27, 2024
0bf402b
Merge branch 'refs/heads/feature/iteratable-view' into feature/atomic…
xgreenx Jun 27, 2024
ffc6481
Merge branch 'refs/heads/feature/atomic-latest-view' into feature/his…
xgreenx Jun 27, 2024
97983c5
Merge branch 'refs/heads/master' into feature/atomic-latest-view
xgreenx Jun 28, 2024
ccc0a2c
Added more tets and rollback fucntionality
xgreenx Jun 28, 2024
8513901
Use explicit getter instead of deref
xgreenx Jun 28, 2024
f4e8bbf
Merge branch 'feature/atomic-latest-view' into feature/historical-vie…
xgreenx Jun 28, 2024
c733a48
Merge branch 'refs/heads/master' into feature/historical-view-impleme…
xgreenx Jun 28, 2024
eeb75ac
Added rollback command and e2e tests to verify the whole behaviour.
xgreenx Jun 29, 2024
c43006a
Updated CHANGELOG.md
xgreenx Jun 29, 2024
f06508c
Merge branch 'master' into feature/historical-view-implementation
xgreenx Jul 1, 2024
5bd9e44
Fixed the comment
xgreenx Jul 2, 2024
0020b2f
Merge branch 'master' into feature/historical-view-implementation
xgreenx Jul 2, 2024
df44f88
Added handling of incorrect shutdown of the off-chain GraphQL worker
xgreenx Jul 2, 2024
271d5fa
Stop off-chain worker on error.
xgreenx Jul 2, 2024
8e3b865
Updated CHANGELOG.md
xgreenx Jul 2, 2024
5041f4b
Renamed the argument to `continue-services-on-error`
xgreenx Jul 2, 2024
af88cc9
Merge branch 'master' into feature/historical-view-implementation
xgreenx Jul 2, 2024
cf17061
Merge branch 'feature/historical-view-implementation' into feature/re…
xgreenx Jul 2, 2024
7e49992
Applied comments from the PR
xgreenx Jul 2, 2024
4d56031
Merge branch 'master' into feature/historical-view-implementation
xgreenx Jul 2, 2024
3acfe68
Merge branch 'feature/historical-view-implementation' into feature/re…
xgreenx Jul 2, 2024
c466c13
Merge branch 'master' into feature/historical-view-implementation
xgreenx Jul 3, 2024
b0ab401
Merge branch 'feature/historical-view-implementation' into feature/re…
xgreenx Jul 3, 2024
ee634e7
Use better naming for variable=)
xgreenx Jul 3, 2024
2633cec
Merge branch 'master' into feature/historical-view-implementation
xgreenx Jul 4, 2024
562171c
Merge `history` and original databases into one
xgreenx Jul 4, 2024
34067fe
Merge branch 'feature/historical-view-implementation' into feature/re…
xgreenx Jul 4, 2024
6885cb9
Return error instead of panic
xgreenx Jul 4, 2024
5ef77f6
Merge branch 'refs/heads/feature/historical-view-implementation' into…
xgreenx Jul 5, 2024
4d661e1
Merge branch 'refs/heads/master' into feature/recover-off-chain-database
xgreenx Jul 5, 2024
2da03d7
Stop in tests on error
xgreenx Jul 5, 2024
9994176
Merge branch 'master' into feature/recover-off-chain-database
xgreenx Jul 5, 2024
69c6e9f
Merge branch 'master' into feature/recover-off-chain-database
xgreenx Jul 5, 2024
4a4b01c
Merge branch 'master' into feature/recover-off-chain-database
Dentosal Jul 5, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- [#2004](https://github.com/FuelLabs/fuel-core/pull/2004): Added new CLI argument `continue-services-on-error` to control internal flow of services.
- [#2004](https://github.com/FuelLabs/fuel-core/pull/2004): Added handling of incorrect shutdown of the off-chain GraphQL worker by using state rewind feature.
- [#2007](https://github.com/FuelLabs/fuel-core/pull/2007): Improved metrics:
- Added database metrics per column.
- Added statistic about commit time of each database.
Expand Down
8 changes: 7 additions & 1 deletion bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub struct Command {
/// The default value is 7 days = 604800 blocks.
///
/// The `BlockHeight` is `u32`, meaning the maximum possible number of blocks
/// is less than 137 years. `2^32 / 24 / 60 / 60/ 365` = `136.1925195332` years.
/// is less than 137 years. `2^32 / 24 / 60 / 60 / 365` = `136.1925195332` years.
/// If the value is 136 years or more, the rewind feature is enabled for all blocks.
#[clap(long = "state-rewind-duration", default_value = "7d", env)]
pub state_rewind_duration: humantime::Duration,
Expand All @@ -141,6 +141,10 @@ pub struct Command {
#[arg(name = "DB_PRUNE", long = "db-prune", env, default_value = "false")]
pub db_prune: bool,

/// The determines whether to continue the services on internal error or not.
#[clap(long = "continue-services-on-error", default_value = "false", env)]
pub continue_on_error: bool,

/// Should be used for local development only. Enabling debug mode:
/// - Allows GraphQL Endpoints to arbitrarily advance blocks.
/// - Enables debugger GraphQL Endpoints.
Expand Down Expand Up @@ -236,6 +240,7 @@ impl Command {
state_rewind_duration,
db_prune,
snapshot,
continue_on_error,
vm_backtrace,
debug,
utxo_validation,
Expand Down Expand Up @@ -384,6 +389,7 @@ impl Command {
snapshot_reader,
debug,
native_executor_version,
continue_on_error,
utxo_validation,
block_production: trigger,
vm: VMConfig {
Expand Down
4 changes: 3 additions & 1 deletion crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ where
);
};
self.inner_storage().data.rollback_last_block()?;
*lock = height.rollback_height();
let new_height = height.rollback_height();
*lock = new_height;
tracing::info!("Rollback to the height {:?} was successful", new_height);

Ok(())
}
Expand Down
8 changes: 8 additions & 0 deletions crates/fuel-core/src/database/sealed_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ impl OnChainIterableKeyValueView {
}
}

pub fn genesis_height(&self) -> StorageResult<Option<BlockHeight>> {
Ok(self
.iter_all::<FuelBlocks>(Some(IterDirection::Forward))
.next()
.transpose()?
.map(|(height, _)| height))
}

pub fn genesis_block(&self) -> StorageResult<Option<CompressedBlock>> {
Ok(self
.iter_all::<FuelBlocks>(Some(IterDirection::Forward))
Expand Down
22 changes: 18 additions & 4 deletions crates/fuel-core/src/graphql_api/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,24 @@ pub mod worker {
},
};

pub trait Transactional: Send + Sync {
type Transaction<'a>: OffChainDatabase
pub trait OnChainDatabase: Send + Sync {
/// Returns the latest block height.
fn latest_height(&self) -> StorageResult<Option<BlockHeight>>;
}

pub trait OffChainDatabase: Send + Sync {
type Transaction<'a>: OffChainDatabaseTransaction
where
Self: 'a;

/// Returns the latest block height.
fn latest_height(&self) -> StorageResult<Option<BlockHeight>>;

/// Creates a write database transaction.
fn transaction(&mut self) -> Self::Transaction<'_>;
}

pub trait OffChainDatabase:
pub trait OffChainDatabaseTransaction:
StorageMutate<OwnedMessageIds, Error = StorageError>
+ StorageMutate<OwnedCoins, Error = StorageError>
+ StorageMutate<FuelBlockIdsToHeights, Error = StorageError>
Expand Down Expand Up @@ -331,9 +339,15 @@ pub mod worker {
fn commit(self) -> StorageResult<()>;
}

pub trait BlockImporter {
pub trait BlockImporter: Send + Sync {
/// Returns a stream of imported block.
fn block_events(&self) -> BoxStream<SharedImportResult>;

/// Return the import result at the given height.
fn block_event_at_height(
&self,
height: Option<BlockHeight>,
) -> anyhow::Result<SharedImportResult>;
}

pub trait TxPool: Send + Sync {
Expand Down
4 changes: 2 additions & 2 deletions crates/fuel-core/src/graphql_api/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
TransactionStatuses,
},
},
graphql_api::ports::worker::OffChainDatabase,
graphql_api::ports::worker::OffChainDatabaseTransaction,
};
use fuel_core_storage::{
kv_store::{
Expand Down Expand Up @@ -116,7 +116,7 @@ impl StorageColumn for Column {
}
}

impl<S> OffChainDatabase for StorageTransaction<S>
impl<S> OffChainDatabaseTransaction for StorageTransaction<S>
where
S: KeyValueInspect<Column = Column> + Modifiable,
StorageTransaction<S>: StorageMutate<OwnedMessageIds, Error = StorageError>
Expand Down
Loading
Loading