Skip to content

Commit 76efb1b

Browse files
committed
Revert "CP: use hacked-together open_at for async VirtualFile open calls instead of spawn_blocking"
This reverts commit 55cdf6c.
1 parent 2f656c6 commit 76efb1b

File tree

6 files changed

+44
-124
lines changed

6 files changed

+44
-124
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pageserver/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ enumset.workspace = true
8383
strum.workspace = true
8484
strum_macros.workspace = true
8585
tokio-epoll-uring = { path = "/home/admin/tokio-epoll-uring/tokio-epoll-uring" }
86-
#tokio-epoll-uring = { git = "https://github.com/neondatabase/tokio-epoll-uring.git" , branch = "problame/hacky-openat" }
8786

8887
[dev-dependencies]
8988
criterion.workspace = true

pageserver/src/tenant/ephemeral_file.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ impl EphemeralFile {
4444
"ephemeral-{filename_disambiguator}"
4545
)));
4646

47-
let file = {
48-
let mut options = tokio_epoll_uring::ops::open_at::OpenOptions::new();
49-
options.read(true).write(true).create(true);
50-
VirtualFile::open_with_options_async(&filename, options).await?
51-
};
47+
let file = VirtualFile::open_with_options(
48+
&filename,
49+
OpenOptions::new().read(true).write(true).create(true),
50+
)
51+
.await?;
5252

