Skip to content

Commit

Permalink
review: copy open_options instead of taking mut
Browse files Browse the repository at this point in the history
Signed-off-by: Yuchen Liang <[email protected]>
  • Loading branch information
yliang412 committed Oct 8, 2024
1 parent f1418ca commit 4b60df5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pageserver/src/virtual_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ impl VirtualFile {
path: P,
ctx: &RequestContext,
) -> Result<Self, std::io::Error> {
Self::open_with_options_v2(path.as_ref(), OpenOptions::new().read(true), ctx).await
let open_options = {
let mut options = OpenOptions::new();
options.read(true);
options
};
Self::open_with_options_v2(path.as_ref(), open_options, ctx).await
}

pub async fn create<P: AsRef<Utf8Path>>(
Expand All @@ -121,12 +126,12 @@ impl VirtualFile {
path: P,
ctx: &RequestContext,
) -> Result<Self, std::io::Error> {
VirtualFile::open_with_options_v2(
path.as_ref(),
OpenOptions::new().write(true).create(true).truncate(true),
ctx,
)
.await
let open_options = {
let mut options = OpenOptions::new();
options.write(true).create(true).truncate(true);
options
};
VirtualFile::open_with_options_v2(path.as_ref(), open_options, ctx).await
}

pub async fn open_with_options<P: AsRef<Utf8Path>>(
Expand All @@ -140,12 +145,12 @@ impl VirtualFile {

pub async fn open_with_options_v2<P: AsRef<Utf8Path>>(
path: P,
open_options: &mut OpenOptions, // Uses `&mut` here to add `O_DIRECT`.
open_options: OpenOptions,
ctx: &RequestContext, /* TODO: carry a pointer to the metrics in the RequestContext instead of the parsing https://github.com/neondatabase/neon/issues/6107 */
) -> Result<Self, std::io::Error> {
let file = match get_io_mode() {
IoMode::Buffered => {
let file = VirtualFileInner::open_with_options(path, open_options, ctx).await?;
let file = VirtualFileInner::open_with_options(path, &open_options, ctx).await?;
Self::Buffered(file)
}
#[cfg(target_os = "linux")]
Expand Down

0 comments on commit 4b60df5

Please sign in to comment.