Skip to content

Commit

Permalink
fixup file cache dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
baichuan3 committed Jul 6, 2024
1 parent 46890a2 commit 521fc47
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4,335 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions crates/rooch-common/src/fs/file_cache.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use libc::{posix_fadvise, POSIX_FADV_DONTNEED};
use std::fs::File;
use std::io::{Error, Result};
use std::io::Result;
#[cfg(target_os = "linux")]
use std::os::unix::io::AsRawFd;
use std::path::PathBuf;

#[allow(dead_code)]
pub struct FileCacheManager {
file: File,
}
Expand All @@ -17,21 +18,27 @@ impl FileCacheManager {
Ok(FileCacheManager { file })
}

#[cfg(target_os = "linux")]
pub fn drop_cache_range(&self, offset: u64, len: u64) -> Result<()> {
let fd = self.file.as_raw_fd();
let ret = unsafe {
posix_fadvise(
libc::posix_fadvise(
fd,
offset as libc::off_t,
len as libc::off_t,
POSIX_FADV_DONTNEED,
libc::POSIX_FADV_DONTNEED,
)
};

if ret != 0 {
return Err(Error::from_raw_os_error(ret));
return Err(std::io::Error::from_raw_os_error(ret));
}

Ok(())
}

#[cfg(not(target_os = "linux"))]
pub fn drop_cache_range(&self, _offset: u64, _len: u64) -> Result<()> {
Ok(())
}
}
Loading

0 comments on commit 521fc47

Please sign in to comment.