5353
Ok(EphemeralFile {
5454
page_cache_file_id: page_cache::next_file_id(),
@@ -89,8 +89,7 @@ impl EphemeralFile {
8989
return Ok(BlockLease::PageReadGuard(guard))
9090
}
9191
page_cache::ReadBufResult::NotFound(mut write_guard) => {
92-
let write_guard = self
93-
.file
92+
let write_guard = self.file
9493
.read_exact_at(write_guard, blknum as u64 * PAGE_SZ as u64)
9594
.await?;
9695
let read_guard = write_guard.mark_valid();

pageserver/src/tenant/storage_layer/delta_layer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -852,12 +852,12 @@ impl DeltaLayer {
852852
new_timeline: TimelineId,
853853
ctx: &RequestContext,
854854
) -> anyhow::Result<()> {
855-
let mut options = tokio_epoll_uring::ops::open_at::OpenOptions::new();
856-
options.read(true)
857-
.write(true);
858-
let file = VirtualFile::open_with_options_async(path, options)
859-
.await
860-
.with_context(|| format!("Failed to open file '{}'", path))?;
855+
let file = VirtualFile::open_with_options(
856+
path,
857+
&*std::fs::OpenOptions::new().read(true).write(true),
858+
)
859+
.await
860+
.with_context(|| format!("Failed to open file '{}'", path))?;
861861
let file = FileBlockReader::new(file);
862862
let summary_blk = file.read_blk(0, ctx).await?;
863863
let actual_summary = Summary::des_prefix(summary_blk.as_ref())?;

pageserver/src/tenant/storage_layer/image_layer.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,12 @@ impl ImageLayer {
444444
new_timeline: TimelineId,
445445
ctx: &RequestContext,
446446
) -> anyhow::Result<()> {
447-
let mut options = tokio_epoll_uring::ops::open_at::OpenOptions::new();
448-
options.read(true).write(true);
449-
let file = VirtualFile::open_with_options_async(path, options)
450-
.await
451-
.with_context(|| format!("Failed to open file '{}'", path))?;
447+
let file = VirtualFile::open_with_options(
448+
path,
449+
&*std::fs::OpenOptions::new().read(true).write(true),
450+
)
451+
.await
452+
.with_context(|| format!("Failed to open file '{}'", path))?;
452453
let file = FileBlockReader::new(file);
453454
let summary_blk = file.read_blk(0, ctx).await?;
454455
let actual_summary = Summary::des_prefix(summary_blk.as_ref())?;
@@ -600,11 +601,11 @@ impl ImageLayerWriterInner {
600601
},
601602
);
602603
info!("new image layer {path}");
603-
let mut file = {
604-
let mut options = tokio_epoll_uring::ops::open_at::OpenOptions::new();
605-
options.write(true).create_new(true);
606-
VirtualFile::open_with_options_async(&path, options).await?
607-
};
604+
let mut file = VirtualFile::open_with_options(
605+
&path,
606+
std::fs::OpenOptions::new().write(true).create_new(true),
607+
)
608+
.await?;
608609
// make room for the header block
609610
file.seek(SeekFrom::Start(PAGE_SZ as u64)).await?;
610611
let blob_writer = BlobWriter::new(file, PAGE_SZ as u64);

pageserver/src/virtual_file.rs

Lines changed: 18 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct VirtualFile {
5555
/// opened, in the VirtualFile::create() function, and strip the flag before
5656
/// storing it here.
5757
pub path: Utf8PathBuf,
58-
open_options: tokio_epoll_uring::ops::open_at::OpenOptions,
58+
open_options: OpenOptions,
5959

6060
// These are strings becase we only use them for metrics, and those expect strings.
6161
// It makes no sense for us to constantly turn the `TimelineId` and `TenantId` into
@@ -237,25 +237,24 @@ macro_rules! with_file {
237237
impl VirtualFile {
238238
/// Open a file in read-only mode. Like File::open.
239239
pub async fn open(path: &Utf8Path) -> Result<VirtualFile, std::io::Error> {
240-
let mut options = tokio_epoll_uring::ops::open_at::OpenOptions::new();
241-
options.read(true);
242-
Self::open_with_options_async(path, options).await
240+
Self::open_with_options(path, OpenOptions::new().read(true)).await
243241
}
244242

245243
/// Create a new file for writing. If the file exists, it will be truncated.
246244
/// Like File::create.
247245
pub async fn create(path: &Utf8Path) -> Result<VirtualFile, std::io::Error> {
248-
let mut options = tokio_epoll_uring::ops::open_at::OpenOptions::new();
249-
options.write(true).create(true).truncate(true);
250-
Self::open_with_options_async(path, options).await
246+
Self::open_with_options(
247+
path,
248+
OpenOptions::new().write(true).create(true).truncate(true),
249+
)
250+
.await
251251
}
252252

253253
/// Open a file with given options.
254254
///
255255
/// Note: If any custom flags were set in 'open_options' through OpenOptionsExt,
256256
/// they will be applied also when the file is subsequently re-opened, not only
257257
/// on the first time. Make sure that's sane!
258-
#[cfg(test)]
259258
pub async fn open_with_options(
260259
path: &Utf8Path,
261260
open_options: &OpenOptions,
@@ -318,17 +317,16 @@ impl VirtualFile {
318317
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
319318
Err(e) => return Err(CrashsafeOverwriteError::RemovePreviousTempfile(e)),
320319
}
321-
let mut file = {
322-
let mut options = tokio_epoll_uring::ops::open_at::OpenOptions::new();
323-
options
320+
let mut file = Self::open_with_options(
321+
tmp_path,
322+
OpenOptions::new()
324323
.write(true)
325324
// Use `create_new` so that, if we race with ourselves or something else,
326325
// we bail out instead of causing damage.
327-
.create_new(true);
328-
Self::open_with_options_async(tmp_path, options)
329-
.await
330-
.map_err(CrashsafeOverwriteError::CreateTempfile)?
331-
};
326+
.create_new(true),
327+
)
328+
.await
329+
.map_err(CrashsafeOverwriteError::CreateTempfile)?;
332330
file.write_all(content)
333331
.await
334332
.map_err(CrashsafeOverwriteError::WriteContents)?;
@@ -344,80 +342,17 @@ impl VirtualFile {
344342
// the current `find_victim_slot` impl might pick the same slot for both
345343
// VirtualFile., and it eventually does a blocking write lock instead of
346344
// try_lock.
347-
let final_parent_dirfd = {
348-
let mut options = tokio_epoll_uring::ops::open_at::OpenOptions::new();
349-
options.read(true);
350-
Self::open_with_options_async(final_path_parent, options)
345+
let final_parent_dirfd =
346+
Self::open_with_options(final_path_parent, OpenOptions::new().read(true))
351347
.await
352-
.map_err(CrashsafeOverwriteError::OpenFinalPathParentDir)?
353-
};
348+
.map_err(CrashsafeOverwriteError::OpenFinalPathParentDir)?;
354349
final_parent_dirfd
355350
.sync_all()
356351
.await
357352
.map_err(CrashsafeOverwriteError::SyncFinalPathParentDir)?;
358353
Ok(())
359354
}
360355

361-
/// Open a file with given options.
362-
///
363-
/// Note: If any custom flags were set in 'open_options' through OpenOptionsExt,
364-
/// they will be applied also when the file is subsequently re-opened, not only
365-
/// on the first time. Make sure that's sane!
366-
pub async fn open_with_options_async(
367-
path: &Utf8Path,
368-
open_options: tokio_epoll_uring::ops::open_at::OpenOptions,
369-
) -> Result<VirtualFile, std::io::Error> {
370-
let path_str = path.to_string();
371-
let parts = path_str.split('/').collect::<Vec<&str>>();
372-
let tenant_id;
373-
let timeline_id;
374-
if parts.len() > 5 && parts[parts.len() - 5] == "tenants" {
375-
tenant_id = parts[parts.len() - 4].to_string();
376-
timeline_id = parts[parts.len() - 2].to_string();
377-
} else {
378-
tenant_id = "*".to_string();
379-
timeline_id = "*".to_string();
380-
}
381-
let (handle, mut slot_guard) = get_open_files().find_victim_slot().await;
382-
383-
let file = {
384-
let start = std::time::Instant::now();
385-
let system = tokio_epoll_uring::thread_local_system().await;
386-
let file: OwnedFd = system
387-
.open(path, &open_options)
388-
.await
389-
.map_err(|e| match e {
390-
tokio_epoll_uring::Error::Op(e) => e,
391-
tokio_epoll_uring::Error::System(system) => {
392-
std::io::Error::new(std::io::ErrorKind::Other, system)
393-
}
394-
})?;
395-
let file = File::from(file);
396-
file
397-
};
398-
399-
// Strip all options other than read and write.
400-
//
401-
// It would perhaps be nicer to check just for the read and write flags
402-
// explicitly, but OpenOptions doesn't contain any functions to read flags,
403-
// only to set them.
404-
let mut reopen_options = open_options;
405-
reopen_options.create(false);
406-
reopen_options.create_new(false);
407-
reopen_options.truncate(false);
408-
409-
let vfile = VirtualFile {
410-
handle: RwLock::new(handle),
411-
pos: 0,
412-
path: path.to_path_buf(),
413-
open_options: reopen_options,
414-
tenant_id,
415-
timeline_id,
416-
};
417-
418-
Ok(vfile)
419-
}
420-
421356
/// Call File::sync_all() on the underlying File.
422357
pub async fn sync_all(&self) -> Result<(), Error> {
423358
with_file!(self, StorageIoOperation::Fsync, |file| file
@@ -480,21 +415,7 @@ impl VirtualFile {
480415
let (handle, mut slot_guard) = open_files.find_victim_slot().await;
481416

482417
// Open the physical file
483-
let file = {
484-
let system = tokio_epoll_uring::thread_local_system().await;
485-
let file: OwnedFd =
486-
system
487-
.open(&self.path, &self.open_options)
488-
.await
489-
.map_err(|e| match e {
490-
tokio_epoll_uring::Error::Op(e) => e,
491-
tokio_epoll_uring::Error::System(system) => {
492-
std::io::Error::new(std::io::ErrorKind::Other, system)
493-
}
494-
})?;
495-
let file = File::from(file);
496-
file
497-
};
418+
let file = observe_duration!(StorageIoOperation::Open, self.open_options.open(&self.path))?;
498419

499420
// Store the File in the slot and update the handle in the VirtualFile
500421
// to point to it.

0 commit comments

Comments
 (0)