Skip to content

Commit ce24df5

Browse files
pbhandar2meta-codesync[bot]
authored andcommitted
Thread lastAccessTimeSecs through BlockCache write path
Summary: This diff modifies the BlockCache write path to include the last access time in seconds. The `insert` function in several files (`BlockCache.cpp`, `Driver.h`, `EnginePair.h`, `BigHash.h`, and `NoopEngine.h`) is updated to take an additional `lastAccessTimeSecs` parameter. This change allows the DRAM cache to pass last accessed time to be stored in BlockCache. This is needed for TTA based item lifetime enforcement. Reviewed By: byahn0996 Differential Revision: D94716016 fbshipit-source-id: 79665972400474355aa8ffc5761b04ba9195a53a
1 parent d308c02 commit ce24df5

13 files changed

Lines changed: 129 additions & 75 deletions

File tree

cachelib/allocator/nvmcache/NvmCache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,8 @@ void NvmCache<C>::put(Item& item, PutToken token) {
12281228
}
12291229
recordEvent(AllocatorApiEvent::NVM_INSERT, key.key(), eventRes);
12301230
putCleanup();
1231-
});
1231+
},
1232+
item.getLastAccessTime());
12321233

12331234
if (status == navy::Status::Ok) {
12341235
guard.dismiss();

cachelib/navy/AbstractCache.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ class AbstractCache {
6767

6868
// Inserts entry into cache.
6969
// Returns: Ok, Rejected, DeviceError
70-
virtual Status insert(HashedKey key, BufferView value) = 0;
70+
// TODO: For now passing lastAccessTimeSecs as a param. This is
71+
// temporary until ItemMetadata lands. After that, we will pass
72+
// ItemMetadata as a param.
73+
virtual Status insert(HashedKey key,
74+
BufferView value,
75+
uint32_t lastAccessTimeSecs = 0) = 0;
7176

7277
// Asynchronously inserts entry into the cache.
7378
// Invokes callback when done on a worker thread. Callback is optional.
@@ -78,7 +83,8 @@ class AbstractCache {
7883
// Returns: Ok, Rejected
7984
virtual Status insertAsync(HashedKey key,
8085
BufferView value,
81-
InsertCallback cb) = 0;
86+
InsertCallback cb,
87+
uint32_t lastAccessTimeSecs = 0) = 0;
8288

8389
// Looks up value. Returns non-null buffer if found.
8490
// Returns: Ok, NotFound, DeviceError

cachelib/navy/bighash/BigHash.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ bool BigHash::recover(RecordReader& rr) {
292292
return true;
293293
}
294294

295-
Status BigHash::insert(HashedKey hk, BufferView value) {
295+
Status BigHash::insert(HashedKey hk,
296+
BufferView value,
297+
uint32_t /* lastAccessTimeSecs */) {
296298
const auto bid = getBucketId(hk);
297299
insertCount_.inc();
298300

cachelib/navy/bighash/BigHash.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ class BigHash final : public Engine, folly::NonCopyableNonMovable {
116116

117117
// Inserts key and value into BigHash. This will replace an existing
118118
// key if found. If it failed to write, it will return DeviceError.
119-
Status insert(HashedKey hk, BufferView value) override;
119+
Status insert(HashedKey hk,
120+
BufferView value,
121+
uint32_t lastAccessTimeSecs = 0) override;
120122

121123
// Removes an entry from BigHash if found. Ok on success, NotFound on miss,
122124
// and DeviceError on error.

cachelib/navy/block_cache/BlockCache.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ uint32_t BlockCache::serializedSize(uint32_t keySize,
207207
return powTwoAlign(size, allocAlignSize_);
208208
}
209209

210-
Status BlockCache::insert(HashedKey hk, BufferView value) {
210+
Status BlockCache::insert(HashedKey hk,
211+
BufferView value,
212+
uint32_t lastAccessTimeSecs) {
211213
auto start = getSteadyClock();
212214
SCOPE_EXIT {
213215
insertLatency_.trackValue(toMicros(getSteadyClock() - start).count());
@@ -222,7 +224,7 @@ Status BlockCache::insert(HashedKey hk, BufferView value) {
222224

223225
// After allocation a region is opened for writing. Until we close it, the
224226
// region would not be reclaimed and index never gets an invalid entry.
225-
writeEntry(addr, slotSize, hk, value);
227+
writeEntry(addr, slotSize, hk, value, lastAccessTimeSecs);
226228
updateIndex(hk.keyHash(), slotSize, addr, /* allowReplace */ true);
227229
allocator_.close(std::move(desc));
228230
INJECT_PAUSE(pause_blockcache_insert_done);
@@ -1033,21 +1035,26 @@ BlockCache::allocateForInsert(const HashedKey& hk, const uint32_t valueSize) {
10331035
}
10341036

10351037
/* static */ BlockCache::EntryDesc* BlockCache::writeEntryDescAndKey(
1036-
Buffer& buffer, const HashedKey& hk, uint32_t valueSize) {
1038+
Buffer& buffer,
1039+
const HashedKey& hk,
1040+
uint32_t valueSize,
1041+
uint32_t lastAccessTimeSecs) {
10371042
// Copy descriptor and the key to the end
10381043
size_t descOffset = buffer.size() - sizeof(EntryDesc);
10391044
auto desc = new (buffer.data() + descOffset)
1040-
EntryDesc(hk.key().size(), valueSize, hk.keyHash());
1045+
EntryDesc(hk.key().size(), valueSize, hk.keyHash(), lastAccessTimeSecs);
10411046
buffer.copyFrom(descOffset - hk.key().size(), makeView(hk.key()));
10421047
return desc;
10431048
}
10441049

10451050
void BlockCache::writeEntry(RelAddress addr,
10461051
uint32_t size,
10471052
HashedKey hk,
1048-
BufferView value) {
1053+
BufferView value,
1054+
uint32_t lastAccessTimeSecs) {
10491055
auto buffer = Buffer(size);
1050-
auto* desc = writeEntryDescAndKey(buffer, hk, value.size());
1056+
auto* desc =
1057+
writeEntryDescAndKey(buffer, hk, value.size(), lastAccessTimeSecs);
10511058
if (checksumData_) {
10521059
desc->cs = checksum(value);
10531060
}

cachelib/navy/block_cache/BlockCache.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ class BlockCache final : public Engine {
143143
// @return Status::Ok on success,
144144
// Status::Rejected on error,
145145
// Status::Retry on no space available for now.
146-
Status insert(HashedKey hk, BufferView value) override;
146+
Status insert(HashedKey hk,
147+
BufferView value,
148+
uint32_t lastAccessTimeSecs = 0) override;
147149

148150
// Looks up a key in BlockCache.
149151
//
@@ -293,7 +295,8 @@ class BlockCache final : public Engine {
293295
// @param valueSize size of the value to be inserted
294296
static EntryDesc* writeEntryDescAndKey(Buffer& buffer,
295297
const HashedKey& hk,
296-
uint32_t valueSize);
298+
uint32_t valueSize,
299+
uint32_t lastAccessTimeSecs = 0);
297300

298301
struct LookupData {
299302
Buffer buffer_;
@@ -316,7 +319,8 @@ class BlockCache final : public Engine {
316319
void writeEntry(RelAddress addr,
317320
uint32_t size,
318321
HashedKey hk,
319-
BufferView value);
322+
BufferView value,
323+
uint32_t lastAccessTimeSecs = 0);
320324
// @param ld LookupData containing the entry metadata for reading
321325
// @param addrEnd End of the entry since the item layout is backward
322326
// @param approxSize Approximate size since we got this size from index

cachelib/navy/driver/Driver.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,18 @@ uint64_t Driver::estimateWriteSize(HashedKey hk, BufferView value) const {
110110
: hk.key().size() + value.size();
111111
}
112112

113-
Status Driver::insert(HashedKey key, BufferView value) {
113+
Status Driver::insert(HashedKey key,
114+
BufferView value,
115+
uint32_t lastAccessTimeSecs) {
114116
trace::Profiled<folly::fibers::Baton, "cachelib:navy:driver_insert"> done;
115117
Status cbStatus{Status::Ok};
116-
auto status = insertAsync(key, value,
117-
[&done, &cbStatus](Status s, HashedKey /* key */) {
118-
cbStatus = s;
119-
done.post();
120-
});
118+
auto status = insertAsync(
119+
key, value,
120+
[&done, &cbStatus](Status s, HashedKey /* key */) {
121+
cbStatus = s;
122+
done.post();
123+
},
124+
lastAccessTimeSecs);
121125
if (status != Status::Ok) {
122126
return status;
123127
}
@@ -171,7 +175,10 @@ bool Driver::admissionTest(HashedKey hk, BufferView value) const {
171175
return false;
172176
}
173177

174-
Status Driver::insertAsync(HashedKey hk, BufferView value, InsertCallback cb) {
178+
Status Driver::insertAsync(HashedKey hk,
179+
BufferView value,
180+
InsertCallback cb,
181+
uint32_t lastAccessTimeSecs) {
175182
if (hk.key().size() > maxKeySize_) {
176183
rejectedCount_.inc();
177184
rejectedBytes_.add(hk.key().size() + value.size());
@@ -200,7 +207,8 @@ Status Driver::insertAsync(HashedKey hk, BufferView value, InsertCallback cb) {
200207
}
201208
parcelMemory_.sub(totalSize);
202209
concurrentInserts_.dec();
203-
});
210+
},
211+
lastAccessTimeSecs);
204212
return Status::Ok;
205213
}
206214

cachelib/navy/driver/Driver.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ class Driver final : public AbstractCache {
8686
// @param key the item key
8787
// @param value the item value
8888
// @return a status indicates success or failure, and the reason for failure
89-
Status insert(HashedKey key, BufferView value) override;
89+
Status insert(HashedKey key,
90+
BufferView value,
91+
uint32_t lastAccessTimeSecs = 0) override;
9092

9193
// insert a key and value into the cache asynchronously.
9294
// @param key the item key
@@ -96,7 +98,8 @@ class Driver final : public AbstractCache {
9698
// reason for failure
9799
Status insertAsync(HashedKey key,
98100
BufferView value,
99-
InsertCallback cb) override;
101+
InsertCallback cb,
102+
uint32_t lastAccessTimeSecs = 0) override;
100103

101104
// lookup a key in the cache.
102105
// @param key the item key to lookup

0 commit comments

Comments
 (0)