flush_frozen_layer: assert we own the frozen layer when we remove its ephemeral file

TODO the assert is incorrect because get_reconstruct_data's traversal_path
can be holding references to inmemory and frozen layers.
This commit is contained in:
Christian Schwarz
2023-06-09 17:25:53 +02:00
parent 7ef080c404
commit 0bf9db2e5d

View File

@@ -2865,14 +2865,21 @@ impl Timeline {
// in-memory layer from the map now.
{
let mut layers = self.layers.write().unwrap();
let l = layers.frozen_layers.pop_front();
let l = layers.frozen_layers.pop_front().unwrap();
// Only one thread may call this function at a time (for this
// timeline). If two threads tried to flush the same frozen
// layer to disk at the same time, that would not work.
assert!(LayerMap::compare_arced_layers(&l.unwrap(), &frozen_layer));
// release lock on 'layers'
assert!(LayerMap::compare_arced_layers(&l, &frozen_layer));
drop(frozen_layer);
// XXX once we upgrade to Rust 1.70, use Arc::into_inner.
// It does the following checks atomically.
assert_eq!(Arc::weak_count(&l), 0);
let l =
Arc::try_unwrap(l).expect("no-one except us holds references to this layer");
drop(layers); // don't hold layer map lock when doing disk IO
info!("dropping frozen layer, this should remove the ephemeral file on disk");
drop(l);
}
fail_point!("checkpoint-after-sync");