2013-10-30 19:45:22 +01:00
|
|
|
// test preservePadding
|
2014-01-07 05:53:21 +01:00
|
|
|
|
2014-01-31 14:03:34 +01:00
|
|
|
var db = db.getSiblingDB('compactPreservePadding');
|
2014-01-07 05:53:21 +01:00
|
|
|
var collName = "compactPreservePadding";
|
|
|
|
var t = db.getCollection(collName);
|
2013-10-30 19:45:22 +01:00
|
|
|
t.drop();
|
2014-01-07 05:53:21 +01:00
|
|
|
|
|
|
|
// use larger keyname to avoid hitting an edge case with extents
|
2013-10-30 19:45:22 +01:00
|
|
|
for (i = 0; i < 10000; i++) {
|
2014-01-07 05:53:21 +01:00
|
|
|
t.insert({useLargerKeyName:i});
|
2013-10-30 19:45:22 +01:00
|
|
|
}
|
2014-01-07 05:53:21 +01:00
|
|
|
|
2013-10-30 19:45:22 +01:00
|
|
|
// remove half the entries
|
2014-01-07 05:53:21 +01:00
|
|
|
t.remove({useLargerKeyName:{$mod:[2,0]}})
|
2013-10-30 19:45:22 +01:00
|
|
|
printjson(t.stats());
|
|
|
|
originalSize = t.stats().size;
|
|
|
|
originalStorage = t.stats().storageSize;
|
2014-01-07 05:53:21 +01:00
|
|
|
|
2013-10-30 19:45:22 +01:00
|
|
|
// compact!
|
2014-01-07 05:53:21 +01:00
|
|
|
db.runCommand({compact: collName, preservePadding: true});
|
2013-10-30 19:45:22 +01:00
|
|
|
printjson(t.stats());
|
2014-01-07 05:53:21 +01:00
|
|
|
|
2013-10-30 19:45:22 +01:00
|
|
|
// object sizes ('size') should be the same (unless we hit an edge case involving extents, which
|
|
|
|
// this test doesn't) and storage size should shrink
|
|
|
|
assert(originalSize == t.stats().size);
|
|
|
|
assert(originalStorage > t.stats().storageSize);
|