summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-07-29 17:36:32 -0400
committerEliot Horowitz <eliot@10gen.com>2014-07-29 23:46:48 -0400
commit6d66597265e158ec16dd31f823f0d474194519e7 (patch)
tree67e5237c7706a60d6f5f1f8043c37cbfc4dc9671 /src
parent5eba41b4540c2bef454784c4b5516691c397604b (diff)
downloadmongo-6d66597265e158ec16dd31f823f0d474194519e7.tar.gz
SERVER-13635: better tracking of heap index size
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/storage/heap1/heap1_btree_impl.cpp22
-rw-r--r--src/mongo/db/storage/heap1/heap1_database_catalog_entry.cpp1
2 files changed, 9 insertions, 14 deletions
diff --git a/src/mongo/db/storage/heap1/heap1_btree_impl.cpp b/src/mongo/db/storage/heap1/heap1_btree_impl.cpp
index 00577a19045..a5ee3bf00ce 100644
--- a/src/mongo/db/storage/heap1/heap1_btree_impl.cpp
+++ b/src/mongo/db/storage/heap1/heap1_btree_impl.cpp
@@ -246,8 +246,7 @@ namespace {
Heap1BtreeImpl(const IndexCatalogEntry& info, IndexSet* data)
: _info(info),
_data(data) {
- _averageSizeHelpers.totalSize = 0;
- _averageSizeHelpers.totalDocs = 0;
+ _currentKeySize = 0;
}
virtual SortedDataBuilderInterface* getBulkBuilder(OperationContext* txn, bool dupsAllowed) {
@@ -259,9 +258,6 @@ namespace {
const DiskLoc& loc,
bool dupsAllowed) {
- _averageSizeHelpers.totalSize += key.objsize();
- _averageSizeHelpers.totalDocs++;
-
invariant(!loc.isNull());
invariant(loc.isValid());
invariant(!hasFieldNames(key));
@@ -271,6 +267,7 @@ namespace {
return dupKeyError(key);
_data->insert(IndexEntry(key.getOwned(), loc));
+ _currentKeySize += key.objsize();
return Status::OK();
}
@@ -281,6 +278,9 @@ namespace {
const size_t numDeleted = _data->erase(IndexEntry(key, loc));
invariant(numDeleted <= 1);
+ if ( numDeleted == 1 )
+ _currentKeySize -= key.objsize();
+
return numDeleted == 1;
}
@@ -290,9 +290,8 @@ namespace {
}
virtual long long getSpaceUsedBytes( OperationContext* txn ) const {
- // this is a guess
- double avg = _averageSizeHelpers.totalSize / _averageSizeHelpers.totalDocs;
- return _data->size() * ( 24 + avg );
+ // 24 is a guess for DiskLoc + std::set overhead
+ return _currentKeySize + ( sizeof(IndexEntry) * _data->size() );
}
virtual Status dupKeyCheck(OperationContext* txn, const BSONObj& key, const DiskLoc& loc) {
@@ -542,12 +541,7 @@ namespace {
private:
const IndexCatalogEntry& _info;
IndexSet* _data;
-
- struct AverageSizeHelpers {
- double totalSize;
- double totalDocs;
- } _averageSizeHelpers;
-
+ long long _currentKeySize;
};
} // namespace
diff --git a/src/mongo/db/storage/heap1/heap1_database_catalog_entry.cpp b/src/mongo/db/storage/heap1/heap1_database_catalog_entry.cpp
index 94d1a8c2b13..1059537af58 100644
--- a/src/mongo/db/storage/heap1/heap1_database_catalog_entry.cpp
+++ b/src/mongo/db/storage/heap1/heap1_database_catalog_entry.cpp
@@ -201,6 +201,7 @@ namespace mongo {
boost::mutex::scoped_lock lk( _entryMapLock );
Entry* e = _entryMap[fromNS.toString()];
if ( !e ) {
+ _entryMap.erase( fromNS.toString() );
return Status( ErrorCodes::NamespaceNotFound,
"cannot renameCollection missng collection" );
}