Skip to content

Commit 5975846

Browse files
BenHuddlestondaverigby
authored andcommitted
MB-41857: Increase cache limit on close of old db during compaction
During compaction we call openDbForRead for the old database file and then manually close the file. Manually closing the file causes us to not track the closure of the file against the file cache limit. This causes us to decrease the file cache limit with no way to later increase it, causing opens to later fail as the cache is full. Change-Id: I3b795263d44e62865e537bc75bd11cb84e107759 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/137569 Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 4a5d9f4 commit 5975846

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,8 +1309,12 @@ bool CouchKVStore::compactDBInternal(std::unique_lock<std::mutex>& vbLock,
13091309
false, // copy with lock
13101310
hook_ctx->stats.preparesPurged,
13111311
vbid);
1312-
// Close the source Database File once compaction is done
1313-
openResult.fileHandle->getDbHolder().close();
1312+
1313+
auto oldRev = openResult.fileHandle->getDbHolder().getFileRev();
1314+
1315+
// Close the source database file
1316+
openResult.fileHandle.reset();
1317+
13141318
// Close the destination file so we may rename it
13151319
targetDb.close();
13161320

@@ -1376,7 +1380,7 @@ bool CouchKVStore::compactDBInternal(std::unique_lock<std::mutex>& vbLock,
13761380
updateDbFileMap(vbid, new_rev);
13771381

13781382
// Removing the stale couch file
1379-
unlinkCouchFile(vbid, openResult.fileHandle->getDbHolder().getFileRev());
1383+
unlinkCouchFile(vbid, oldRev);
13801384

13811385
st.compactHisto.add(std::chrono::duration_cast<std::chrono::microseconds>(
13821386
std::chrono::steady_clock::now() - start));

engines/ep/tests/module_tests/couch-kvstore_test.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,3 +2104,16 @@ TEST_F(CouchstoreTest, CacheLimitOpenDbForReadFailure) {
21042104

21052105
EXPECT_EQ(1, CouchKVStoreFileCache::get().getHandle()->capacity());
21062106
}
2107+
2108+
TEST_F(CouchstoreTest, CacheLimitBumpedOnOldDbCloseDuringCompaction) {
2109+
CouchKVStoreFileCache::get().getHandle()->resize(5);
2110+
CompactionConfig config;
2111+
auto ctx = std::make_shared<CompactionContext>(config, 0);
2112+
2113+
std::mutex mutex;
2114+
std::unique_lock<std::mutex> lock(mutex);
2115+
EXPECT_EQ(5, CouchKVStoreFileCache::get().getHandle()->capacity());
2116+
2117+
EXPECT_TRUE(kvstore->compactDB(lock, ctx));
2118+
EXPECT_EQ(5, CouchKVStoreFileCache::get().getHandle()->capacity());
2119+
}

0 commit comments

Comments
 (0)