Skip to content

Commit

Permalink
MB-7965: Skip scanning for existing files during flush all
Browse files Browse the repository at this point in the history
During flush all, all the vbucket files are being deleted
and recreated. Given that the files are going to be
recreated anyways, there is no need to scan the directory
for any existing files.

Change-Id: I9b6e0c39f193e282441aba6e481cc1ebbff1a64c
Reviewed-on: http://review.couchbase.org/47134
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Sriram Ganesan <sriram@couchbase.com>
  • Loading branch information
Sriram Ganesan committed Feb 24, 2015
1 parent e84b104 commit 94ffb15
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
70 changes: 45 additions & 25 deletions src/couch-kvstore/couch-kvstore.cc
Expand Up @@ -1010,7 +1010,7 @@ bool CouchKVStore::snapshotStats(const std::map<std::string,
}

bool CouchKVStore::setVBucketState(uint16_t vbucketId, vbucket_state &vbstate,
Callback<kvstats_ctx> *kvcb) {
Callback<kvstats_ctx> *kvcb, bool reset) {
Db *db = NULL;
uint64_t fileRev, newFileRev;
std::stringstream id, rev;
Expand All @@ -1026,7 +1026,7 @@ bool CouchKVStore::setVBucketState(uint16_t vbucketId, vbucket_state &vbstate,

couchstore_error_t errorCode;
errorCode = openDB(vbucketId, fileRev, &db,
(uint64_t)COUCHSTORE_OPEN_FLAG_CREATE, &newFileRev);
(uint64_t)COUCHSTORE_OPEN_FLAG_CREATE, &newFileRev, reset);
if (errorCode != COUCHSTORE_SUCCESS) {
++st.numVbSetFailure;
LOG(EXTENSION_LOG_WARNING,
Expand Down Expand Up @@ -1375,38 +1375,58 @@ couchstore_error_t CouchKVStore::openDB(uint16_t vbucketId,
uint64_t fileRev,
Db **db,
uint64_t options,
uint64_t *newFileRev) {
uint64_t *newFileRev,
bool reset) {
std::string dbFileName = getDBFileName(dbname, vbucketId, fileRev);
couch_file_ops* ops = &statCollectingFileOps;

uint64_t newRevNum = fileRev;
couchstore_error_t errorCode = COUCHSTORE_SUCCESS;

if (options == COUCHSTORE_OPEN_FLAG_CREATE) {
// first try to open the requested file without the create option
// in case it does already exist
errorCode = couchstore_open_db_ex(dbFileName.c_str(), 0, ops, db);
if (errorCode != COUCHSTORE_SUCCESS) {
// open_db failed but still check if the file exists
newRevNum = checkNewRevNum(dbFileName);
bool fileExists = (newRevNum) ? true : false;
if (fileExists) {
errorCode = openDB_retry(dbFileName, 0, ops, db, &newRevNum);
} else {
// requested file doesn't seem to exist, just create one
errorCode = couchstore_open_db_ex(dbFileName.c_str(), options,
ops, db);
if (errorCode == COUCHSTORE_SUCCESS) {
newRevNum = 1;
updateDbFileMap(vbucketId, fileRev);
LOG(EXTENSION_LOG_INFO,
"INFO: created new couch db file, name=%s rev=%llu",
dbFileName.c_str(), fileRev);
if (reset) {
errorCode = couchstore_open_db_ex(dbFileName.c_str(), options,
ops, db);
if (errorCode == COUCHSTORE_SUCCESS) {
newRevNum = 1;
updateDbFileMap(vbucketId, fileRev);
LOG(EXTENSION_LOG_INFO,
"reset: created new couchstore file, name=%s rev=%llu",
dbFileName.c_str(), fileRev);
} else {
LOG(EXTENSION_LOG_WARNING,
"reset: creating a new couchstore file,"
"name=%s rev=%llu failed with error=%s", dbFileName.c_str(),
fileRev, couchstore_strerror(errorCode));
}
} else {
if (options == COUCHSTORE_OPEN_FLAG_CREATE) {
// first try to open the requested file without the
// create option in case it does already exist
errorCode = couchstore_open_db_ex(dbFileName.c_str(), 0, ops, db);
if (errorCode != COUCHSTORE_SUCCESS) {
// open_db failed but still check if the file exists
newRevNum = checkNewRevNum(dbFileName);
bool fileExists = (newRevNum) ? true : false;
if (fileExists) {
errorCode = openDB_retry(dbFileName, 0, ops, db,
&newRevNum);
} else {
// requested file doesn't seem to exist, just create one
errorCode = couchstore_open_db_ex(dbFileName.c_str(),
options, ops, db);
if (errorCode == COUCHSTORE_SUCCESS) {
newRevNum = 1;
updateDbFileMap(vbucketId, fileRev);
LOG(EXTENSION_LOG_INFO,
"INFO: created new couch db file, name=%s rev=%llu",
dbFileName.c_str(), fileRev);
}
}
}
} else {
errorCode = openDB_retry(dbFileName, options, ops, db,
&newRevNum);
}
} else {
errorCode = openDB_retry(dbFileName, options, ops, db, &newRevNum);
}

/* update command statistics */
Expand Down
7 changes: 4 additions & 3 deletions src/couch-kvstore/couch-kvstore.h
Expand Up @@ -553,10 +553,10 @@ class CouchKVStore : public KVStore
private:

bool setVBucketState(uint16_t vbucketId, vbucket_state &vbstate,
Callback<kvstats_ctx> *cb);
Callback<kvstats_ctx> *cb, bool reset=false);
bool resetVBucket(uint16_t vbucketId, vbucket_state &vbstate) {
cachedDocCount[vbucketId] = 0;
return setVBucketState(vbucketId, vbstate, NULL);
return setVBucketState(vbucketId, vbstate, NULL, true);
}

template <typename T>
Expand All @@ -577,7 +577,8 @@ class CouchKVStore : public KVStore
void remVBucketFromDbFileMap(uint16_t vbucketId);
void updateDbFileMap(uint16_t vbucketId, uint64_t newFileRev);
couchstore_error_t openDB(uint16_t vbucketId, uint64_t fileRev, Db **db,
uint64_t options, uint64_t *newFileRev = NULL);
uint64_t options, uint64_t *newFileRev = NULL,
bool reset=false);
couchstore_error_t openDB_retry(std::string &dbfile, uint64_t options,
const couch_file_ops *ops,
Db **db, uint64_t *newFileRev);
Expand Down

0 comments on commit 94ffb15

Please sign in to comment.