Skip to content

Commit 3979895

Browse files
committed
MB-60276: Avoid unnecessarily calling CouchKVStore::getDbFileInfo()
This method requires reading metadata from disk on Couchstore, which is naturally very slow. We read this metadata for every STAT("all") request, which is wasteful and can result in very long runtimes. This patch avoids the call made in getHistoryDiskSize() under Couchstore, as it doesn't support history in the first place. Magma stores the file metadata in memory, so it is not affected. Change-Id: I59f70b6227d511ff5fa055dc9d6d6cb9c4545a07 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/203267 Reviewed-by: Jim Walker <[email protected]> Tested-by: Vesko Karaganev <[email protected]>
1 parent 23a5a6e commit 3979895

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

engines/ep/src/ep_vb.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,13 @@ uint64_t EPVBucket::getHistoryDiskSize() {
441441
return 0;
442442
}
443443
try {
444-
return shard->getRWUnderlying()->getDbFileInfo(getId()).historyDiskSize;
444+
auto& kvstore = *shard->getRWUnderlying();
445+
// Avoid calling getDbFileInfo when backend does not support history.
446+
// Especially important for Couchstore, as the call goes to disk.
447+
if (kvstore.getStorageProperties().canRetainHistory()) {
448+
return kvstore.getDbFileInfo(getId()).historyDiskSize;
449+
}
450+
return 0;
445451
} catch (std::runtime_error& error) {
446452
EP_LOG_WARN(
447453
"EPVBucket::getHistoryDiskSize: Exception caught during "

engines/ep/src/kvstore/kvstore_iface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ class KVStoreIface {
435435
* is passed in as an argument. The information returned contains
436436
* the item count, file size and space used.
437437
*
438+
* Note: For some backends (Couchstore), this may require going to disk.
439+
*
438440
* @throws std::runtime_error (and subclasses) if it was not possible to
439441
* obtain the DB file info.
440442
*/

0 commit comments

Comments
 (0)