Skip to content

Commit 8ae3b4f

Browse files
committed
Reduce coupling in KVShard
This class doesn't need to know about the higher-level bucket or ep-engine classes. Change-Id: I9c1ad7b9a08aabc8a74057b90a07dd52271daab1 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/160324 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Trond Norbye <trond.norbye@couchbase.com>
1 parent 4b3c037 commit 8ae3b4f

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

engines/ep/src/kvshard.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@
1212
#include <functional>
1313
#include <memory>
1414

15-
#include "ep_bucket.h"
16-
#include "ep_engine.h"
15+
#include "configuration.h"
1716
#include "flusher.h"
1817
#include "kvshard.h"
1918
#include "kvstore/kvstore.h"
19+
#include "vbucket.h"
2020

2121
/* [EPHE TODO]: Consider not using KVShard for ephemeral bucket */
22-
KVShard::KVShard(EventuallyPersistentEngine& engine, id_type id)
22+
KVShard::KVShard(Configuration& config,
23+
id_type numShards,
24+
id_type id)
2325
: // Size vBuckets to have sufficient slots for the maximum number of
2426
// vBuckets each shard is responsible for. To ensure correct behaviour
2527
// when vbuckets isn't a multiple of num_shards, apply ceil() to the
2628
// division so we round up where necessary.
27-
vbuckets(std::ceil(float(engine.getConfiguration().getMaxVbuckets()) /
28-
engine.getWorkLoadPolicy().getNumShards())),
29+
vbuckets(std::ceil(float(config.getMaxVbuckets()) / numShards)),
2930
highPriorityCount(0) {
30-
const auto numShards = engine.getWorkLoadPolicy().getNumShards();
31-
auto& config = engine.getConfiguration();
3231
const std::string backend = config.getBackend();
3332

3433
#ifdef EP_USE_MAGMA

engines/ep/src/kvshard.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,13 @@
5959
*/
6060
class Configuration;
6161
class CookieIface;
62-
class EPBucket;
63-
class EventuallyPersistentEngine;
6462
class KVStoreIface;
6563

6664
class KVShard {
6765
public:
6866
// Identifier for a KVShard
6967
using id_type = uint16_t;
70-
KVShard(EventuallyPersistentEngine& engine, KVShard::id_type id);
68+
KVShard(Configuration& config, id_type numShards, id_type id);
7169
~KVShard();
7270

7371
KVStoreIface* getRWUnderlying() {

engines/ep/src/vbucketmap.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ VBucketMap::VBucketMap(KVBucket& bucket)
2323
const auto numShards = engine.getWorkLoadPolicy().getNumShards();
2424
shards.resize(numShards);
2525
for (size_t shardId = 0; shardId < numShards; shardId++) {
26-
shards[shardId] = std::make_unique<KVShard>(engine, shardId);
26+
shards[shardId] = std::make_unique<KVShard>(
27+
bucket.getEPEngine().getConfiguration(), numShards, shardId);
2728
}
2829

2930
auto& config = engine.getConfiguration();
@@ -184,4 +185,4 @@ size_t VBucketMap::getNumAliveVBuckets() const {
184185
res += getVBStateCount(state);
185186
}
186187
return res;
187-
}
188+
}

engines/ep/tests/module_tests/evp_vbucket_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ TEST_P(EPVBucketTest, GetBGFetchItemsPerformance) {
4949
// bgFetcher
5050
auto mockEPBucket =
5151
engine->public_makeMockBucket(engine->getConfiguration());
52-
KVShard kvShard(*engine.get(), 0);
52+
KVShard kvShard(engine->getConfiguration(),
53+
engine->getConfiguration().getMaxNumShards(),
54+
0);
5355
BgFetcher bgFetcher(*mockEPBucket.get());
5456

5557
for (unsigned int ii = 0; ii < 100000; ii++) {

0 commit comments

Comments
 (0)