Skip to content

Commit

Permalink
Add a KVStoreConfig class for configuration parameters
Browse files Browse the repository at this point in the history
Change-Id: Id93a4ce0c72f3a4538838fb2d2bab7268d7dd9a1
Reviewed-on: http://review.couchbase.org/48765
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
  • Loading branch information
mikewied authored and Michael Wiederhold committed Mar 26, 2015
1 parent 2d1d5f3 commit ba3f6e8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/couch-kvstore/couch-kvstore.cc
Expand Up @@ -302,16 +302,16 @@ CouchRequest::CouchRequest(const Item &it, uint64_t rev,
start = gethrtime();
}

CouchKVStore::CouchKVStore(Configuration &config, bool read_only) :
CouchKVStore::CouchKVStore(KVStoreConfig &config, bool read_only) :
KVStore(read_only), configuration(config),
dbname(configuration.getDbname()), intransaction(false),
dbname(configuration.getDBName()), intransaction(false),
backfillCounter(0)
{
open();
statCollectingFileOps = getCouchstoreStatsOps(&st.fsStats);

// init db file map with default revision number, 1
numDbFiles = static_cast<uint16_t>(configuration.getMaxVbuckets());
numDbFiles = configuration.getMaxVBuckets();
cachedVBStates.reserve(numDbFiles);
for (uint16_t i = 0; i < numDbFiles; i++) {
// pre-allocate to avoid rehashing for safe read-only operations
Expand Down
4 changes: 2 additions & 2 deletions src/couch-kvstore/couch-kvstore.h
Expand Up @@ -279,7 +279,7 @@ class CouchKVStore : public KVStore
* @param config Configuration information
* @param read_only flag indicating if this kvstore instance is for read-only operations
*/
CouchKVStore(Configuration &config, bool read_only = false);
CouchKVStore(KVStoreConfig &config, bool read_only = false);

/**
* Copy constructor
Expand Down Expand Up @@ -614,7 +614,7 @@ class CouchKVStore : public KVStore

void removeCompactFile(const std::string &filename);

Configuration &configuration;
KVStoreConfig &configuration;
const std::string dbname;
std::vector<uint64_t>dbFileRevMap;
uint16_t numDbFiles;
Expand Down
5 changes: 3 additions & 2 deletions src/kvshard.cc
Expand Up @@ -33,8 +33,9 @@ KVShard::KVShard(uint16_t id, EventuallyPersistentStore &store) :

vbuckets = new RCPtr<VBucket>[maxVbuckets];

rwUnderlying = KVStoreFactory::create(config, false);
roUnderlying = KVStoreFactory::create(config, true);
KVStoreConfig kvconfig(config);
rwUnderlying = KVStoreFactory::create(kvconfig, false);
roUnderlying = KVStoreFactory::create(kvconfig, true);

flusher = new Flusher(&store, this);
bgFetcher = new BgFetcher(&store, this, stats);
Expand Down
14 changes: 13 additions & 1 deletion src/kvstore.cc
Expand Up @@ -24,7 +24,19 @@
#include "couch-kvstore/couch-kvstore.h"
#include "kvstore.h"

KVStore *KVStoreFactory::create(Configuration &config, bool read_only) {
KVStoreConfig::KVStoreConfig(Configuration& config)
: maxVBuckets(config.getMaxVbuckets()), dbname(config.getDbname()),
backend(config.getBackend()) {

}

KVStoreConfig::KVStoreConfig(uint16_t _maxVBuckets, std::string& _dbname,
std::string& _backend)
: maxVBuckets(_maxVBuckets), dbname(_dbname), backend(_backend) {

}

KVStore *KVStoreFactory::create(KVStoreConfig &config, bool read_only) {
KVStore *ret = NULL;
std::string backend = config.getBackend();
if (backend.compare("couchdb") == 0) {
Expand Down
28 changes: 27 additions & 1 deletion src/kvstore.h
Expand Up @@ -222,6 +222,32 @@ class StorageProperties {
};

class RollbackCB;
class Configuration;

class KVStoreConfig {
public:
KVStoreConfig(Configuration& config);

KVStoreConfig(uint16_t _maxVBuckets, std::string& _dbname,
std::string& _backend);

uint16_t getMaxVBuckets() {
return maxVBuckets;
}

std::string getDBName() {
return dbname;
}

std::string getBackend() {
return backend;
}

private:
uint16_t maxVBuckets;
std::string dbname;
std::string backend;
};

/**
* Base class representing kvstore operations.
Expand Down Expand Up @@ -441,7 +467,7 @@ class KVStoreFactory {
* @param config engine configuration
* @param read_only true if the kvstore instance is for read operations only
*/
static KVStore *create(Configuration &config, bool read_only = false);
static KVStore *create(KVStoreConfig &config, bool read_only = false);
};

/**
Expand Down

0 comments on commit ba3f6e8

Please sign in to comment.