From edbe3d2f760efa03bf12acf704b86f81d85a34be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arpad=20M=C3=BCller?= Date: Mon, 28 Aug 2023 11:49:56 +0200 Subject: [PATCH] Remove Read impl that was only used in one place --- pageserver/src/tenant/manifest.rs | 17 +++++++++-------- pageserver/src/virtual_file.rs | 11 +---------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/pageserver/src/tenant/manifest.rs b/pageserver/src/tenant/manifest.rs index 1d2835114f..fef66abd4f 100644 --- a/pageserver/src/tenant/manifest.rs +++ b/pageserver/src/tenant/manifest.rs @@ -26,7 +26,7 @@ //! recovered from this file. This is tracked in //! -use std::io::{self, Read, Write}; +use std::io::{self, Write}; use crate::virtual_file::VirtualFile; use anyhow::Result; @@ -151,11 +151,12 @@ impl Manifest { /// Load a manifest. Returns the manifest and a list of operations. If the manifest is corrupted, /// the bool flag will be set to true and the user is responsible to reconstruct a new manifest and /// backup the current one. - pub fn load( - mut file: VirtualFile, + pub async fn load( + file: VirtualFile, ) -> Result<(Self, Vec, ManifestPartiallyCorrupted), ManifestLoadError> { let mut buf = vec![]; - file.read_to_end(&mut buf).map_err(ManifestLoadError::Io)?; + file.read_exact_at(&mut buf, 0) + .map_err(ManifestLoadError::Io)?; // Read manifest header let mut buf = Bytes::from(buf); @@ -241,8 +242,8 @@ mod tests { use super::*; - #[test] - fn test_read_manifest() { + #[tokio::test] + async fn test_read_manifest() { let testdir = crate::config::PageServerConf::test_repo_dir("test_read_manifest"); std::fs::create_dir_all(&testdir).unwrap(); let file = VirtualFile::create(&testdir.join("MANIFEST")).unwrap(); @@ -274,7 +275,7 @@ mod tests { .truncate(false), ) .unwrap(); - let (mut manifest, operations, corrupted) = Manifest::load(file).unwrap(); + let (mut manifest, operations, corrupted) = Manifest::load(file).await.unwrap(); assert!(!corrupted.0); assert_eq!(operations.len(), 2); assert_eq!( @@ -306,7 +307,7 @@ mod tests { .truncate(false), ) .unwrap(); - let (_manifest, operations, corrupted) = Manifest::load(file).unwrap(); + let (_manifest, operations, corrupted) = Manifest::load(file).await.unwrap(); assert!(!corrupted.0); assert_eq!(operations.len(), 3); assert_eq!(&operations[0], &Operation::Snapshot(snapshot, Lsn::from(0))); diff --git a/pageserver/src/virtual_file.rs b/pageserver/src/virtual_file.rs index 33645525df..8e4f103158 100644 --- a/pageserver/src/virtual_file.rs +++ b/pageserver/src/virtual_file.rs @@ -13,7 +13,7 @@ use crate::metrics::{STORAGE_IO_SIZE, STORAGE_IO_TIME}; use once_cell::sync::OnceCell; use std::fs::{self, File, OpenOptions}; -use std::io::{Error, ErrorKind, Read, Seek, SeekFrom, Write}; +use std::io::{Error, ErrorKind, Seek, SeekFrom, Write}; use std::os::unix::fs::FileExt; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; @@ -430,15 +430,6 @@ impl Drop for VirtualFile { } } -impl Read for VirtualFile { - fn read(&mut self, buf: &mut [u8]) -> Result { - let pos = self.pos; - let n = self.read_at(buf, pos)?; - self.pos += n as u64; - Ok(n) - } -} - impl Write for VirtualFile { fn write(&mut self, buf: &[u8]) -> Result { let pos = self.pos;