Skip to content

Commit 6b5fb6a

Browse files
BenHuddlestondaverigby
authored andcommitted
MB-39745: Remove KVShard from BGFetcher
It's not necessary and is required to decouple BGFetchers from KVShards Change-Id: Ifbeb2b10f2d55d16cfc53ac341dceabfd91eccf4 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/136376 Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent e02bd2c commit 6b5fb6a

File tree

5 files changed

+19
-30
lines changed

5 files changed

+19
-30
lines changed

engines/ep/src/bgfetcher.cc

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@
2121
#include "ep_engine.h"
2222
#include "executorpool.h"
2323
#include "kv_bucket.h"
24-
#include "kvshard.h"
2524
#include "tasks.h"
2625
#include "vbucket_bgfetch_item.h"
2726
#include <phosphor/phosphor.h>
2827
#include <algorithm>
2928
#include <climits>
3029
#include <vector>
3130

32-
BgFetcher::BgFetcher(KVBucket& s, KVShard& k)
33-
: BgFetcher(s, k, s.getEPEngine().getEpStats()) {
31+
BgFetcher::BgFetcher(KVBucket& s) : BgFetcher(s, s.getEPEngine().getEpStats()) {
3432
}
3533

3634
BgFetcher::~BgFetcher() {
@@ -88,7 +86,7 @@ size_t BgFetcher::doFetch(Vbid vbId, vb_bgfetch_queue_t& itemsToFetch) {
8886
startTime.time_since_epoch())
8987
.count());
9088

91-
shard.getROUnderlying()->getMulti(vbId, itemsToFetch);
89+
store.getROUnderlying(vbId)->getMulti(vbId, itemsToFetch);
9290

9391
std::vector<bgfetched_item_t> fetchedItems;
9492
for (const auto& fetch : itemsToFetch) {
@@ -143,7 +141,7 @@ bool BgFetcher::run(GlobalTask *task) {
143141
size_t num_fetched_items = 0;
144142

145143
for (const auto vbId : bg_vbs) {
146-
VBucketPtr vb = shard.getBucket(vbId);
144+
VBucketPtr vb = store.getVBucket(vbId);
147145
if (vb) {
148146
// Requeue the bg fetch task if vbucket DB file is not created yet.
149147
if (vb->isBucketCreation()) {
@@ -166,13 +164,3 @@ bool BgFetcher::run(GlobalTask *task) {
166164

167165
return true;
168166
}
169-
170-
bool BgFetcher::pendingJob() const {
171-
for (const auto vbid : shard.getVBuckets()) {
172-
VBucketPtr vb = shard.getBucket(vbid);
173-
if (vb && vb->hasPendingBGFetchItems()) {
174-
return true;
175-
}
176-
}
177-
return false;
178-
}

engines/ep/src/bgfetcher.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
// Forward declarations.
2626
class EPStats;
2727
class KVBucket;
28-
class KVShard;
2928
class GlobalTask;
3029

3130
/**
@@ -38,11 +37,10 @@ class BgFetcher {
3837
* Construct a BgFetcher
3938
*
4039
* @param s The store
41-
* @param k The shard to which this background fetcher belongs
4240
* @param st reference to statistics
4341
*/
44-
BgFetcher(KVBucket& s, KVShard& k, EPStats& st)
45-
: store(s), shard(k), taskId(0), stats(st), pendingFetch(false) {
42+
BgFetcher(KVBucket& s, EPStats& st)
43+
: store(s), taskId(0), stats(st), pendingFetch(false) {
4644
}
4745

4846
/**
@@ -52,16 +50,14 @@ class BgFetcher {
5250
* from KVBucket's reference to EPEngine's epstats.
5351
*
5452
* @param s The store
55-
* @param k The shard to which this background fetcher belongs
5653
*/
57-
BgFetcher(KVBucket& s, KVShard& k);
54+
BgFetcher(KVBucket& s);
5855

5956
~BgFetcher();
6057

6158
void start();
6259
void stop();
6360
bool run(GlobalTask *task);
64-
bool pendingJob() const;
6561
void notifyBGEvent();
6662
void setTaskId(size_t newId) { taskId = newId; }
6763
void addPendingVB(Vbid vbId) {
@@ -78,7 +74,6 @@ class BgFetcher {
7874
void wakeUpTaskIfSnoozed();
7975

8076
KVBucket& store;
81-
KVShard& shard;
8277
size_t taskId;
8378
std::mutex queueMutex;
8479
EPStats &stats;

engines/ep/src/ep_bucket.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,12 +962,18 @@ bool EPBucket::startBgFetcher() {
962962
void EPBucket::stopBgFetcher() {
963963
for (const auto& shard : vbMap.shards) {
964964
BgFetcher* bgfetcher = shard->getBgFetcher();
965-
if (bgfetcher->pendingJob()) {
966-
EP_LOG_WARN(
967-
"Shutting down engine while there are still pending data "
968-
"read for shard {} from database storage",
969-
shard->getId());
965+
for (const auto vbid : shard->getVBuckets()) {
966+
VBucketPtr vb = shard->getBucket(vbid);
967+
if (vb && vb->hasPendingBGFetchItems()) {
968+
EP_LOG_WARN(
969+
"Shutting down engine while there are still pending "
970+
"data "
971+
"read for shard {} from database storage",
972+
shard->getId());
973+
break;
974+
}
970975
}
976+
971977
EP_LOG_INFO("Stopping bg fetcher for shard:{}", shard->getId());
972978
bgfetcher->stop();
973979
}

engines/ep/src/kvshard.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ KVShard::KVShard(EventuallyPersistentEngine& engine, id_type id)
8484

8585
void KVShard::enablePersistence(EPBucket& ep) {
8686
flusher = std::make_unique<Flusher>(&ep, this);
87-
bgFetcher = std::make_unique<BgFetcher>(ep, *this);
87+
bgFetcher = std::make_unique<BgFetcher>(ep);
8888
}
8989

9090
// Non-inline destructor so we can destruct

engines/ep/tests/module_tests/evp_vbucket_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ TEST_P(EPVBucketTest, GetBGFetchItemsPerformance) {
5555
auto mockEPBucket =
5656
engine->public_makeMockBucket(engine->getConfiguration());
5757
KVShard kvShard(*engine.get(), 0);
58-
BgFetcher bgFetcher(*mockEPBucket.get(), kvShard);
58+
BgFetcher bgFetcher(*mockEPBucket.get());
5959

6060
for (unsigned int ii = 0; ii < 100000; ii++) {
6161
auto fetchItem =

0 commit comments

Comments
 (0)