|
Just for the information of anyone who might see this, that test isn't really measuring the storage size for WT: the storage size isn't known until the collection is actually written to disk, and that doesn't happen until it is checkpointed. Adding db.adminCommand({fsync:1}) before the calls to db.stats() to force a checkpoint gives much different numbers for WT:
Before creating the index {a: 1}
|
{ "storageSize" : 28672, "indexes" : 1, "indexSize" : 20480 }
|
After creating the index {a: 1}
|
{ "storageSize" : 28672, "indexes" : 2, "indexSize" : 45056 }
|
The conclusion is still correct however: both WT and mmapv1 include only the collection data in storageSize.
The behavior that the storageSize is not computed immediately for WT is an inconsistency between WT and mmapv1, but it is unavoidable due to the difference between the two in how and when data is written to disk.
|
|
Hi Steve,
I'm seeing that db.stats().storageSize remains the same after an index is added to a collection. Is there a case where you observed something different happening?
(function() {
|
"use strict";
|
|
function extractRelevantStats(stats) {
|
return {
|
storageSize: stats.storageSize,
|
indexes: stats.indexes,
|
indexSize: stats.indexSize,
|
};
|
}
|
|
var collName = 'storage_size_test';
|
var t = db[collName];
|
|
t.drop();
|
for (var i = 0; i < 1000; ++i) {
|
t.insert({_id: ObjectId(), a: i});
|
}
|
|
print('Before creating the index {a: 1}');
|
printjson(extractRelevantStats(db.stats()));
|
|
t.ensureIndex({a: 1});
|
|
print('After creating the index {a: 1}');
|
printjson(extractRelevantStats(db.stats()));
|
})();
|
With MMAPv1,
Before creating the index {a: 1}
|
{ "storageSize" : 184320, "indexes" : 1, "indexSize" : 40880 }
|
After creating the index {a: 1}
|
{ "storageSize" : 184320, "indexes" : 2, "indexSize" : 81760 }
|
With WiredTiger,
Before creating the index {a: 1}
|
{ "storageSize" : 4096, "indexes" : 1, "indexSize" : 4096 }
|
After creating the index {a: 1}
|
{ "storageSize" : 4096, "indexes" : 2, "indexSize" : 28672 }
|
|