summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Stolley <colin.stolley@mongodb.com>2022-09-27 14:20:58 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-27 15:01:02 +0000
commitfca4f3f22ef5073031c3bf9352ea4eb0ade30e6c (patch)
tree126695fd43d479489287cf5d98bcd704f2d6175d
parentcb8b9029c089316a198b5f98a74ae21fc1f18299 (diff)
downloadmongo-fca4f3f22ef5073031c3bf9352ea4eb0ade30e6c.tar.gz
SERVER-69845: Implement column store size on disk.
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_column_store.cpp21
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp35
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp31
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_util.h2
4 files changed, 49 insertions, 40 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_column_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_column_store.cpp
index b3aef5dc0a6..1caf0b67158 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_column_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_column_store.cpp
@@ -426,17 +426,22 @@ bool WiredTigerColumnStore::isEmpty(OperationContext* opCtx) {
}
long long WiredTigerColumnStore::getSpaceUsedBytes(OperationContext* opCtx) const {
- // TODO: SERVER-65980.
- // For now we just return this so that tests can successfully obtain collection-level stats on
- // a collection with a columnstore index.
- return 27017;
+ dassert(opCtx->lockState()->isReadLocked());
+ auto ru = WiredTigerRecoveryUnit::get(opCtx);
+ WT_SESSION* s = ru->getSession()->getSession();
+
+ if (ru->getSessionCache()->isEphemeral()) {
+ return static_cast<long long>(WiredTigerUtil::getEphemeralIdentSize(s, _uri));
+ }
+ return static_cast<long long>(WiredTigerUtil::getIdentSize(s, _uri));
}
long long WiredTigerColumnStore::getFreeStorageBytes(OperationContext* opCtx) const {
- // TODO: SERVER-65980.
- // For now we just fake this so that tests can successfully obtain collection-level stats on a
- // collection with a columnstore index.
- return 27017;
+ dassert(opCtx->lockState()->isReadLocked());
+ auto ru = WiredTigerRecoveryUnit::get(opCtx);
+ WiredTigerSession* session = ru->getSession();
+
+ return static_cast<long long>(WiredTigerUtil::getIdentReuseSize(session->getSession(), _uri));
}
Status WiredTigerColumnStore::compact(OperationContext* opCtx) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
index 8e5df7fdf82..ce6f7bb0a84 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
@@ -509,41 +509,12 @@ void WiredTigerIndex::printIndexEntryMetadata(OperationContext* opCtx,
long long WiredTigerIndex::getSpaceUsedBytes(OperationContext* opCtx) const {
dassert(opCtx->lockState()->isReadLocked());
auto ru = WiredTigerRecoveryUnit::get(opCtx);
- WiredTigerSession* session = ru->getSession();
+ WT_SESSION* s = ru->getSession()->getSession();
if (ru->getSessionCache()->isEphemeral()) {
- // For ephemeral case, use cursor statistics
- const auto statsUri = "statistics:" + uri();
-
- // Helper function to retrieve stats and check for errors
- auto getStats = [&](int key) -> int64_t {
- auto result = WiredTigerUtil::getStatisticsValue(
- session->getSession(), statsUri, "statistics=(fast)", key);
- if (!result.isOK()) {
- if (result.getStatus().code() == ErrorCodes::CursorNotFound)
- return 0; // ident gone, so return 0
-
- uassertStatusOK(result.getStatus());
- }
- return result.getValue();
- };
-
- auto inserts = getStats(WT_STAT_DSRC_CURSOR_INSERT);
- auto removes = getStats(WT_STAT_DSRC_CURSOR_REMOVE);
- auto insertBytes = getStats(WT_STAT_DSRC_CURSOR_INSERT_BYTES);
-
- if (inserts == 0 || removes >= inserts)
- return 0;
-
- // Rough approximation of index size as average entry size times number of entries.
- // May be off if key sizes change significantly over the life time of the collection,
- // but is the best we can do currrently with the statistics available.
- auto bytesPerEntry = (insertBytes + inserts - 1) / inserts; // round up
- auto numEntries = inserts - removes;
- return numEntries * bytesPerEntry;
+ return static_cast<long long>(WiredTigerUtil::getEphemeralIdentSize(s, _uri));
}
-
- return static_cast<long long>(WiredTigerUtil::getIdentSize(session->getSession(), _uri));
+ return static_cast<long long>(WiredTigerUtil::getIdentSize(s, _uri));
}
long long WiredTigerIndex::getFreeStorageBytes(OperationContext* opCtx) const {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
index a3a9ec4109d..ab4623f5441 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
@@ -500,6 +500,37 @@ int64_t WiredTigerUtil::getIdentSize(WT_SESSION* s, const std::string& uri) {
return result.getValue();
}
+int64_t WiredTigerUtil::getEphemeralIdentSize(WT_SESSION* s, const std::string& uri) {
+ // For ephemeral case, use cursor statistics
+ const auto statsUri = "statistics:" + uri;
+
+ // Helper function to retrieve stats and check for errors
+ auto getStats = [&](int key) -> int64_t {
+ auto result = getStatisticsValue(s, statsUri, "statistics=(fast)", key);
+ if (!result.isOK()) {
+ if (result.getStatus().code() == ErrorCodes::CursorNotFound)
+ return 0; // ident gone, so return 0
+
+ uassertStatusOK(result.getStatus());
+ }
+ return result.getValue();
+ };
+
+ auto inserts = getStats(WT_STAT_DSRC_CURSOR_INSERT);
+ auto removes = getStats(WT_STAT_DSRC_CURSOR_REMOVE);
+ auto insertBytes = getStats(WT_STAT_DSRC_CURSOR_INSERT_BYTES);
+
+ if (inserts == 0 || removes >= inserts)
+ return 0;
+
+ // Rough approximation of index size as average entry size times number of entries.
+ // May be off if key sizes change significantly over the life time of the collection,
+ // but is the best we can do currrently with the statistics available.
+ auto bytesPerEntry = (insertBytes + inserts - 1) / inserts; // round up
+ auto numEntries = inserts - removes;
+ return numEntries * bytesPerEntry;
+}
+
int64_t WiredTigerUtil::getIdentReuseSize(WT_SESSION* s, const std::string& uri) {
auto result = WiredTigerUtil::getStatisticsValue(
s, "statistics:" + uri, "statistics=(fast)", WT_STAT_DSRC_BLOCK_REUSE_BYTES);
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h
index dbca93e6bc6..b17dfcb6f85 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h
@@ -272,6 +272,8 @@ public:
const std::string& config,
int statisticsKey);
+ static int64_t getEphemeralIdentSize(WT_SESSION* s, const std::string& uri);
+
static int64_t getIdentSize(WT_SESSION* s, const std::string& uri);
/**