Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] full file cache on XFS #297

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/overlaybd/cache/full_file_cache/cache_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void FileCachePool::eviction() {
{
photon::scoped_rwlock rl(lruEntry->rw_lock_, photon::WLOCK);
err = mediaFs_->truncate(fileName.data(), 0);
lruEntry->truncate_done = false;
}

if (err) {
Expand Down
3 changes: 2 additions & 1 deletion src/overlaybd/cache/full_file_cache/cache_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ class FileCachePool : public FileSystem::ICachePool {

struct LruEntry {
LruEntry(uint32_t lruIt, int openCnt, uint64_t fileSize)
: lruIter(lruIt), openCount(openCnt), size(fileSize) {
: lruIter(lruIt), openCount(openCnt), size(fileSize), truncate_done(false) {
}
~LruEntry() = default;
uint32_t lruIter;
int openCount;
uint64_t size;
photon::rwlock rw_lock_;
bool truncate_done;
};

// Normally, fileIndex(std::map) always keep growing, so its iterators always
Expand Down
17 changes: 17 additions & 0 deletions src/overlaybd/cache/full_file_cache/cache_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ FileCacheStore::~FileCacheStore() {
cachePool_->removeOpenFile(iterator_);
}

ICacheStore::try_preadv_result FileCacheStore::try_preadv2(const struct iovec *iov, int iovcnt,
off_t offset, int flags) {
auto lruEntry = static_cast<FileCachePool::LruEntry *>(iterator_->second.get());
photon::scoped_rwlock rl(lruEntry->rw_lock_, photon::RLOCK);
return this->ICacheStore::try_preadv2(iov, iovcnt, offset, flags);
}

ssize_t FileCacheStore::do_preadv2(const struct iovec *iov, int iovcnt, off_t offset, int flags) {
// TODO(suoshi.yf): maybe a new interface for updating lru is better for avoiding
// multiple cacheStore preadvs but cacheFile preadv only once
Expand All @@ -60,6 +67,16 @@ ssize_t FileCacheStore::do_preadv2(const struct iovec *iov, int iovcnt, off_t of
ssize_t FileCacheStore::do_pwritev(const struct iovec *iov, int iovcnt, off_t offset) {
ssize_t ret;
iovector_view view((iovec *)iov, iovcnt);
auto lruEntry = static_cast<FileCachePool::LruEntry *>(iterator_->second.get());
photon::scoped_rwlock rl(lruEntry->rw_lock_, photon::RLOCK);
if (!lruEntry->truncate_done) {
// May repeated ftruncate() here, but it doesn't matter
ret = localFile_->ftruncate(actual_size_);
if (ret) {
LOG_ERRNO_RETURN(0, -1, "failed to truncate media file: ", VALUE(ret));
}
lruEntry->truncate_done = true;
}
ScopedRangeLock lock(rangeLock_, offset, view.sum());
SCOPE_AUDIT_THRESHOLD(10UL * 1000, "file:write", AU_FILEOP("", offset, ret));
ret = localFile_->pwritev(iov, iovcnt, offset);
Expand Down
2 changes: 2 additions & 0 deletions src/overlaybd/cache/full_file_cache/cache_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class FileCacheStore : public FileSystem::ICacheStore {
size_t refillUnit, FileIterator iterator);
~FileCacheStore();

try_preadv_result try_preadv2(const struct iovec *iov, int iovcnt, off_t offset, int flags) override;

ssize_t do_preadv2(const struct iovec *iov, int iovcnt, off_t offset, int flags) override;

ssize_t do_pwritev2(const struct iovec *iov, int iovcnt, off_t offset, int flags) override;
Expand Down