1616//
1717
1818use crate :: indexer_impl:: IndexerNodeImpl ;
19- use crate :: recover:: { Recover , RecoverConfig } ;
19+ use crate :: recover:: { Recover , RecoverConfig , RecoverType } ;
2020use crate :: rollup_executor:: RollupExecutorConfig ;
2121use crate :: storage_node_light_impl:: { StorageNodeV2Config , StorageNodeV2Impl } ;
2222use crate :: system_impl:: SystemImpl ;
@@ -35,7 +35,7 @@ use db3_storage::db_store_v2::{DBStoreV2, DBStoreV2Config};
3535use db3_storage:: doc_store:: DocStoreConfig ;
3636use db3_storage:: key_store:: KeyStore ;
3737use db3_storage:: key_store:: KeyStoreConfig ;
38- use db3_storage:: mutation_store:: MutationStoreConfig ;
38+ use db3_storage:: mutation_store:: { MutationStore , MutationStoreConfig } ;
3939use db3_storage:: state_store:: { StateStore , StateStoreConfig } ;
4040use db3_storage:: system_store:: { SystemRole , SystemStore , SystemStoreConfig } ;
4141use ethers:: prelude:: LocalWallet ;
@@ -183,6 +183,35 @@ pub enum RecoverCommand {
183183 verbose : bool ,
184184 } ,
185185 // TODO: support recover rollup
186+ #[ clap( name = "rollup" ) ]
187+ Rollup {
188+ /// The database path for mutation
189+ #[ clap( long, default_value = "./mutation_db" ) ]
190+ mutation_db_path : String ,
191+ /// The database path for state
192+ #[ clap( long, default_value = "./state_db" ) ]
193+ state_db_path : String ,
194+ /// The database path for doc db
195+ #[ clap( long, default_value = "./doc_db" ) ]
196+ doc_db_path : String ,
197+ #[ clap( short, long, default_value = "./rollup_meta_db" ) ]
198+ meta_db_path : String ,
199+ #[ clap( short, long, default_value = "./keys" ) ]
200+ key_root_path : String ,
201+ #[ clap( short, long, default_value = "./recover_rollup_temp" ) ]
202+ recover_temp_path : String ,
203+ #[ clap(
204+ short,
205+ long,
206+ default_value = "0x0000000000000000000000000000000000000000"
207+ ) ]
208+ admin_addr : String ,
209+ /// this is just for upgrade the node
210+ #[ clap( long, default_value = "100000" ) ]
211+ doc_id_start : i64 ,
212+ #[ clap( short, long) ]
213+ verbose : bool ,
214+ } ,
186215}
187216impl DB3Command {
188217 fn build_wallet ( key_root_path : & str ) -> std:: result:: Result < LocalWallet , DB3Error > {
@@ -382,6 +411,41 @@ impl DB3Command {
382411 info ! ( "exit standalone indexer" )
383412 }
384413 DB3Command :: Recover { cmd } => match cmd {
414+ RecoverCommand :: Rollup {
415+ mutation_db_path,
416+ state_db_path,
417+ doc_db_path,
418+ meta_db_path,
419+ key_root_path,
420+ recover_temp_path,
421+ admin_addr,
422+ doc_id_start,
423+ verbose,
424+ } => {
425+ let log_level = if verbose {
426+ LevelFilter :: DEBUG
427+ } else {
428+ LevelFilter :: INFO
429+ } ;
430+
431+ tracing_subscriber:: fmt ( ) . with_max_level ( log_level) . init ( ) ;
432+ info ! ( "{ABOUT}" ) ;
433+ let recover = Self :: create_recover (
434+ mutation_db_path,
435+ meta_db_path,
436+ state_db_path,
437+ doc_db_path,
438+ key_root_path,
439+ recover_temp_path,
440+ admin_addr,
441+ doc_id_start,
442+ RecoverType :: Rollup ,
443+ )
444+ . await ;
445+ info ! ( "start recovering index node" ) ;
446+ recover. recover_stat ( ) . unwrap ( ) ;
447+ recover. recover_from_ar ( ) . await . unwrap ( ) ;
448+ }
385449 RecoverCommand :: Index {
386450 meta_db_path,
387451 state_db_path,
@@ -401,14 +465,15 @@ impl DB3Command {
401465 tracing_subscriber:: fmt ( ) . with_max_level ( log_level) . init ( ) ;
402466 info ! ( "{ABOUT}" ) ;
403467 let recover = Self :: create_recover (
468+ "" . to_string ( ) ,
404469 meta_db_path,
405470 state_db_path,
406471 doc_db_path,
407472 key_root_path,
408473 recover_temp_path,
409474 admin_addr,
410475 doc_id_start,
411- SystemRole :: DataIndexNode ,
476+ RecoverType :: Index ,
412477 )
413478 . await ;
414479 info ! ( "start recovering index node" ) ;
@@ -418,14 +483,15 @@ impl DB3Command {
418483 }
419484 }
420485 async fn create_recover (
486+ mutation_db_path : String ,
421487 meta_db_path : String ,
422488 state_db_path : String ,
423489 doc_db_path : String ,
424490 key_root_path : String ,
425491 recover_temp_path : String ,
426492 _admin_addr : String ,
427493 doc_id_start : i64 ,
428- role : SystemRole ,
494+ recover_type : RecoverType ,
429495 ) -> Recover {
430496 let system_store_config = SystemStoreConfig {
431497 key_root_path : key_root_path. to_string ( ) ,
@@ -445,6 +511,10 @@ impl DB3Command {
445511 in_memory_db_handle_limit : 16 ,
446512 } ;
447513
514+ let enable_doc_store = match recover_type {
515+ RecoverType :: Index => true ,
516+ RecoverType :: Rollup => false ,
517+ } ;
448518 let db_store_config = DBStoreV2Config {
449519 db_path : meta_db_path. to_string ( ) ,
450520 db_store_cf_name : "db_store_cf" . to_string ( ) ,
@@ -454,20 +524,38 @@ impl DB3Command {
454524 doc_owner_store_cf_name : "doc_owner_store_cf" . to_string ( ) ,
455525 db_owner_store_cf_name : "db_owner_cf" . to_string ( ) ,
456526 scan_max_limit : 1000 ,
457- enable_doc_store : true ,
527+ enable_doc_store,
458528 doc_store_conf,
459529 doc_start_id : doc_id_start,
460530 } ;
461531
462532 let db_store = DBStoreV2 :: new ( db_store_config. clone ( ) ) . unwrap ( ) ;
533+
534+ let storage = match recover_type {
535+ RecoverType :: Rollup => {
536+ let mutation_store_config = MutationStoreConfig {
537+ db_path : mutation_db_path. to_string ( ) ,
538+ block_store_cf_name : "block_store_cf" . to_string ( ) ,
539+ tx_store_cf_name : "tx_store_cf" . to_string ( ) ,
540+ rollup_store_cf_name : "rollup_store_cf" . to_string ( ) ,
541+ gc_cf_name : "gc_store_cf" . to_string ( ) ,
542+ message_max_buffer : 4 * 1024 ,
543+ scan_max_limit : 50 ,
544+ block_state_cf_name : "block_state_cf" . to_string ( ) ,
545+ } ;
546+ let store = MutationStore :: new ( mutation_store_config) . unwrap ( ) ;
547+ Some ( Arc :: new ( store) )
548+ }
549+ RecoverType :: Index => None ,
550+ } ;
551+
463552 std:: fs:: create_dir_all ( recover_temp_path. as_str ( ) ) . unwrap ( ) ;
464553 let recover_config = RecoverConfig {
465554 key_root_path : key_root_path. to_string ( ) ,
466555 temp_data_path : recover_temp_path. to_string ( ) ,
467- enable_mutation_recover : false ,
468- role,
556+ recover_type,
469557 } ;
470- Recover :: new ( recover_config, db_store, system_store)
558+ Recover :: new ( recover_config, db_store, system_store, storage )
471559 . await
472560 . unwrap ( )
473561 }
0 commit comments