Skip to content

Commit 7297d76

Browse files
authored
Only perform region replacement for r/w regions (#7243)
Region replacement does not work for read-only regions (there is a check in the region_replacement_start saga that bails out if the supplied region is read-only) - this is tracked by #6172. The current plan to make read-only region replacement work is to use the same machinery as region snapshot replacements (as they're both read-only), so this commit changes the current query that finds expunged regions to replace to only return read/write regions. This can be changed back in the future if the plan for #6172 changes.
1 parent ad61b01 commit 7297d76

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

nexus/db-queries/src/db/datastore/region.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ impl DataStore {
422422
}
423423
}
424424

425-
/// Find regions on expunged disks
426-
pub async fn find_regions_on_expunged_physical_disks(
425+
/// Find read/write regions on expunged disks
426+
pub async fn find_read_write_regions_on_expunged_physical_disks(
427427
&self,
428428
opctx: &OpContext,
429429
) -> LookupResult<Vec<Region>> {
@@ -450,6 +450,8 @@ impl DataStore {
450450
))
451451
.select(dataset_dsl::id)
452452
))
453+
// only return read-write regions here
454+
.filter(region_dsl::read_only.eq(false))
453455
.select(Region::as_select())
454456
.load_async(&*conn)
455457
.await

nexus/db-queries/src/db/datastore/region_replacement.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ impl DataStore {
3737
opctx: &OpContext,
3838
region: &Region,
3939
) -> Result<Uuid, Error> {
40+
if region.read_only() {
41+
return Err(Error::invalid_request(format!(
42+
"region {} is read-only",
43+
region.id(),
44+
)));
45+
}
46+
4047
let request = RegionReplacement::for_region(region);
4148
let request_id = request.id;
4249

nexus/src/app/background/tasks/region_replacement.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,18 @@ impl BackgroundTask for RegionReplacementDetector {
6868

6969
let mut status = RegionReplacementStatus::default();
7070

71-
// Find regions on expunged physical disks
71+
// Find read/write regions on expunged physical disks
7272
let regions_to_be_replaced = match self
7373
.datastore
74-
.find_regions_on_expunged_physical_disks(opctx)
74+
.find_read_write_regions_on_expunged_physical_disks(opctx)
7575
.await
7676
{
7777
Ok(regions) => regions,
7878

7979
Err(e) => {
8080
let s = format!(
81-
"find_regions_on_expunged_physical_disks failed: {e}"
81+
"find_read_write_regions_on_expunged_physical_disks \
82+
failed: {e}"
8283
);
8384
error!(&log, "{s}");
8485
status.errors.push(s);

nexus/tests/integration_tests/disks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ async fn test_disk_expunge(cptestctx: &ControlPlaneTestContext) {
25772577

25782578
// All three regions should be returned
25792579
let expunged_regions = datastore
2580-
.find_regions_on_expunged_physical_disks(&opctx)
2580+
.find_read_write_regions_on_expunged_physical_disks(&opctx)
25812581
.await
25822582
.unwrap();
25832583

0 commit comments

Comments
 (0)