Prevent duplicated layer in LayerMap

This commit is contained in:
Konstantin Knizhnik
2023-03-21 16:20:58 +02:00
parent a7cf926aeb
commit c2731e17a9
3 changed files with 10 additions and 11 deletions

View File

@@ -490,10 +490,12 @@ impl<Value: Clone> BufferedHistoricLayerCoverage<Value> {
self.buffer.retain(|layer_key, layer| {
match layer {
Some(l) => {
self.layers.insert(layer_key.clone(), l.clone());
// There should not be duplicate layers
assert!(self.layers.insert(layer_key.clone(), l.clone()).is_none());
}
None => {
self.layers.remove(layer_key);
// layer is present in the tree
assert!(self.layers.remove(layer_key).is_some());
}
};
false

View File

@@ -623,9 +623,6 @@ impl ImageLayerWriterInner {
lsn: self.lsn,
},
);
if final_path.exists() {
warn!("Overwrite existed image layer {}", final_path.display());
}
std::fs::rename(self.path, final_path)?;
trace!("created image layer {}", layer.path().display());

View File

@@ -2921,12 +2921,12 @@ impl Timeline {
let img_range =
partition.ranges.first().unwrap().start..partition.ranges.last().unwrap().end;
if wanted.overlaps(&img_range) {
//
// gc_timeline only pays attention to image layers that are older than the GC cutoff,
// but create_image_layers creates image layers at last-record-lsn.
// So it's possible that gc_timeline wants a new image layer to be created for a key range,
// but the range is already covered by image layers at more recent LSNs. Before we
// create a new image layer, check if the range is already covered at more recent LSNs.
//
// gc_timeline only pays attention to image layers that are older than the GC cutoff,
// but create_image_layers creates image layers at last-record-lsn.
// So it's possible that gc_timeline wants a new image layer to be created for a key range,
// but the range is already covered by image layers at more recent LSNs. Before we
// create a new image layer, check if the range is already covered at more recent LSNs.
if !layers
.image_layer_exists(&img_range, &(Lsn::min(lsn, *cutoff_lsn)..lsn + 1))?
{