Skip to content

Commit 3c8b5eb

Browse files
committed
MB-27554: [BP] Move numTotalItems from HashTable -> VBucket
Originally 04d6809 In Full-Eviction, items may exist in a VBucket without being in the HashTable, as they may have been fully evicted. As such, numTotalItems is not a property of the HashTable, it is a property of the VBucket. Therefore move numTotalItems from HashTable to VBucket, to better encapsulate the VBucket's state. Change-Id: Ic45de1ee49468753d7cc76804f8c5cc9eb64f881 Reviewed-on: http://review.couchbase.org/88381 Well-Formed: Build Bot <[email protected]> Reviewed-by: Jim Walker <[email protected]> Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 46152ca commit 3c8b5eb

File tree

10 files changed

+59
-27
lines changed

10 files changed

+59
-27
lines changed

engines/ep/src/ep_bucket.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ void EPBucket::flushOneDeleteAll() {
605605
getRWUnderlying(vb->getId())->reset(i);
606606
}
607607
// Reset disk item count.
608-
vb->ht.setNumTotalItems(0);
608+
vb->setNumTotalItems(0);
609609
}
610610

611611
--stats.diskQueueSize;
@@ -941,7 +941,7 @@ class EPDiskRollbackCB : public RollbackCB {
941941
}
942942
// Irrespective of if the in-memory delete succeeded; the document
943943
// doesn't exist on disk; so decrement the item count.
944-
vb.ht.decrNumTotalItems();
944+
vb.decrNumTotalItems();
945945
}
946946

947947
private:

engines/ep/src/ep_vb.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,27 @@ size_t EPVBucket::getNumItems() const {
257257
if (eviction == VALUE_ONLY) {
258258
return ht.getNumInMemoryItems() - ht.getNumDeletedItems();
259259
} else {
260-
return ht.getNumTotalItems() - ht.getNumDeletedItems();
260+
return onDiskTotalItems;
261261
}
262262
}
263263

