mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 01:12:56 +00:00
Prevent duplicated layer in LayerMap
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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))?
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user