Skip to content

Commit 99a7914

Browse files
xiaoyang-hhhEricHuangqx
authored andcommitted
add parameter storeCacheTTLUsecs (#1139)
1 parent e106243 commit 99a7914

5 files changed

Lines changed: 22 additions & 14 deletions

File tree

fs/cache/cache.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,33 @@ limitations under the License.
2727
namespace photon {
2828
namespace fs{
2929

30-
ICachedFileSystem *new_full_file_cached_fs(IFileSystem *srcFs, IFileSystem *mediaFs,
30+
ICachedFileSystem *new_full_file_cached_fs(IFileSystem *srcFs, IFileSystem *mediaFs,
3131
uint64_t refillUnit, uint64_t capacityInGB,
3232
uint64_t periodInUs, uint64_t diskAvailInBytes,
3333
IOAlloc *allocator, int quotaDirLevel,
34-
CacheFnTransFunc fn_trans_func) {
34+
CacheFnTransFunc fn_trans_func,
35+
uint64_t storeCacheTTLUsecs) {
3536
if (refillUnit % 4096 != 0 || !is_power_of_2(refillUnit)) {
3637
LOG_ERROR_RETURN(EINVAL, nullptr, "refill Unit need to be aligned to 4KB and power of 2")
3738
}
3839
if (!allocator) {
3940
allocator = new IOAlloc;
4041
}
4142
FileCachePool *pool = nullptr;
42-
pool =
43-
new FileCachePool(mediaFs, capacityInGB, periodInUs, diskAvailInBytes, refillUnit);
43+
pool = new FileCachePool(mediaFs, capacityInGB, periodInUs, diskAvailInBytes,
44+
refillUnit, storeCacheTTLUsecs);
4445
pool->Init();
4546
return new_cached_fs(srcFs, pool, 4096, allocator, fn_trans_func);
4647
}
4748

4849
using OC = ObjectCache<std::string, ICacheStore*>;
49-
ICachePool::ICachePool(uint32_t pool_size, uint32_t max_refilling, uint32_t refilling_threshold, bool pin_write)
50-
: m_stores(new OC(10UL * 1000 * 1000)),
51-
m_max_refilling(max_refilling),
52-
m_refilling_threshold(refilling_threshold),
53-
m_pin_write(pin_write) {
50+
ICachePool::ICachePool(uint32_t pool_size, uint32_t max_refilling,
51+
uint32_t refilling_threshold, bool pin_write,
52+
uint64_t store_cache_ttl_usecs)
53+
: m_stores(new OC(store_cache_ttl_usecs)),
54+
m_max_refilling(max_refilling),
55+
m_refilling_threshold(refilling_threshold),
56+
m_pin_write(pin_write) {
5457
if (pool_size != 0) {
5558
m_thread_pool = photon::new_thread_pool(pool_size, 128 * 1024UL);
5659
m_vcpu = photon::get_vcpu();

fs/cache/cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ ICachedFileSystem *new_full_file_cached_fs(IFileSystem *srcFs,
116116
uint64_t capacityInGB, uint64_t periodInUs,
117117
uint64_t diskAvailInBytes, IOAlloc *allocator,
118118
int quotaDirLevel,
119-
CacheFnTransFunc fn_trans_func = nullptr);
119+
CacheFnTransFunc fn_trans_func = nullptr,
120+
uint64_t storeCacheTTLUsecs = 10'000'000);
120121

121122
/**
122123
* @param blk_size The proper size for cache metadata and IO efficiency. Large writes to cache media

fs/cache/full_file_cache/cache_pool.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ const uint64_t kMaxFreeSpace = 50 * kGB;
3737
const int64_t kEvictionMark = 5ll * kGB;
3838

3939
FileCachePool::FileCachePool(IFileSystem* mediaFs, uint64_t capacityInGB,
40-
uint64_t periodInUs, uint64_t diskAvailInBytes, uint64_t refillUnit)
41-
: ICachePool(0),
40+
uint64_t periodInUs, uint64_t diskAvailInBytes, uint64_t refillUnit,
41+
uint64_t storeCacheTTLUsecs)
42+
: ICachePool(0, 128, -1U, false, storeCacheTTLUsecs),
4243
mediaFs_(mediaFs),
4344
capacityInGB_(capacityInGB),
4445
periodInUs_(periodInUs),

fs/cache/full_file_cache/cache_pool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ namespace fs {
3535
class FileCachePool : public photon::fs::ICachePool {
3636
public:
3737
FileCachePool(photon::fs::IFileSystem *mediaFs, uint64_t capacityInGB, uint64_t periodInUs,
38-
uint64_t diskAvailInBytes, uint64_t refillUnit);
38+
uint64_t diskAvailInBytes, uint64_t refillUnit,
39+
uint64_t storeCacheTTLUsecs = 10'000'000);
3940
~FileCachePool();
4041

4142
static const uint64_t kDiskBlockSize = 512; // stat(2)

fs/cache/pool_store.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ namespace fs
7979
class ICachePool : public Object
8080
{
8181
public:
82-
ICachePool(uint32_t pool_size = 128, uint32_t max_refilling = 128, uint32_t refilling_threshold = -1U, bool pin_write = false);
82+
ICachePool(uint32_t pool_size = 128, uint32_t max_refilling = 128,
83+
uint32_t refilling_threshold = -1U, bool pin_write = false,
84+
uint64_t store_cache_ttl_usecs = 10'000'000);
8385
~ICachePool();
8486

8587
ICacheStore* open(std::string_view filename, int flags, mode_t mode);

0 commit comments

Comments
 (0)