Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MB-6844 Increase max retry number for couchstore_open_db

Increased number of open_db retries will reduce the chance of
entire pending writes on the given vbucket being requeued in
the flusher queue. The requeuing those failed writes is OK but
yet it could create number of false alerts to ns server and clients.

Change-Id: I2fc8c1daab1bb2487dda028434d55699d42d9703
Reviewed-on: http://review.couchbase.org/21454
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
  • Loading branch information...
commit 4f9646ca6ade4fc072165eb97571daf0bde6b9df 1 parent 0336098
@jinlim jinlim authored Farshid Ghods committed
View
49 src/couch-kvstore/couch-kvstore.cc
@@ -28,7 +28,7 @@ static const int MUTATION_FAILED = -1;
static const int DOC_NOT_FOUND = 0;
static const int MUTATION_SUCCESS = 1;
-static const int MAX_OPEN_DB_RETRY = 2;
+static const int MAX_OPEN_DB_RETRY = 10;
extern "C" {
static int recordDbDumpC(Db *db, DocInfo *docinfo, void *ctx)
@@ -202,7 +202,6 @@ static void batchWarmupCallback(uint16_t vbId,
}
}
-
struct GetMultiCbCtx {
GetMultiCbCtx(CouchKVStore &c, uint16_t v, vb_bgfetch_queue_t &f) :
cks(c), vbId(v), fetches(f) {}
@@ -1195,10 +1194,11 @@ couchstore_error_t CouchKVStore::openDB(uint16_t vbucketId,
// 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);
- if (newRevNum) {
- errorCode = couchstore_open_db_ex(dbFileName.c_str(), 0,
- ops, db);
+ 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,
@@ -1212,20 +1212,7 @@ couchstore_error_t CouchKVStore::openDB(uint16_t vbucketId,
}
}
} else {
- while (retry < MAX_OPEN_DB_RETRY) {
- errorCode = couchstore_open_db_ex(dbFileName.c_str(),
- options, ops, db);
- if (errorCode == COUCHSTORE_SUCCESS) {
- break;
- }
- getLogger()->log(EXTENSION_LOG_INFO, NULL,
- "INFO: couchstore_open_db failed, name=%s "
- "options=%X error=%s [%s], try it again!\n",
- dbFileName.c_str(), options, couchstore_strerror(errorCode),
- couchkvstore_strerrno(errorCode).c_str());
- newRevNum = checkNewRevNum(dbFileName);
- ++retry;
- }
+ errorCode = openDB_retry(dbFileName, options, ops, db, &newRevNum);
}
/* update command statistics */
@@ -1252,6 +1239,30 @@ couchstore_error_t CouchKVStore::openDB(uint16_t vbucketId,
return errorCode;
}
+couchstore_error_t CouchKVStore::openDB_retry(std::string &dbfile,
+ uint64_t options,
+ const couch_file_ops *ops,
+ Db** db, uint64_t *newFileRev)
+{
+ int retry = 0;
+ couchstore_error_t errCode = COUCHSTORE_SUCCESS;
+
+ while (retry < MAX_OPEN_DB_RETRY) {
+ errCode = couchstore_open_db_ex(dbfile.c_str(), options, ops, db);
+ if (errCode == COUCHSTORE_SUCCESS) {
+ return errCode;
+ }
+ getLogger()->log(EXTENSION_LOG_INFO, NULL,
+ "INFO: couchstore_open_db failed, name=%s "
+ "options=%X error=%s [%s], try it again!\n",
+ dbfile.c_str(), options, couchstore_strerror(errCode),
+ couchkvstore_strerrno(errCode).c_str());
+ *newFileRev = checkNewRevNum(dbfile);
+ ++retry;
+ }
+ return errCode;
+}
+
void CouchKVStore::getFileNameMap(std::vector<uint16_t> *vbids,
std::string &dirname,
std::map<uint16_t, uint64_t> &filemap)
View
7 src/couch-kvstore/couch-kvstore.hh
@@ -505,8 +505,11 @@ private:
void updateDbFileMap(uint16_t vbucketId, uint64_t newFileRev,
bool insertImmediately = false);
void remVBucketFromDbFileMap(uint16_t vbucketId);
- couchstore_error_t openDB(uint16_t vbucketId, uint64_t fileRev, Db **db,
- uint64_t options, uint64_t *newFileRev = NULL);
+ couchstore_error_t openDB(uint16_t vbucketId, uint64_t fileRev, Db **db,
+ uint64_t options, uint64_t *newFileRev = NULL);
+ couchstore_error_t openDB_retry(std::string &dbfile, uint64_t options,
+ const couch_file_ops *ops,
+ Db **db, uint64_t *newFileRev);
couchstore_error_t saveDocs(uint16_t vbid, uint64_t rev, Doc **docs,
DocInfo **docinfos, int docCount);
void commitCallback(CouchRequest **committedReqs, int numReqs,
Please sign in to comment.
Something went wrong with that request. Please try again.