16
16
//
17
17
18
18
use crate :: indexer_impl:: IndexerNodeImpl ;
19
- use crate :: recover:: { Recover , RecoverConfig } ;
19
+ use crate :: recover:: { Recover , RecoverConfig , RecoverType } ;
20
20
use crate :: rollup_executor:: RollupExecutorConfig ;
21
21
use crate :: storage_node_light_impl:: { StorageNodeV2Config , StorageNodeV2Impl } ;
22
22
use crate :: system_impl:: SystemImpl ;
@@ -35,7 +35,7 @@ use db3_storage::db_store_v2::{DBStoreV2, DBStoreV2Config};
35
35
use db3_storage:: doc_store:: DocStoreConfig ;
36
36
use db3_storage:: key_store:: KeyStore ;
37
37
use db3_storage:: key_store:: KeyStoreConfig ;
38
- use db3_storage:: mutation_store:: MutationStoreConfig ;
38
+ use db3_storage:: mutation_store:: { MutationStore , MutationStoreConfig } ;
39
39
use db3_storage:: state_store:: { StateStore , StateStoreConfig } ;
40
40
use db3_storage:: system_store:: { SystemRole , SystemStore , SystemStoreConfig } ;
41
41
use ethers:: prelude:: LocalWallet ;
@@ -183,6 +183,35 @@ pub enum RecoverCommand {
183
183
verbose : bool ,
184
184
} ,
185
185
// 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
+ } ,
186
215
}
187
216
impl DB3Command {
188
217
fn build_wallet ( key_root_path : & str ) -> std:: result:: Result < LocalWallet , DB3Error > {
@@ -382,6 +411,41 @@ impl DB3Command {
382
411
info ! ( "exit standalone indexer" )
383
412
}
384
413
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
+ }
385
449
RecoverCommand :: Index {
386
450
meta_db_path,
387
451
state_db_path,
@@ -401,14 +465,15 @@ impl DB3Command {
401
465
tracing_subscriber:: fmt ( ) . with_max_level ( log_level) . init ( ) ;
402
466
info ! ( "{ABOUT}" ) ;
403
467
let recover = Self :: create_recover (
468
+ "" . to_string ( ) ,
404
469
meta_db_path,
405
470
state_db_path,
406
471
doc_db_path,
407
472
key_root_path,
408
473
recover_temp_path,
409
474
admin_addr,
410
475
doc_id_start,
411
- SystemRole :: DataIndexNode ,
476
+ RecoverType :: Index ,
412
477
)
413
478
. await ;
414
479
info ! ( "start recovering index node" ) ;
@@ -418,14 +483,15 @@ impl DB3Command {
418
483
}
419
484
}
420
485
async fn create_recover (
486
+ mutation_db_path : String ,
421
487
meta_db_path : String ,
422
488
state_db_path : String ,
423
489
doc_db_path : String ,
424
490
key_root_path : String ,
425
491
recover_temp_path : String ,
426
492
_admin_addr : String ,
427
493
doc_id_start : i64 ,
428
- role : SystemRole ,
494
+ recover_type : RecoverType ,
429
495
) -> Recover {
430
496
let system_store_config = SystemStoreConfig {
431
497
key_root_path : key_root_path. to_string ( ) ,
@@ -445,6 +511,10 @@ impl DB3Command {
445
511
in_memory_db_handle_limit : 16 ,
446
512
} ;
447
513
514
+ let enable_doc_store = match recover_type {
515
+ RecoverType :: Index => true ,
516
+ RecoverType :: Rollup => false ,
517
+ } ;
448
518
let db_store_config = DBStoreV2Config {
449
519
db_path : meta_db_path. to_string ( ) ,
450
520
db_store_cf_name : "db_store_cf" . to_string ( ) ,
@@ -454,20 +524,38 @@ impl DB3Command {
454
524
doc_owner_store_cf_name : "doc_owner_store_cf" . to_string ( ) ,
455
525
db_owner_store_cf_name : "db_owner_cf" . to_string ( ) ,
456
526
scan_max_limit : 1000 ,
457
- enable_doc_store : true ,
527
+ enable_doc_store,
458
528
doc_store_conf,
459
529
doc_start_id : doc_id_start,
460
530
} ;
461
531
462
532
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
+
463
552
std:: fs:: create_dir_all ( recover_temp_path. as_str ( ) ) . unwrap ( ) ;
464
553
let recover_config = RecoverConfig {
465
554
key_root_path : key_root_path. to_string ( ) ,
466
555
temp_data_path : recover_temp_path. to_string ( ) ,
467
- enable_mutation_recover : false ,
468
- role,
556
+ recover_type,
469
557
} ;
470
- Recover :: new ( recover_config, db_store, system_store)
558
+ Recover :: new ( recover_config, db_store, system_store, storage )
471
559
. await
472
560
. unwrap ( )
473
561
}
0 commit comments