Skip to content

Commit

Permalink
cache: store files in one directory identified by digest
Browse files Browse the repository at this point in the history
Signed-off-by: liulanzheng <liulanzheng@gmail.com>
  • Loading branch information
liulanzheng committed Feb 17, 2022
1 parent 39ad2b3 commit a1390fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/overlaybd/fs/cache/full_file_cache/cache_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ void FileCachePool::Init() {
}

ICacheStore *FileCachePool::do_open(std::string_view pathname, int flags, mode_t mode) {
auto localFile = openMedia(pathname, flags, mode);
// use filename (sha256 in overlaybd image) as the key, it's not a universal file cache any more
auto filename = Path(pathname.data()).basename();
auto localFile = openMedia(filename, flags, mode);
if (!localFile) {
return nullptr;
}

auto find = fileIndex_.find(pathname);
auto find = fileIndex_.find(filename);
if (find == fileIndex_.end()) {
auto lruIter = lru_.push_front(fileIndex_.end());
std::unique_ptr<LruEntry> entry(new LruEntry{lruIter, 1, 0});
find = fileIndex_.emplace(pathname, std::move(entry)).first;
find = fileIndex_.emplace(filename, std::move(entry)).first;
lru_.front() = find;
} else {
lru_.access(find->second->lruIter);
Expand Down
4 changes: 2 additions & 2 deletions src/overlaybd/fs/cache/full_file_cache/test/cache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ void commonTest(bool cacheIsFull, bool enableDirControl, bool dirFull) {
EXPECT_EQ(0, memcmp(buf, src.data(), kPageSize));

struct stat st1;
::stat(std::string(root + prefix + "/testDir/file_1").c_str(), &st1);
::stat(std::string(root + prefix + "/file_1").c_str(), &st1);
EXPECT_EQ(0, cachedFile->evict(0, kPageSize));
struct stat st2;
::stat(std::string(root + prefix + "/testDir/file_1").c_str(), &st2);
::stat(std::string(root + prefix + "/file_1").c_str(), &st2);
EXPECT_EQ(kPageSize, st1.st_blocks * 512 - st2.st_blocks * 512);

// test refill last block
Expand Down

0 comments on commit a1390fa

Please sign in to comment.