-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resharding): flat storage resharding children catchup (#12312)
PR to add children catchup step for flat storages created as a result of a parent shard split. In previous iterations, the two children shards were populated in a background task from the flat storage of the parent at height `last block of old shard layout` (post-processing). Since the task mentioned above takes a long time and the children are active shards in the `first block of the new shard layout` their flat storage accumulates a lot of deltas. The catchup step applies delta in the background, then finalizes creation of child flat storage, and triggers a possible memtrie rebuild. Part of #12174
- Loading branch information
Showing
10 changed files
with
696 additions
and
123 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,88 @@ | ||
use super::types::FlatStorageSplitShardRequest; | ||
use near_async::messaging::{self, Handler}; | ||
use super::types::{ | ||
FlatStorageShardCatchupRequest, FlatStorageSplitShardRequest, MemtrieReloadRequest, | ||
}; | ||
use crate::flat_storage_resharder::{FlatStorageResharder, FlatStorageReshardingTaskStatus}; | ||
use crate::ChainStore; | ||
use near_async::futures::{DelayedActionRunner, DelayedActionRunnerExt}; | ||
use near_async::messaging::{self, Handler, HandlerWithContext}; | ||
use near_primitives::hash::CryptoHash; | ||
use near_primitives::types::BlockHeight; | ||
use near_store::{ShardUId, Store}; | ||
use time::Duration; | ||
|
||
/// Dedicated actor for resharding V3. | ||
pub struct ReshardingActor {} | ||
pub struct ReshardingActor { | ||
chain_store: ChainStore, | ||
} | ||
|
||
impl messaging::Actor for ReshardingActor {} | ||
|
||
impl Handler<FlatStorageSplitShardRequest> for ReshardingActor { | ||
fn handle(&mut self, msg: FlatStorageSplitShardRequest) { | ||
self.handle_flat_storage_split_shard_request(msg); | ||
match msg.resharder.split_shard_task() { | ||
FlatStorageReshardingTaskStatus::Successful { .. } => { | ||
// All good. | ||
} | ||
FlatStorageReshardingTaskStatus::Failed => { | ||
panic!("impossible to recover from a flat storage split shard failure!") | ||
} | ||
FlatStorageReshardingTaskStatus::Cancelled => { | ||
// The task has been cancelled. Nothing else to do. | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl HandlerWithContext<FlatStorageShardCatchupRequest> for ReshardingActor { | ||
fn handle( | ||
&mut self, | ||
msg: FlatStorageShardCatchupRequest, | ||
ctx: &mut dyn DelayedActionRunner<Self>, | ||
) { | ||
// Shard catchup task is delayed and could get postponed several times. This must be | ||
// done to cover the scenario in which catchup is triggered so fast that the initial | ||
// state of the new flat storage is beyond the chain final tip. | ||
ctx.run_later( | ||
"ReshardingActor FlatStorageShardCatchup", | ||
Duration::milliseconds(100), | ||
move |act, _| { | ||
act.handle_flat_storage_shard_catchup( | ||
msg.resharder, | ||
msg.shard_uid, | ||
msg.flat_head_block_hash, | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
impl Handler<MemtrieReloadRequest> for ReshardingActor { | ||
fn handle(&mut self, _msg: MemtrieReloadRequest) { | ||
// TODO | ||
} | ||
} | ||
|
||
impl ReshardingActor { | ||
pub fn new() -> Self { | ||
Self {} | ||
pub fn new(store: Store, genesis_height: BlockHeight) -> Self { | ||
Self { chain_store: ChainStore::new(store, genesis_height, false) } | ||
} | ||
|
||
pub fn handle_flat_storage_split_shard_request(&mut self, msg: FlatStorageSplitShardRequest) { | ||
msg.resharder.split_shard_task(); | ||
fn handle_flat_storage_shard_catchup( | ||
&self, | ||
resharder: FlatStorageResharder, | ||
shard_uid: ShardUId, | ||
flat_head_block_hash: CryptoHash, | ||
) { | ||
match resharder.shard_catchup_task(shard_uid, flat_head_block_hash, &self.chain_store) { | ||
FlatStorageReshardingTaskStatus::Successful { .. } => { | ||
// All good. | ||
} | ||
FlatStorageReshardingTaskStatus::Failed => { | ||
panic!("impossible to recover from a flat storage shard catchup failure!") | ||
} | ||
FlatStorageReshardingTaskStatus::Cancelled => { | ||
// The task has been cancelled. Nothing else to do. | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters