LayerMap::search is actually infallible

Found this while investigating failure modes of on-demand download.

I think it's a nice cleanup.
This commit is contained in:
Christian Schwarz
2022-12-19 19:43:06 +01:00
committed by Christian Schwarz
parent 486a985629
commit a3f0111726
3 changed files with 12 additions and 12 deletions

View File

@@ -163,7 +163,7 @@ fn bench_from_captest_env(c: &mut Criterion) {
c.bench_function("captest_uniform_queries", |b| {
b.iter(|| {
for q in queries.clone().into_iter() {
layer_map.search(q.0, q.1).unwrap();
layer_map.search(q.0, q.1);
}
});
});
@@ -192,7 +192,7 @@ fn bench_from_real_project(c: &mut Criterion) {
c.bench_function("real_map_uniform_queries", |b| {
b.iter(|| {
for q in queries.clone().into_iter() {
layer_map.search(q.0, q.1).unwrap();
layer_map.search(q.0, q.1);
}
});
});
@@ -238,7 +238,7 @@ fn bench_sequential(c: &mut Criterion) {
// Run the search queries
b.iter(|| {
for q in queries.clone().into_iter() {
layer_map.search(q.0, q.1).unwrap();
layer_map.search(q.0, q.1);
}
});
});

View File

@@ -261,7 +261,7 @@ where
/// contain the version, even if it's missing from the returned
/// layer.
///
pub fn search(&self, key: Key, end_lsn: Lsn) -> Result<Option<SearchResult<L>>> {
pub fn search(&self, key: Key, end_lsn: Lsn) -> Option<SearchResult<L>> {
// linear search
// Find the latest image layer that covers the given key
let mut latest_img: Option<Arc<L>> = None;
@@ -286,10 +286,10 @@ where
assert!(img_lsn < end_lsn);
if Lsn(img_lsn.0 + 1) == end_lsn {
// found exact match
return Ok(Some(SearchResult {
return Some(SearchResult {
layer: Arc::clone(l),
lsn_floor: img_lsn,
}));
});
}
if img_lsn > latest_img_lsn.unwrap_or(Lsn(0)) {
latest_img = Some(Arc::clone(l));
@@ -346,19 +346,19 @@ where
Lsn(latest_img_lsn.unwrap_or(Lsn(0)).0 + 1),
l.get_lsn_range().start,
);
Ok(Some(SearchResult {
Some(SearchResult {
lsn_floor,
layer: l,
}))
})
} else if let Some(l) = latest_img {
trace!("found img layer and no deltas for request on {key} at {end_lsn}");
Ok(Some(SearchResult {
Some(SearchResult {
lsn_floor: latest_img_lsn.unwrap(),
layer: l,
}))
})
} else {
trace!("no layer found for request on {key} at {end_lsn}");
Ok(None)
None
}
}

View File

@@ -1587,7 +1587,7 @@ impl Timeline {
}
}
if let Some(SearchResult { lsn_floor, layer }) = layers.search(key, cont_lsn)? {
if let Some(SearchResult { lsn_floor, layer }) = layers.search(key, cont_lsn) {
//info!("CHECKING for {} at {} on historic layer {}", key, cont_lsn, layer.filename().display());
let lsn_floor = max(cached_lsn + 1, lsn_floor);