@@ -185,6 +185,10 @@ enum Action {
185
185
#[ clap( long, default_value = "15" , action) ]
186
186
extent_count : u64 ,
187
187
188
+ /// Downstairs will all be started read only (default: false)
189
+ #[ clap( long, action, default_value = "false" ) ]
190
+ read_only : bool ,
191
+
188
192
/// default output directory
189
193
#[ clap( long, global = true , default_value = "/tmp/dsc" , action) ]
190
194
output_dir : PathBuf ,
@@ -225,6 +229,7 @@ struct DownstairsInfo {
225
229
_create_output : String ,
226
230
output_file : PathBuf ,
227
231
client_id : usize ,
232
+ read_only : bool ,
228
233
}
229
234
230
235
impl DownstairsInfo {
@@ -235,6 +240,7 @@ impl DownstairsInfo {
235
240
_create_output : String ,
236
241
output_file : PathBuf ,
237
242
client_id : usize ,
243
+ read_only : bool ,
238
244
) -> DownstairsInfo {
239
245
DownstairsInfo {
240
246
ds_bin,
@@ -243,6 +249,7 @@ impl DownstairsInfo {
243
249
_create_output,
244
250
output_file,
245
251
client_id,
252
+ read_only,
246
253
}
247
254
}
248
255
@@ -254,9 +261,23 @@ impl DownstairsInfo {
254
261
255
262
let port_value = format ! ( "{}" , self . port) ;
256
263
264
+ let mode = if self . read_only {
265
+ "ro" . to_string ( )
266
+ } else {
267
+ "rw" . to_string ( )
268
+ } ;
269
+
257
270
let region_dir = self . region_dir . clone ( ) ;
258
271
let cmd = Command :: new ( self . ds_bin . clone ( ) )
259
- . args ( [ "run" , "-p" , & port_value, "-d" , & region_dir] )
272
+ . args ( [
273
+ "run" ,
274
+ "-p" ,
275
+ & port_value,
276
+ "-d" ,
277
+ & region_dir,
278
+ "--mode" ,
279
+ & mode,
280
+ ] )
260
281
. stdout ( Stdio :: from ( outputs) )
261
282
. stderr ( Stdio :: from ( errors) )
262
283
. spawn ( )
@@ -293,9 +314,12 @@ pub struct DscInfo {
293
314
rs : Mutex < RegionSet > ,
294
315
/// Work for the dsc to do, what downstairs to start/stop/etc
295
316
work : Mutex < DscWork > ,
317
+ /// If the downstairs are started read only
318
+ read_only : bool ,
296
319
}
297
320
298
321
impl DscInfo {
322
+ #[ allow( clippy:: too_many_arguments) ]
299
323
fn new (
300
324
downstairs_bin : String ,
301
325
output_dir : PathBuf ,
@@ -304,6 +328,7 @@ impl DscInfo {
304
328
create : bool ,
305
329
port_base : u32 ,
306
330
region_count : usize ,
331
+ read_only : bool ,
307
332
) -> Result < Arc < Self > > {
308
333
// Verify the downstairs binary exists as is a file
309
334
if !Path :: new ( & downstairs_bin) . exists ( ) {
@@ -418,6 +443,7 @@ impl DscInfo {
418
443
output_dir,
419
444
rs : mrs,
420
445
work,
446
+ read_only,
421
447
} ) )
422
448
}
423
449
@@ -532,6 +558,7 @@ impl DscInfo {
532
558
String :: from_utf8 ( output. stdout ) . unwrap ( ) ,
533
559
output_path,
534
560
ds_id,
561
+ self . read_only ,
535
562
) ;
536
563
rs. ds . push ( Arc :: new ( dsi) ) ;
537
564
Ok ( time_f)
@@ -582,6 +609,7 @@ impl DscInfo {
582
609
"/dev/null" . to_string ( ) ,
583
610
output_path,
584
611
ds_id,
612
+ self . read_only ,
585
613
) ;
586
614
rs. ds . push ( Arc :: new ( dsi) ) ;
587
615
port += rs. port_step ;
@@ -1387,6 +1415,7 @@ fn main() -> Result<()> {
1387
1415
true ,
1388
1416
port_base,
1389
1417
region_count,
1418
+ false ,
1390
1419
) ?;
1391
1420
1392
1421
runtime. block_on ( dsci. create_region_set (
@@ -1405,7 +1434,7 @@ fn main() -> Result<()> {
1405
1434
region_dir,
1406
1435
} => {
1407
1436
let dsci = DscInfo :: new (
1408
- ds_bin, output_dir, region_dir, notify_tx, true , 8810 , 3 ,
1437
+ ds_bin, output_dir, region_dir, notify_tx, true , 8810 , 3 , false ,
1409
1438
) ?;
1410
1439
runtime. block_on ( region_create_test ( & dsci, long, csv_out) )
1411
1440
}
@@ -1420,6 +1449,7 @@ fn main() -> Result<()> {
1420
1449
extent_count,
1421
1450
output_dir,
1422
1451
port_base,
1452
+ read_only,
1423
1453
region_dir,
1424
1454
region_count,
1425
1455
} => {
@@ -1443,6 +1473,7 @@ fn main() -> Result<()> {
1443
1473
create,
1444
1474
port_base,
1445
1475
region_count,
1476
+ read_only,
1446
1477
) ?;
1447
1478
1448
1479
if create {
@@ -1489,8 +1520,16 @@ mod test {
1489
1520
let dir = tempdir ( ) . unwrap ( ) . as_ref ( ) . to_path_buf ( ) ;
1490
1521
let ( tx, _) = watch:: channel ( 0 ) ;
1491
1522
let region_vec = vec ! [ dir. clone( ) ] ;
1492
- let res =
1493
- DscInfo :: new ( ds_bin, dir. clone ( ) , region_vec, tx, true , 8810 , 3 ) ;
1523
+ let res = DscInfo :: new (
1524
+ ds_bin,
1525
+ dir. clone ( ) ,
1526
+ region_vec,
1527
+ tx,
1528
+ true ,
1529
+ 8810 ,
1530
+ 3 ,
1531
+ false ,
1532
+ ) ;
1494
1533
assert ! ( res. is_ok( ) ) ;
1495
1534
assert ! ( Path :: new( & dir) . exists( ) ) ;
1496
1535
}
@@ -1514,6 +1553,7 @@ mod test {
1514
1553
true ,
1515
1554
8810 ,
1516
1555
3 ,
1556
+ false ,
1517
1557
) ;
1518
1558
assert ! ( res. is_ok( ) ) ;
1519
1559
assert ! ( Path :: new( & dir) . exists( ) ) ;
@@ -1533,7 +1573,8 @@ mod test {
1533
1573
let r2 = tempdir ( ) . unwrap ( ) . as_ref ( ) . to_path_buf ( ) ;
1534
1574
let region_vec = vec ! [ r1, r2] ;
1535
1575
let ( tx, _) = watch:: channel ( 0 ) ;
1536
- let res = DscInfo :: new ( ds_bin, dir, region_vec, tx, true , 8810 , 3 ) ;
1576
+ let res =
1577
+ DscInfo :: new ( ds_bin, dir, region_vec, tx, true , 8810 , 3 , false ) ;
1537
1578
assert ! ( res. is_err( ) ) ;
1538
1579
}
1539
1580
@@ -1549,7 +1590,8 @@ mod test {
1549
1590
let r3 = tempdir ( ) . unwrap ( ) . as_ref ( ) . to_path_buf ( ) ;
1550
1591
let region_vec = vec ! [ r1, r2, r3] ;
1551
1592
let ( tx, _) = watch:: channel ( 0 ) ;
1552
- let res = DscInfo :: new ( ds_bin, dir, region_vec, tx, true , 8810 , 2 ) ;
1593
+ let res =
1594
+ DscInfo :: new ( ds_bin, dir, region_vec, tx, true , 8810 , 2 , false ) ;
1553
1595
assert ! ( res. is_err( ) ) ;
1554
1596
}
1555
1597
@@ -1573,6 +1615,7 @@ mod test {
1573
1615
true ,
1574
1616
8810 ,
1575
1617
4 ,
1618
+ false ,
1576
1619
) ;
1577
1620
assert ! ( res. is_ok( ) ) ;
1578
1621
assert ! ( Path :: new( & dir) . exists( ) ) ;
@@ -1597,6 +1640,7 @@ mod test {
1597
1640
true ,
1598
1641
8810 ,
1599
1642
3 ,
1643
+ false ,
1600
1644
) ;
1601
1645
1602
1646
assert ! ( res. is_err( ) ) ;
@@ -1621,13 +1665,15 @@ mod test {
1621
1665
true ,
1622
1666
8810 ,
1623
1667
3 ,
1668
+ false ,
1624
1669
)
1625
1670
. unwrap ( ) ;
1626
1671
1627
1672
// Now, create them again and expect an error.
1628
1673
let ( tx, _) = watch:: channel ( 0 ) ;
1629
- let res =
1630
- DscInfo :: new ( ds_bin, output_dir, region_vec, tx, true , 8810 , 3 ) ;
1674
+ let res = DscInfo :: new (
1675
+ ds_bin, output_dir, region_vec, tx, true , 8810 , 3 , false ,
1676
+ ) ;
1631
1677
assert ! ( res. is_err( ) ) ;
1632
1678
}
1633
1679
@@ -1640,7 +1686,8 @@ mod test {
1640
1686
let region_vec = vec ! [ dir. clone( ) ] ;
1641
1687
let ( tx, _) = watch:: channel ( 0 ) ;
1642
1688
let dsci =
1643
- DscInfo :: new ( ds_bin, dir, region_vec, tx, true , 8810 , 3 ) . unwrap ( ) ;
1689
+ DscInfo :: new ( ds_bin, dir, region_vec, tx, true , 8810 , 3 , false )
1690
+ . unwrap ( ) ;
1644
1691
1645
1692
let res = dsci. delete_ds_region ( 0 ) . await ;
1646
1693
println ! ( "res is {:?}" , res) ;
@@ -1659,7 +1706,8 @@ mod test {
1659
1706
let region_vec = vec ! [ r1. clone( ) , r2, r3] ;
1660
1707
let ( tx, _) = watch:: channel ( 0 ) ;
1661
1708
let dsci =
1662
- DscInfo :: new ( ds_bin, dir, region_vec, tx, true , 8810 , 3 ) . unwrap ( ) ;
1709
+ DscInfo :: new ( ds_bin, dir, region_vec, tx, true , 8810 , 3 , false )
1710
+ . unwrap ( ) ;
1663
1711
1664
1712
// Manually create the first region directory.
1665
1713
let ds_region_dir =
@@ -1684,9 +1732,17 @@ mod test {
1684
1732
let dir = tempdir ( ) . unwrap ( ) . as_ref ( ) . to_path_buf ( ) ;
1685
1733
let region_vec = vec ! [ dir. clone( ) ] ;
1686
1734
let ( tx, _) = watch:: channel ( 0 ) ;
1687
- let dsci =
1688
- DscInfo :: new ( ds_bin, dir. clone ( ) , region_vec, tx, true , 8810 , 3 )
1689
- . unwrap ( ) ;
1735
+ let dsci = DscInfo :: new (
1736
+ ds_bin,
1737
+ dir. clone ( ) ,
1738
+ region_vec,
1739
+ tx,
1740
+ true ,
1741
+ 8810 ,
1742
+ 3 ,
1743
+ false ,
1744
+ )
1745
+ . unwrap ( ) ;
1690
1746
1691
1747
// Manually create the region directory. We have to convert the
1692
1748
// PathBuf back into a string.
@@ -1708,9 +1764,17 @@ mod test {
1708
1764
let dir = tempdir ( ) . unwrap ( ) . as_ref ( ) . to_path_buf ( ) ;
1709
1765
let region_vec = vec ! [ dir. clone( ) ] ;
1710
1766
let ( tx, _) = watch:: channel ( 0 ) ;
1711
- let dsci =
1712
- DscInfo :: new ( ds_bin, dir. clone ( ) , region_vec, tx, true , 8810 , 3 )
1713
- . unwrap ( ) ;
1767
+ let dsci = DscInfo :: new (
1768
+ ds_bin,
1769
+ dir. clone ( ) ,
1770
+ region_vec,
1771
+ tx,
1772
+ true ,
1773
+ 8810 ,
1774
+ 3 ,
1775
+ false ,
1776
+ )
1777
+ . unwrap ( ) ;
1714
1778
assert ! ( Path :: new( & dir) . exists( ) ) ;
1715
1779
1716
1780
// Manually create the region set. We have to convert the
@@ -1737,9 +1801,17 @@ mod test {
1737
1801
let dir = tempdir ( ) . unwrap ( ) . as_ref ( ) . to_path_buf ( ) ;
1738
1802
let region_vec = vec ! [ dir. clone( ) ] ;
1739
1803
let ( tx, _) = watch:: channel ( 0 ) ;
1740
- let dsci =
1741
- DscInfo :: new ( ds_bin, dir. clone ( ) , region_vec, tx, true , 8810 , 4 )
1742
- . unwrap ( ) ;
1804
+ let dsci = DscInfo :: new (
1805
+ ds_bin,
1806
+ dir. clone ( ) ,
1807
+ region_vec,
1808
+ tx,
1809
+ true ,
1810
+ 8810 ,
1811
+ 4 ,
1812
+ false ,
1813
+ )
1814
+ . unwrap ( ) ;
1743
1815
assert ! ( Path :: new( & dir) . exists( ) ) ;
1744
1816
1745
1817
// Manually create the region set. We have to convert the
@@ -1767,9 +1839,17 @@ mod test {
1767
1839
let dir = tempdir ( ) . unwrap ( ) . as_ref ( ) . to_path_buf ( ) ;
1768
1840
let region_vec = vec ! [ dir. clone( ) ] ;
1769
1841
let ( tx, _) = watch:: channel ( 0 ) ;
1770
- let dsci =
1771
- DscInfo :: new ( ds_bin, dir. clone ( ) , region_vec, tx, true , 8810 , 3 )
1772
- . unwrap ( ) ;
1842
+ let dsci = DscInfo :: new (
1843
+ ds_bin,
1844
+ dir. clone ( ) ,
1845
+ region_vec,
1846
+ tx,
1847
+ true ,
1848
+ 8810 ,
1849
+ 3 ,
1850
+ false ,
1851
+ )
1852
+ . unwrap ( ) ;
1773
1853
assert ! ( Path :: new( & dir) . exists( ) ) ;
1774
1854
1775
1855
// Manually create the 2/3 of the region set.
@@ -1797,9 +1877,17 @@ mod test {
1797
1877
let dir = tempdir ( ) . unwrap ( ) . as_ref ( ) . to_path_buf ( ) ;
1798
1878
let region_vec = vec ! [ dir. clone( ) ] ;
1799
1879
let ( tx, _) = watch:: channel ( 0 ) ;
1800
- let dsci =
1801
- DscInfo :: new ( ds_bin, dir. clone ( ) , region_vec, tx, true , 8810 , 4 )
1802
- . unwrap ( ) ;
1880
+ let dsci = DscInfo :: new (
1881
+ ds_bin,
1882
+ dir. clone ( ) ,
1883
+ region_vec,
1884
+ tx,
1885
+ true ,
1886
+ 8810 ,
1887
+ 4 ,
1888
+ false ,
1889
+ )
1890
+ . unwrap ( ) ;
1803
1891
assert ! ( Path :: new( & dir) . exists( ) ) ;
1804
1892
1805
1893
// Manually create the region set. We have to convert the
0 commit comments