@@ -1351,6 +1351,99 @@ pub struct ActiveUpstairs {
1351
1351
pub terminate_sender : oneshot:: Sender < UpstairsConnection > ,
1352
1352
}
1353
1353
1354
+ #[ derive( Debug ) ]
1355
+ pub struct DownstairsBuilder < ' a > {
1356
+ data : & ' a Path ,
1357
+ read_only : bool ,
1358
+ lossy : Option < bool > ,
1359
+ read_errors : Option < bool > , // Test flag
1360
+ write_errors : Option < bool > , // Test flag
1361
+ flush_errors : Option < bool > , // Test flag
1362
+ backend : Option < Backend > ,
1363
+ log : Option < Logger > ,
1364
+ }
1365
+
1366
+ impl DownstairsBuilder < ' _ > {
1367
+ pub fn set_lossy ( & mut self , lossy : bool ) -> & mut Self {
1368
+ self . lossy = Some ( lossy) ;
1369
+ self
1370
+ }
1371
+ pub fn set_test_errors (
1372
+ & mut self ,
1373
+ read_errors : bool ,
1374
+ write_errors : bool ,
1375
+ flush_errors : bool ,
1376
+ ) -> & mut Self {
1377
+ self . read_errors = Some ( read_errors) ;
1378
+ self . write_errors = Some ( write_errors) ;
1379
+ self . flush_errors = Some ( flush_errors) ;
1380
+ self
1381
+ }
1382
+ pub fn set_backend ( & mut self , backend : Backend ) -> & mut Self {
1383
+ self . backend = Some ( backend) ;
1384
+ self
1385
+ }
1386
+ pub fn set_logger ( & mut self , log : Logger ) -> & mut Self {
1387
+ self . log = Some ( log) ;
1388
+ self
1389
+ }
1390
+
1391
+ pub async fn build ( & mut self ) -> Result < Arc < Mutex < Downstairs > > > {
1392
+ let lossy = self . lossy . unwrap_or ( false ) ;
1393
+ let read_errors = self . read_errors . unwrap_or ( false ) ;
1394
+ let write_errors = self . write_errors . unwrap_or ( false ) ;
1395
+ let flush_errors = self . flush_errors . unwrap_or ( false ) ;
1396
+ let backend = self . backend . unwrap_or ( Backend :: RawFile ) ;
1397
+
1398
+ let log = match & self . log {
1399
+ Some ( log) => log. clone ( ) ,
1400
+ None => build_logger ( ) ,
1401
+ } ;
1402
+
1403
+ // Open the region at the provided location.
1404
+ let region = Region :: open_with_backend (
1405
+ self . data ,
1406
+ Default :: default ( ) ,
1407
+ true ,
1408
+ self . read_only ,
1409
+ backend,
1410
+ & log,
1411
+ )
1412
+ . await ?;
1413
+
1414
+ let encrypted = region. encrypted ( ) ;
1415
+
1416
+ let dss = DsStatOuter {
1417
+ ds_stat_wrap : Arc :: new ( std:: sync:: Mutex :: new ( DsCountStat :: new (
1418
+ region. def ( ) . uuid ( ) ,
1419
+ ) ) ) ,
1420
+ } ;
1421
+
1422
+ info ! ( log, "UUID: {:?}" , region. def( ) . uuid( ) ) ;
1423
+ info ! (
1424
+ log,
1425
+ "Blocks per extent:{} Total Extents: {}" ,
1426
+ region. def( ) . extent_size( ) . value,
1427
+ region. def( ) . extent_count( ) ,
1428
+ ) ;
1429
+
1430
+ Ok ( Arc :: new ( Mutex :: new ( Downstairs {
1431
+ region,
1432
+ lossy,
1433
+ read_errors,
1434
+ write_errors,
1435
+ flush_errors,
1436
+ active_upstairs : HashMap :: new ( ) ,
1437
+ dss,
1438
+ read_only : self . read_only ,
1439
+ encrypted,
1440
+ address : None ,
1441
+ repair_address : None ,
1442
+ log,
1443
+ } ) ) )
1444
+ }
1445
+ }
1446
+
1354
1447
/*
1355
1448
* Overall structure for things the downstairs is tracking.
1356
1449
* This includes the extents and their status as well as the
@@ -1374,34 +1467,16 @@ pub struct Downstairs {
1374
1467
1375
1468
#[ allow( clippy:: too_many_arguments) ]
1376
1469
impl Downstairs {
1377
- fn new (
1378
- region : Region ,
1379
- lossy : bool ,
1380
- read_errors : bool ,
1381
- write_errors : bool ,
1382
- flush_errors : bool ,
1383
- read_only : bool ,
1384
- encrypted : bool ,
1385
- log : Logger ,
1386
- ) -> Self {
1387
- let dss = DsStatOuter {
1388
- ds_stat_wrap : Arc :: new ( std:: sync:: Mutex :: new ( DsCountStat :: new (
1389
- region. def ( ) . uuid ( ) ,
1390
- ) ) ) ,
1391
- } ;
1392
- Downstairs {
1393
- region,
1394
- lossy,
1395
- read_errors,
1396
- write_errors,
1397
- flush_errors,
1398
- active_upstairs : HashMap :: new ( ) ,
1399
- dss,
1470
+ pub fn new_builder ( data : & Path , read_only : bool ) -> DownstairsBuilder {
1471
+ DownstairsBuilder {
1472
+ data,
1400
1473
read_only,
1401
- encrypted,
1402
- address : None ,
1403
- repair_address : None ,
1404
- log,
1474
+ lossy : Some ( false ) ,
1475
+ read_errors : Some ( false ) ,
1476
+ write_errors : Some ( false ) ,
1477
+ flush_errors : Some ( false ) ,
1478
+ backend : Some ( Backend :: RawFile ) ,
1479
+ log : None ,
1405
1480
}
1406
1481
}
1407
1482
@@ -3069,78 +3144,6 @@ pub async fn create_region_with_backend(
3069
3144
Ok ( region)
3070
3145
}
3071
3146
3072
- pub async fn build_downstairs_for_region (
3073
- data : & Path ,
3074
- lossy : bool ,
3075
- read_errors : bool ,
3076
- write_errors : bool ,
3077
- flush_errors : bool ,
3078
- read_only : bool ,
3079
- log_request : Option < Logger > ,
3080
- ) -> Result < Arc < Mutex < Downstairs > > > {
3081
- build_downstairs_for_region_with_backend (
3082
- data,
3083
- lossy,
3084
- read_errors,
3085
- write_errors,
3086
- flush_errors,
3087
- read_only,
3088
- Backend :: RawFile ,
3089
- log_request,
3090
- )
3091
- . await
3092
- }
3093
-
3094
- // Build the downstairs struct given a region directory and some additional
3095
- // needed information. If a logger is passed in, we will use that, otherwise
3096
- // a logger will be created.
3097
- #[ allow( clippy:: too_many_arguments) ]
3098
- pub async fn build_downstairs_for_region_with_backend (
3099
- data : & Path ,
3100
- lossy : bool ,
3101
- read_errors : bool ,
3102
- write_errors : bool ,
3103
- flush_errors : bool ,
3104
- read_only : bool ,
3105
- backend : Backend ,
3106
- log_request : Option < Logger > ,
3107
- ) -> Result < Arc < Mutex < Downstairs > > > {
3108
- let log = match log_request {
3109
- Some ( log) => log,
3110
- None => build_logger ( ) ,
3111
- } ;
3112
- let region = Region :: open_with_backend (
3113
- data,
3114
- Default :: default ( ) ,
3115
- true ,
3116
- read_only,
3117
- backend,
3118
- & log,
3119
- )
3120
- . await ?;
3121
-
3122
- info ! ( log, "UUID: {:?}" , region. def( ) . uuid( ) ) ;
3123
- info ! (
3124
- log,
3125
- "Blocks per extent:{} Total Extents: {}" ,
3126
- region. def( ) . extent_size( ) . value,
3127
- region. def( ) . extent_count( ) ,
3128
- ) ;
3129
-
3130
- let encrypted = region. encrypted ( ) ;
3131
-
3132
- Ok ( Arc :: new ( Mutex :: new ( Downstairs :: new (
3133
- region,
3134
- lossy,
3135
- read_errors,
3136
- write_errors,
3137
- flush_errors,
3138
- read_only,
3139
- encrypted,
3140
- log,
3141
- ) ) ) )
3142
- }
3143
-
3144
3147
/// Returns Ok if everything spawned ok, Err otherwise
3145
3148
///
3146
3149
/// Return Ok(main task join handle) if all the necessary tasks spawned
@@ -3568,16 +3571,10 @@ mod test {
3568
3571
region. extend ( 2 ) . await ?;
3569
3572
3570
3573
let path_dir = dir. as_ref ( ) . to_path_buf ( ) ;
3571
- let ads = build_downstairs_for_region (
3572
- & path_dir,
3573
- false ,
3574
- false ,
3575
- false ,
3576
- false ,
3577
- false ,
3578
- Some ( csl ( ) ) ,
3579
- )
3580
- . await ?;
3574
+ let ads = Downstairs :: new_builder ( & path_dir, false )
3575
+ . set_logger ( csl ( ) )
3576
+ . build ( )
3577
+ . await ?;
3581
3578
3582
3579
// This happens in proc() function.
3583
3580
let upstairs_connection = UpstairsConnection {
@@ -3653,16 +3650,10 @@ mod test {
3653
3650
region. extend ( extent_count) . await ?;
3654
3651
3655
3652
let path_dir = dir. as_ref ( ) . to_path_buf ( ) ;
3656
- let ads = build_downstairs_for_region (
3657
- & path_dir,
3658
- false ,
3659
- false ,
3660
- false ,
3661
- false ,
3662
- false ,
3663
- Some ( csl ( ) ) ,
3664
- )
3665
- . await ?;
3653
+ let ads = Downstairs :: new_builder ( & path_dir, false )
3654
+ . set_logger ( csl ( ) )
3655
+ . build ( )
3656
+ . await ?;
3666
3657
3667
3658
Ok ( ads)
3668
3659
}
@@ -5506,16 +5497,10 @@ mod test {
5506
5497
5507
5498
let path_dir = dir. as_ref ( ) . to_path_buf ( ) ;
5508
5499
5509
- build_downstairs_for_region (
5510
- & path_dir,
5511
- false , // lossy
5512
- false , // read errors
5513
- false , // write errors
5514
- false , // flush errors
5515
- read_only,
5516
- Some ( csl ( ) ) ,
5517
- )
5518
- . await
5500
+ Downstairs :: new_builder ( & path_dir, read_only)
5501
+ . set_logger ( csl ( ) )
5502
+ . build ( )
5503
+ . await
5519
5504
}
5520
5505
5521
5506
#[ tokio:: test]
@@ -5915,16 +5900,10 @@ mod test {
5915
5900
region. extend ( 2 ) . await ?;
5916
5901
5917
5902
let path_dir = dir. as_ref ( ) . to_path_buf ( ) ;
5918
- let ads = build_downstairs_for_region (
5919
- & path_dir,
5920
- false ,
5921
- false ,
5922
- false ,
5923
- false ,
5924
- false ,
5925
- Some ( csl ( ) ) ,
5926
- )
5927
- . await ?;
5903
+ let ads = Downstairs :: new_builder ( & path_dir, false )
5904
+ . set_logger ( csl ( ) )
5905
+ . build ( )
5906
+ . await ?;
5928
5907
5929
5908
// This happens in proc() function.
5930
5909
let upstairs_connection_1 = UpstairsConnection {
@@ -6011,16 +5990,10 @@ mod test {
6011
5990
region. extend ( 2 ) . await ?;
6012
5991
6013
5992
let path_dir = dir. as_ref ( ) . to_path_buf ( ) ;
6014
- let ads = build_downstairs_for_region (
6015
- & path_dir,
6016
- false ,
6017
- false ,
6018
- false ,
6019
- false ,
6020
- false ,
6021
- Some ( csl ( ) ) ,
6022
- )
6023
- . await ?;
5993
+ let ads = Downstairs :: new_builder ( & path_dir, false )
5994
+ . set_logger ( csl ( ) )
5995
+ . build ( )
5996
+ . await ?;
6024
5997
6025
5998
// This happens in proc() function.
6026
5999
let upstairs_connection_1 = UpstairsConnection {
@@ -6107,16 +6080,10 @@ mod test {
6107
6080
region. extend ( 2 ) . await ?;
6108
6081
6109
6082
let path_dir = dir. as_ref ( ) . to_path_buf ( ) ;
6110
- let ads = build_downstairs_for_region (
6111
- & path_dir,
6112
- false ,
6113
- false ,
6114
- false ,
6115
- false ,
6116
- false ,
6117
- Some ( csl ( ) ) ,
6118
- )
6119
- . await ?;
6083
+ let ads = Downstairs :: new_builder ( & path_dir, false )
6084
+ . set_logger ( csl ( ) )
6085
+ . build ( )
6086
+ . await ?;
6120
6087
6121
6088
// This happens in proc() function.
6122
6089
let upstairs_connection_1 = UpstairsConnection {
0 commit comments