Skip to content

Commit b909e88

Browse files
authored
Allow dsc to start the downstairs in read-only mode. (#1098)
Allow dsc to start the downstairs in read-only mode.
1 parent e30353d commit b909e88

File tree

1 file changed

+113
-25
lines changed

1 file changed

+113
-25
lines changed

dsc/src/main.rs

+113-25
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ enum Action {
185185
#[clap(long, default_value = "15", action)]
186186
extent_count: u64,
187187

188+
/// Downstairs will all be started read only (default: false)
189+
#[clap(long, action, default_value = "false")]
190+
read_only: bool,
191+
188192
/// default output directory
189193
#[clap(long, global = true, default_value = "/tmp/dsc", action)]
190194
output_dir: PathBuf,
@@ -225,6 +229,7 @@ struct DownstairsInfo {
225229
_create_output: String,
226230
output_file: PathBuf,
227231
client_id: usize,
232+
read_only: bool,
228233
}
229234

230235
impl DownstairsInfo {
@@ -235,6 +240,7 @@ impl DownstairsInfo {
235240
_create_output: String,
236241
output_file: PathBuf,
237242
client_id: usize,
243+
read_only: bool,
238244
) -> DownstairsInfo {
239245
DownstairsInfo {
240246
ds_bin,
@@ -243,6 +249,7 @@ impl DownstairsInfo {
243249
_create_output,
244250
output_file,
245251
client_id,
252+
read_only,
246253
}
247254
}
248255

@@ -254,9 +261,23 @@ impl DownstairsInfo {
254261

255262
let port_value = format!("{}", self.port);
256263

264+
let mode = if self.read_only {
265+
"ro".to_string()
266+
} else {
267+
"rw".to_string()
268+
};
269+
257270
let region_dir = self.region_dir.clone();
258271
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+
])
260281
.stdout(Stdio::from(outputs))
261282
.stderr(Stdio::from(errors))
262283
.spawn()
@@ -293,9 +314,12 @@ pub struct DscInfo {
293314
rs: Mutex<RegionSet>,
294315
/// Work for the dsc to do, what downstairs to start/stop/etc
295316
work: Mutex<DscWork>,
317+
/// If the downstairs are started read only
318+
read_only: bool,
296319
}
297320

298321
impl DscInfo {
322+
#[allow(clippy::too_many_arguments)]
299323
fn new(
300324
downstairs_bin: String,
301325
output_dir: PathBuf,
@@ -304,6 +328,7 @@ impl DscInfo {
304328
create: bool,
305329
port_base: u32,
306330
region_count: usize,
331+
read_only: bool,
307332
) -> Result<Arc<Self>> {
308333
// Verify the downstairs binary exists as is a file
309334
if !Path::new(&downstairs_bin).exists() {
@@ -418,6 +443,7 @@ impl DscInfo {
418443
output_dir,
419444
rs: mrs,
420445
work,
446+
read_only,
421447
}))
422448
}
423449

@@ -532,6 +558,7 @@ impl DscInfo {
532558
String::from_utf8(output.stdout).unwrap(),
533559
output_path,
534560
ds_id,
561+
self.read_only,
535562
);
536563
rs.ds.push(Arc::new(dsi));
537564
Ok(time_f)
@@ -582,6 +609,7 @@ impl DscInfo {
582609
"/dev/null".to_string(),
583610
output_path,
584611
ds_id,
612+
self.read_only,
585613
);
586614
rs.ds.push(Arc::new(dsi));
587615
port += rs.port_step;
@@ -1387,6 +1415,7 @@ fn main() -> Result<()> {
13871415
true,
13881416
port_base,
13891417
region_count,
1418+
false,
13901419
)?;
13911420

13921421
runtime.block_on(dsci.create_region_set(
@@ -1405,7 +1434,7 @@ fn main() -> Result<()> {
14051434
region_dir,
14061435
} => {
14071436
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,
14091438
)?;
14101439
runtime.block_on(region_create_test(&dsci, long, csv_out))
14111440
}
@@ -1420,6 +1449,7 @@ fn main() -> Result<()> {
14201449
extent_count,
14211450
output_dir,
14221451
port_base,
1452+
read_only,
14231453
region_dir,
14241454
region_count,
14251455
} => {
@@ -1443,6 +1473,7 @@ fn main() -> Result<()> {
14431473
create,
14441474
port_base,
14451475
region_count,
1476+
read_only,
14461477
)?;
14471478

14481479
if create {
@@ -1489,8 +1520,16 @@ mod test {
14891520
let dir = tempdir().unwrap().as_ref().to_path_buf();
14901521
let (tx, _) = watch::channel(0);
14911522
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+
);
14941533
assert!(res.is_ok());
14951534
assert!(Path::new(&dir).exists());
14961535
}
@@ -1514,6 +1553,7 @@ mod test {
15141553
true,
15151554
8810,
15161555
3,
1556+
false,
15171557
);
15181558
assert!(res.is_ok());
15191559
assert!(Path::new(&dir).exists());
@@ -1533,7 +1573,8 @@ mod test {
15331573
let r2 = tempdir().unwrap().as_ref().to_path_buf();
15341574
let region_vec = vec![r1, r2];
15351575
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);
15371578
assert!(res.is_err());
15381579
}
15391580

@@ -1549,7 +1590,8 @@ mod test {
15491590
let r3 = tempdir().unwrap().as_ref().to_path_buf();
15501591
let region_vec = vec![r1, r2, r3];
15511592
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);
15531595
assert!(res.is_err());
15541596
}
15551597

@@ -1573,6 +1615,7 @@ mod test {
15731615
true,
15741616
8810,
15751617
4,
1618+
false,
15761619
);
15771620
assert!(res.is_ok());
15781621
assert!(Path::new(&dir).exists());
@@ -1597,6 +1640,7 @@ mod test {
15971640
true,
15981641
8810,
15991642
3,
1643+
false,
16001644
);
16011645

16021646
assert!(res.is_err());
@@ -1621,13 +1665,15 @@ mod test {
16211665
true,
16221666
8810,
16231667
3,
1668+
false,
16241669
)
16251670
.unwrap();
16261671

16271672
// Now, create them again and expect an error.
16281673
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+
);
16311677
assert!(res.is_err());
16321678
}
16331679

@@ -1640,7 +1686,8 @@ mod test {
16401686
let region_vec = vec![dir.clone()];
16411687
let (tx, _) = watch::channel(0);
16421688
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();
16441691

16451692
let res = dsci.delete_ds_region(0).await;
16461693
println!("res is {:?}", res);
@@ -1659,7 +1706,8 @@ mod test {
16591706
let region_vec = vec![r1.clone(), r2, r3];
16601707
let (tx, _) = watch::channel(0);
16611708
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();
16631711

16641712
// Manually create the first region directory.
16651713
let ds_region_dir =
@@ -1684,9 +1732,17 @@ mod test {
16841732
let dir = tempdir().unwrap().as_ref().to_path_buf();
16851733
let region_vec = vec![dir.clone()];
16861734
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();
16901746

16911747
// Manually create the region directory. We have to convert the
16921748
// PathBuf back into a string.
@@ -1708,9 +1764,17 @@ mod test {
17081764
let dir = tempdir().unwrap().as_ref().to_path_buf();
17091765
let region_vec = vec![dir.clone()];
17101766
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();
17141778
assert!(Path::new(&dir).exists());
17151779

17161780
// Manually create the region set. We have to convert the
@@ -1737,9 +1801,17 @@ mod test {
17371801
let dir = tempdir().unwrap().as_ref().to_path_buf();
17381802
let region_vec = vec![dir.clone()];
17391803
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();
17431815
assert!(Path::new(&dir).exists());
17441816

17451817
// Manually create the region set. We have to convert the
@@ -1767,9 +1839,17 @@ mod test {
17671839
let dir = tempdir().unwrap().as_ref().to_path_buf();
17681840
let region_vec = vec![dir.clone()];
17691841
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();
17731853
assert!(Path::new(&dir).exists());
17741854

17751855
// Manually create the 2/3 of the region set.
@@ -1797,9 +1877,17 @@ mod test {
17971877
let dir = tempdir().unwrap().as_ref().to_path_buf();
17981878
let region_vec = vec![dir.clone()];
17991879
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();
18031891
assert!(Path::new(&dir).exists());
18041892

18051893
// Manually create the region set. We have to convert the

0 commit comments

Comments
 (0)