Skip to content

Commit bafd9a0

Browse files
committed
Move KVStoreConfig from kvstore.{h,cc} to kvstore_config.{h,cc}
A number of files which currently #include kvstore.h only actually need the declarion of KVStoreConfig. Given that kvstore.h is relatively large, move KVStoreConfig to it's own header / source file to reduce the amount of headers other files need to include to use it. Change-Id: I836ac199fd8d8ae8af83193ea69f3a8cf8fccb5f Reviewed-on: http://review.couchbase.org/82682 Reviewed-by: Oliver Downard <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 3df4fca commit bafd9a0

File tree

11 files changed

+213
-160
lines changed

11 files changed

+213
-160
lines changed

engines/ep/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ ADD_CUSTOM_COMMAND(OUTPUT
146146
genconfig
147147
COMMENT "Generating code for configuration class")
148148

149-
SET(KVSTORE_SOURCE src/kvstore.cc)
150149
SET(COUCH_KVSTORE_SOURCE src/couch-kvstore/couch-kvstore.cc
151150
src/couch-kvstore/couch-fs-stats.cc)
152151
SET(OBJECTREGISTRY_SOURCE src/objectregistry.cc)
@@ -205,6 +204,8 @@ ADD_LIBRARY(ep_objs OBJECT
205204
src/htresizer.cc
206205
src/item.cc
207206
src/item_pager.cc
207+
src/kvstore.cc
208+
src/kvstore_config.cc
208209
src/logger.cc
209210
src/kv_bucket.cc
210211
src/kvshard.cc
@@ -234,7 +235,6 @@ ADD_LIBRARY(ep_objs OBJECT
234235
${OBJECTREGISTRY_SOURCE}
235236
${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c
236237
${CONFIG_SOURCE}
237-
${KVSTORE_SOURCE}
238238
${COUCH_KVSTORE_SOURCE}
239239
${FOREST_KVSTORE_SOURCE}
240240
${ROCKSDB_KVSTORE_SOURCE}

engines/ep/src/couch-kvstore/couch-kvstore.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "common.h"
4747
#include "couch-kvstore/couch-kvstore.h"
4848
#include "ep_types.h"
49+
#include "kvstore_config.h"
4950
#define STATWRITER_NAMESPACE couchstore_engine
5051
#include "statwriter.h"
5152
#undef STATWRITER_NAMESPACE

engines/ep/src/kvshard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "config.h"
2121

22-
#include "kvstore.h"
22+
#include "kvstore_config.h"
2323
#include "utility.h"
2424
#include "vbucket.h"
2525

engines/ep/src/kvstore.cc

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,51 +29,14 @@
2929
#ifdef EP_USE_ROCKSDB
3030
#include "rocksdb-kvstore/rocksdb-kvstore.h"
3131
#endif
32+
#include "kvstore_config.h"
3233
#include "statwriter.h"
3334
#include "kvstore.h"
3435
#include "vbucket.h"
3536
#include <platform/dirutils.h>
3637
#include <sys/types.h>
3738
#include <sys/stat.h>
3839

39-
KVStoreConfig::KVStoreConfig(Configuration& config, uint16_t shardid)
40-
: KVStoreConfig(config.getMaxVbuckets(),
41-
config.getMaxNumShards(),
42-
config.getDbname(),
43-
config.getBackend(),
44-
shardid,
45-
config.isCollectionsPrototypeEnabled()) {
46-
setPeriodicSyncBytes(config.getFsyncAfterEveryNBytesWritten());
47-
config.addValueChangedListener("fsync_after_every_n_bytes_written",
48-
new ConfigChangeListener(*this));
49-
}
50-
51-
KVStoreConfig::KVStoreConfig(uint16_t _maxVBuckets,
52-
uint16_t _maxShards,
53-
const std::string& _dbname,
54-
const std::string& _backend,
55-
uint16_t _shardId,
56-
bool _persistDocNamespace)
57-
: maxVBuckets(_maxVBuckets),
58-
maxShards(_maxShards),
59-
dbname(_dbname),
60-
backend(_backend),
61-
shardId(_shardId),
62-
logger(&global_logger),
63-
buffered(true),
64-
persistDocNamespace(_persistDocNamespace) {
65-
}
66-
67-
KVStoreConfig& KVStoreConfig::setLogger(Logger& _logger) {
68-
logger = &_logger;
69-
return *this;
70-
}
71-
72-
KVStoreConfig& KVStoreConfig::setBuffered(bool _buffered) {
73-
buffered = _buffered;
74-
return *this;
75-
}
76-
7740
KVStoreRWRO KVStoreFactory::create(KVStoreConfig& config) {
7841
std::string backend = config.getBackend();
7942
if (backend == "couchdb") {

engines/ep/src/kvstore.h

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -531,121 +531,6 @@ class StorageProperties {
531531
class RollbackCB;
532532
class Configuration;
533533

534-
class KVStoreConfig {
535-
public:
536-
/**
537-
* This constructor intialises the object from a central
538-
* ep-engine Configuration instance.
539-
*/
540-
KVStoreConfig(Configuration& config, uint16_t shardId);
541-
542-
/**
543-
* This constructor sets the mandatory config options
544-
*
545-
* Optional config options are set using a separate method
546-
*/
547-
KVStoreConfig(uint16_t _maxVBuckets,
548-
uint16_t _maxShards,
549-
const std::string& _dbname,
550-
const std::string& _backend,
551-
uint16_t _shardId,
552-
bool persistDocNamespace);
553-
554-
uint16_t getMaxVBuckets() const {
555-
return maxVBuckets;
556-
}
557-
558-
uint16_t getMaxShards() const {
559-
return maxShards;
560-
}
561-
562-
std::string getDBName() const {
563-
return dbname;
564-
}
565-
566-
const std::string& getBackend() const {
567-
return backend;
568-
}
569-
570-
uint16_t getShardId() const {
571-
return shardId;
572-
}
573-
574-
Logger& getLogger() {
575-
return *logger;
576-
}
577-
578-
/**
579-
* Indicates whether or not underlying file operations will be
580-
* buffered by the storage engine used.
581-
*
582-
* Only recognised by CouchKVStore
583-
*/
584-
bool getBuffered() const {
585-
return buffered;
586-
}
587-
588-
/**
589-
* Used to override the default logger object
590-
*/
591-
KVStoreConfig& setLogger(Logger& _logger);
592-
593-
/**
594-
* Used to override the default buffering behaviour.
595-
*
596-
* Only recognised by CouchKVStore
597-
*/
598-
KVStoreConfig& setBuffered(bool _buffered);
599-
600-
bool shouldPersistDocNamespace() const {
601-
return persistDocNamespace;
602-
}
603-
604-
void setPersistDocNamespace(bool value) {
605-
persistDocNamespace = value;
606-
}
607-
608-
uint64_t getPeriodicSyncBytes() const {
609-
return periodicSyncBytes;
610-
}
611-
612-
void setPeriodicSyncBytes(uint64_t bytes) {
613-
periodicSyncBytes = bytes;
614-
}
615-
616-
private:
617-
/// A listener class to update KVStore related configs at runtime.
618-
class ConfigChangeListener : public ValueChangedListener {
619-
public:
620-
ConfigChangeListener(KVStoreConfig& c) : config(c) {
621-
}
622-
623-
void sizeValueChanged(const std::string& key, size_t value) override {
624-
if (key == "fsync_after_every_n_bytes_written") {
625-
config.setPeriodicSyncBytes(value);
626-
}
627-
}
628-
629-
private:
630-
KVStoreConfig& config;
631-
};
632-
633-
uint16_t maxVBuckets;
634-
uint16_t maxShards;
635-
std::string dbname;
636-
std::string backend;
637-
uint16_t shardId;
638-
Logger* logger;
639-
bool buffered;
640-
bool persistDocNamespace;
641-
642-
/**
643-
* If non-zero, tell storage layer to issue a sync() operation after every
644-
* N bytes written.
645-
*/
646-
uint64_t periodicSyncBytes;
647-
};
648-
649534
class IORequest {
650535
public:
651536
IORequest(uint16_t vbId, MutationRequestCallback &cb, bool del,

engines/ep/src/kvstore_config.cc

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/*
3+
* Copyright 2017 Couchbase, Inc
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "kvstore_config.h"
19+
20+
/// A listener class to update KVStore related configs at runtime.
21+
class KVStoreConfig::ConfigChangeListener : public ValueChangedListener {
22+
public:
23+
ConfigChangeListener(KVStoreConfig& c) : config(c) {
24+
}
25+
26+
void sizeValueChanged(const std::string& key, size_t value) override {
27+
if (key == "fsync_after_every_n_bytes_written") {
28+
config.setPeriodicSyncBytes(value);
29+
}
30+
}
31+
32+
private:
33+
KVStoreConfig& config;
34+
};
35+
36+
KVStoreConfig::KVStoreConfig(Configuration& config, uint16_t shardid)
37+
: KVStoreConfig(config.getMaxVbuckets(),
38+
config.getMaxNumShards(),
39+
config.getDbname(),
40+
config.getBackend(),
41+
shardid,
42+
config.isCollectionsPrototypeEnabled()) {
43+
setPeriodicSyncBytes(config.getFsyncAfterEveryNBytesWritten());
44+
config.addValueChangedListener("fsync_after_every_n_bytes_written",
45+
new ConfigChangeListener(*this));
46+
}
47+
48+
KVStoreConfig::KVStoreConfig(uint16_t _maxVBuckets,
49+
uint16_t _maxShards,
50+
const std::string& _dbname,
51+
const std::string& _backend,
52+
uint16_t _shardId,
53+
bool _persistDocNamespace)
54+
: maxVBuckets(_maxVBuckets),
55+
maxShards(_maxShards),
56+
dbname(_dbname),
57+
backend(_backend),
58+
shardId(_shardId),
59+
logger(&global_logger),
60+
buffered(true),
61+
persistDocNamespace(_persistDocNamespace) {
62+
}
63+
64+
KVStoreConfig& KVStoreConfig::setLogger(Logger& _logger) {
65+
logger = &_logger;
66+
return *this;
67+
}
68+
69+
KVStoreConfig& KVStoreConfig::setBuffered(bool _buffered) {
70+
buffered = _buffered;
71+
return *this;
72+
}

0 commit comments

Comments
 (0)