Skip to content

Commit 62f8386

Browse files
committed
pageserver - fsync image/delta layers
Ensure image and delta layer files are durable. Also, fsync the parent directory to ensure the directory entries are durable.
1 parent 69670b6 commit 62f8386

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

pageserver/src/layered_repository.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,8 @@ impl LayeredTimeline {
13111311
last_record_lsn
13121312
);
13131313

1314+
let timeline_dir = File::open(self.conf.timeline_path(&self.timelineid, &self.tenantid))?;
1315+
13141316
// Take the in-memory layer with the oldest WAL record. If it's older
13151317
// than the threshold, write it out to disk as a new image and delta file.
13161318
// Repeat until all remaining in-memory layers are within the threshold.
@@ -1322,6 +1324,8 @@ impl LayeredTimeline {
13221324
// a lot of memory and/or aren't receiving much updates anymore.
13231325
let mut disk_consistent_lsn = last_record_lsn;
13241326

1327+
let mut created_historics = false;
1328+
13251329
while let Some((oldest_layer, oldest_generation)) = layers.peek_oldest_open() {
13261330
let oldest_pending_lsn = oldest_layer.get_oldest_pending_lsn();
13271331

@@ -1374,6 +1378,11 @@ impl LayeredTimeline {
13741378
drop(layers);
13751379
let new_historics = frozen.write_to_disk(self)?;
13761380
layers = self.layers.lock().unwrap();
1381+
1382+
if !new_historics.is_empty() {
1383+
created_historics = true;
1384+
}
1385+
13771386
if let Some(relish_uploader) = &self.relish_uploader {
13781387
for label_path in new_historics.iter().filter_map(|layer| layer.path()) {
13791388
relish_uploader.schedule_upload(self.timelineid, label_path);
@@ -1409,6 +1418,14 @@ impl LayeredTimeline {
14091418
layer.unload()?;
14101419
}
14111420

1421+
drop(layers);
1422+
1423+
if created_historics {
1424+
// We must fsync the timeline dir to ensure the directory entries for
1425+
// new layer files are durable
1426+
timeline_dir.sync_all()?;
1427+
}
1428+
14121429
// Save the metadata, with updated 'disk_consistent_lsn', to a
14131430
// file in the timeline dir. After crash, we will restart WAL
14141431
// streaming and processing from that point.

pageserver/src/layered_repository/delta_layer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ impl DeltaLayer {
487487
let book = chapter.close()?;
488488

489489
// This flushes the underlying 'buf_writer'.
490-
book.close()?;
490+
let writer = book.close()?;
491+
writer.get_ref().sync_all()?;
491492

492493
trace!("saved {}", &path.display());
493494

pageserver/src/layered_repository/image_layer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ impl ImageLayer {
337337
let book = chapter.close()?;
338338

339339
// This flushes the underlying 'buf_writer'.
340-
book.close()?;
340+
let writer = book.close()?;
341+
writer.get_ref().sync_all()?;
341342

342343
trace!("saved {}", &path.display());
343344

0 commit comments

Comments
 (0)