Skip to content

Commit 1442769

Browse files
byahn0996facebook-github-bot
authored andcommitted
Rename a field with FixedSizeIndex
Summary: Renaming a filed 'sizeForMutex_' which actually means the number of stored buckets within mutex boundary. Original name comes from similar naming with SparseMapIndex, but I feel, with FixedSizeIndex, 'size' doesn't represent what it's supposed to mean. Reviewed By: AlnisM Differential Revision: D81283852 fbshipit-source-id: df8211ba66c4e9e719a06f12f1e832b09a156eee
1 parent 9271965 commit 1442769

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

cachelib/navy/block_cache/FixedSizeIndex.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void FixedSizeIndex::initialize() {
3737

3838
ht_ = std::make_unique<PackedItemRecord[]>(totalBuckets_);
3939
mutex_ = std::make_unique<SharedMutex[]>(totalMutexes_);
40-
sizeForMutex_ = std::make_unique<size_t[]>(totalMutexes_);
40+
validBucketsPerMutex_ = std::make_unique<size_t[]>(totalMutexes_);
4141

4242
bucketDistInfo_.initialize(totalBuckets_);
4343
}
@@ -91,7 +91,7 @@ Index::LookupResult FixedSizeIndex::insert(uint64_t key,
9191
0, /* totalHits */
9292
elb.recordRef().info.curHits));
9393
} else {
94-
++elb.sizeRef();
94+
++elb.validBucketCntRef();
9595
}
9696
// TODO: need to combine this two ops into one to make sure updateDistInfo()
9797
// part is not missed
@@ -123,8 +123,8 @@ Index::LookupResult FixedSizeIndex::remove(uint64_t key) {
123123
0, /* totalHits */
124124
elb.recordRef().info.curHits)};
125125

126-
XDCHECK(elb.sizeRef() > 0);
127-
--elb.sizeRef();
126+
XDCHECK(elb.validBucketCntRef() > 0);
127+
--elb.validBucketCntRef();
128128
elb.recordRef() = PackedItemRecord{};
129129
return lr;
130130
}
@@ -139,8 +139,8 @@ bool FixedSizeIndex::removeIfMatch(uint64_t key, uint32_t address) {
139139
if (elb.recordRef().address == address) {
140140
elb.recordRef() = PackedItemRecord{};
141141

142-
XDCHECK(elb.sizeRef() > 0);
143-
--elb.sizeRef();
142+
XDCHECK(elb.validBucketCntRef() > 0);
143+
--elb.validBucketCntRef();
144144

145145
return true;
146146
}
@@ -154,15 +154,15 @@ void FixedSizeIndex::reset() {
154154
for (uint64_t j = 0; j < numBucketsPerMutex_; ++j) {
155155
ht_[bucketId++] = PackedItemRecord{};
156156
}
157-
sizeForMutex_[i] = 0;
157+
validBucketsPerMutex_[i] = 0;
158158
}
159159
}
160160

161161
size_t FixedSizeIndex::computeSize() const {
162162
size_t size = 0;
163163
for (uint32_t i = 0; i < totalMutexes_; i++) {
164164
auto lock = std::shared_lock{mutex_[i]};
165-
size += sizeForMutex_[i];
165+
size += validBucketsPerMutex_[i];
166166
}
167167

168168
return size;
@@ -246,7 +246,7 @@ void FixedSizeIndex::recover(RecordReader& rr) {
246246
PackedItemRecord{static_cast<uint32_t>(*entry.address()),
247247
static_cast<uint16_t>(*entry.sizeHint()),
248248
static_cast<uint8_t>(*entry.currentHits())};
249-
++sizeForMutex_[*entry.key() / numBucketsPerMutex_];
249+
++validBucketsPerMutex_[*entry.key() / numBucketsPerMutex_];
250250
} else {
251251
ht_[*entry.key()] = PackedItemRecord{};
252252
}

cachelib/navy/block_cache/FixedSizeIndex.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,15 @@ class FixedSizeIndex : public Index {
382382
std::unique_ptr<PackedItemRecord[]> ht_;
383383
std::unique_ptr<SharedMutex[]> mutex_;
384384
// The size for ht (stored bucket count) will be managed per Mutex basis
385-
std::unique_ptr<size_t[]> sizeForMutex_;
385+
std::unique_ptr<size_t[]> validBucketsPerMutex_;
386386

387387
BucketDistInfo bucketDistInfo_;
388388

389389
// A helper class for exclusive locked access to a bucket.
390390
// It will lock the proper mutex with the given key when it's created.
391-
// recordRef() and sizeRef() will return the record and size with exclusively
392-
// locked bucket reference.
393-
// Locked mutex will be released when it's destroyed.
391+
// recordRef() and validBucketCntRef() will return the record and
392+
// valid bucket count with exclusively locked bucket reference. Locked
393+
// mutex will be released when it's destroyed.
394394
class ExclusiveLockedBucket {
395395
public:
396396
explicit ExclusiveLockedBucket(uint64_t key,
@@ -400,7 +400,7 @@ class FixedSizeIndex : public Index {
400400
mid_{index.mutexId(bid_)},
401401
lg_{index.mutex_[mid_]},
402402
record_{&index.ht_[bid_]},
403-
size_{index.sizeForMutex_[mid_]} {
403+
validBuckets_{index.validBucketsPerMutex_[mid_]} {
404404
auto offset = alloc ? index.decideBucketOffset(bid_, key)
405405
: index.checkBucketOffset(bid_, key);
406406
if (offset != 0) {
@@ -411,7 +411,7 @@ class FixedSizeIndex : public Index {
411411
}
412412

413413
PackedItemRecord& recordRef() { return *record_; }
414-
size_t& sizeRef() { return size_; }
414+
size_t& validBucketCntRef() { return validBuckets_; }
415415
void updateDistInfo(uint64_t key, FixedSizeIndex& index) {
416416
index.bucketDistInfo_.updateBucketFillInfo(
417417
bid_, bucketOffset_, index.partialKeyBits(key));
@@ -422,7 +422,7 @@ class FixedSizeIndex : public Index {
422422
uint64_t mid_;
423423
std::lock_guard<SharedMutex> lg_;
424424
PackedItemRecord* record_;
425-
size_t& size_;
425+
size_t& validBuckets_;
426426
uint8_t bucketOffset_{0};
427427
};
428428

0 commit comments

Comments
 (0)