Skip to content

Commit cabfe69

Browse files
rdemellowdaverigby
authored andcommitted
MB-31513 Implement Hashtable::visit() using ::pauseResumeVisit()
Reimplement Hashtable::visit() to use Hashtable::pauseResumeVisit() for easier maintenance of Hashtable::visit(). Change-Id: I1b843e1256ad0a09324938150fcc6a1fdebc75be Reviewed-on: http://review.couchbase.org/100315 Reviewed-by: Dave Rigby <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 81226d8 commit cabfe69

File tree

1 file changed

+3
-39
lines changed

1 file changed

+3
-39
lines changed

engines/ep/src/hash_table.cc

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -602,45 +602,9 @@ void HashTable::storeCompressedBuffer(cb::const_char_buffer buf,
602602
}
603603

604604
void HashTable::visit(HashTableVisitor& visitor) {
605-
if ((valueStats.getNumItems() + valueStats.getNumTempItems()) == 0 ||
606-
!isActive()) {
607-
return;
608-
}
609-
610-
// Acquire one (any) of the mutexes before incrementing {visitors}, this
611-
// prevents any race between this visitor and the HashTable resizer.
612-
// See comments in pauseResumeVisit() for further details.
613-
std::unique_lock<std::mutex> lh(mutexes[0]);
614-
VisitorTracker vt(&visitors);
615-
lh.unlock();
616-
617-
size_t visited = 0;
618-
for (int l = 0; isActive() && l < static_cast<int>(mutexes.size()); l++) {
619-
for (int i = l; i < static_cast<int>(size); i+= mutexes.size()) {
620-
// (re)acquire mutex on each HashBucket, to minimise any impact
621-
// on front-end threads.
622-
HashBucketLock lh(i, mutexes[l]);
623-
624-
StoredValue* v = values[i].get().get();
625-
if (v) {
626-
// TODO: Perf: This check seems costly - do we think it's still
627-
// worth keeping?
628-
auto hashbucket = getBucketForHash(v->getKey().hash());
629-
if (i != hashbucket) {
630-
throw std::logic_error("HashTable::visit: inconsistency "
631-
"between StoredValue's calculated hashbucket "
632-
"(which is " + std::to_string(hashbucket) +
633-
") and bucket is is located in (which is " +
634-
std::to_string(i) + ")");
635-
}
636-
}
637-
while (v) {
638-
StoredValue* tmp = v->getNext().get().get();
639-
visitor.visit(lh, *v);
640-
v = tmp;
641-
}
642-
++visited;
643-
}
605+
HashTable::Position ht_pos;
606+
while (ht_pos != endPosition()) {
607+
ht_pos = pauseResumeVisit(visitor, ht_pos);
644608
}
645609
}
646610

0 commit comments

Comments
 (0)