264+
void EPVBucket::setNumTotalItems(size_t totalItems) {
265+
onDiskTotalItems = totalItems;
266+
}
267+
268+
void EPVBucket::incrNumTotalItems() {
269+
++onDiskTotalItems;
270+
}
271+
272+
void EPVBucket::decrNumTotalItems() {
273+
--onDiskTotalItems;
274+
}
275+
264276
size_t EPVBucket::getNumNonResidentItems() const {
265277
if (eviction == VALUE_ONLY) {
266278
return ht.getNumInMemoryNonResItems();
267279
} else {
268-
size_t num_items = ht.getNumTotalItems();
280+
size_t num_items = onDiskTotalItems;
269281
size_t num_res_items =
270282
ht.getNumInMemoryItems() - ht.getNumInMemoryNonResItems();
271283
return num_items > num_res_items ? (num_items - num_res_items) : 0;

engines/ep/src/ep_vb.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ class EPVBucket : public VBucket {
7171

7272
size_t getNumItems() const override;
7373

74+
void setNumTotalItems(size_t items) override;
75+
76+
void incrNumTotalItems() override;
77+
78+
void decrNumTotalItems() override;
79+
7480
size_t getNumNonResidentItems() const override;
7581

7682
ENGINE_ERROR_CODE statsVKey(const DocKey& key,
@@ -222,6 +228,14 @@ class EPVBucket : public VBucket {
222228
return st.getTotalMemoryUsed() + StoredValue::getRequiredStorage(item);
223229
}
224230

231+
/**
232+
* Total number of alive (non-deleted) items on-disk in this vBucket.
233+
* Initially populated during warmup as the number of items on disk;
234+
* then incremented / decremented by persistence callbacks as new
235+
* items are created & old items deleted.
236+
*/
237+
cb::NonNegativeCounter<size_t> onDiskTotalItems;
238+
225239
/* Indicates if multiple bg fetches are handled in a single bg fetch task */
226240
const bool multiBGFetchEnabled;
227241

engines/ep/src/ephemeral_vb.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ class EphemeralVBucket : public VBucket {
159159
return 0;
160160
}
161161

162+
void incrNumTotalItems() override {
163+
throw std::logic_error(
164+
"EphemeralVBucket::incrNumTotalItems not supported");
165+
}
166+
167+
void decrNumTotalItems() override {
168+
throw std::logic_error(
169+
"EphemeralVBucket::decrNumTotalItems not supported");
170+
}
171+
172+
void setNumTotalItems(size_t items) override {
173+
throw std::logic_error(
174+
"EphemeralVBucket::setNumTotalItems not supported");
175+
}
176+
162177
void queueBackfillItem(queued_item& qi,
163178
const GenerateBySeqno generateBySeqno) override;
164179

engines/ep/src/hash_table.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ HashTable::HashTable(EPStats& st,
4949
stats(st),
5050
valFact(std::move(svFactory)),
5151
visitors(0),
52-
numTotalItems(0),
5352
numItems(0),
5453
numNonResidentItems(0),
5554
numDeletedItems(0),
@@ -110,7 +109,6 @@ void HashTable::clear_UNLOCKED(bool deactivate) {
110109
stats.currentSize.fetch_sub(clearedMemSize - clearedValSize);
111110

112111
datatypeCounts.fill(0);
113-
numTotalItems.store(0);
114112
numItems.store(0);
115113
numTempItems.store(0);
116114
numNonResidentItems.store(0);

engines/ep/src/hash_table.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -227,26 +227,10 @@ class HashTable {
227227
return numItems;
228228
}
229229

230-
void setNumTotalItems(size_t totalItems) {
231-
numTotalItems = totalItems;
232-
}
233-
234-
size_t getNumTotalItems() const {
235-
return numTotalItems;
236-
}
237-
238230
void decrNumItems() {
239231
--numItems;
240232
}
241233

242-
void incrNumTotalItems() {
243-
++numTotalItems;
244-
}
245-
246-
void decrNumTotalItems() {
247-
--numTotalItems;
248-
}
249-
250234
void decrNumNonResidentItems() {
251235
--numNonResidentItems;
252236
}
@@ -672,8 +656,6 @@ class HashTable {
672656
std::unique_ptr<AbstractStoredValueFactory> valFact;
673657
std::atomic<size_t> visitors;
674658

675-
cb::NonNegativeCounter<size_t> numTotalItems;
676-
677659
/// Count of alive & deleted, in-memory non-resident and resident items.
678660
/// Excludes temporary items.
679661
cb::NonNegativeCounter<size_t> numItems;

engines/ep/src/persistence_callback.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void PersistenceCallback::callback(mutation_result& value) {
5151
if (value.second) {
5252
// Insert in value-only or full eviction mode.
5353
++vbucket->opsCreate;
54-
vbucket->ht.incrNumTotalItems();
54+
vbucket->incrNumTotalItems();
5555
vbucket->incrMetaDataDisk(*queuedItem);
5656
} else { // Update in full eviction mode.
5757
++vbucket->opsUpdate;

engines/ep/src/vbucket.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ void VBucket::deletedOnDiskCbk(const Item& queuedItem, bool deleted) {
18801880
}
18811881
if (deleted) {
18821882
// Removed an item from disk - decrement the count of total items.
1883-
ht.decrNumTotalItems();
1883+
decrNumTotalItems();
18841884
}
18851885

18861886
/**

engines/ep/src/vbucket.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,17 @@ class VBucket : public std::enable_shared_from_this<VBucket> {
370370
void incrMetaDataDisk(const Item& qi);
371371
void decrMetaDataDisk(const Item& qi);
372372

373+
/// Increase the total count of items in this VBucket by 1.
374+
virtual void incrNumTotalItems() = 0;
375+
376+
/// Decrease the total count of items in this VBucket by 1.
377+
virtual void decrNumTotalItems() = 0;
378+
379+
/**
380+
* Set the total count of items in this VBucket to the specified value.
381+
*/
382+
virtual void setNumTotalItems(size_t items) = 0;
383+
373384
/// Reset all statistics assocated with this vBucket.
374385
virtual void resetStats();
375386

engines/ep/src/warmup.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ void Warmup::estimateDatabaseItemCount(uint16_t shardId)
940940
getItemCount(vbid);
941941
VBucketPtr vb = store.getVBucket(vbid);
942942
if (vb) {
943-
vb->ht.setNumTotalItems(vbItemCount);
943+
vb->setNumTotalItems(vbItemCount);
944944
}
945945
item_count += vbItemCount;
946946
}

0 commit comments

Comments
 (0)