2013-10-30 19:45:22 +01:00
|
|
|
// test preservePadding
|
2014-01-07 05:53:21 +01:00
|
|
|
|
2014-01-31 15:00:33 +01:00
|
|
|
var mydb = db.getSiblingDB('compactPreservePadding');
|
2014-01-07 05:53:21 +01:00
|
|
|
var collName = "compactPreservePadding";
|
2014-01-31 15:00:33 +01:00
|
|
|
var t = mydb.getCollection(collName);
|
2013-10-30 19:45:22 +01:00
|
|
|
t.drop();
|
2014-01-07 05:53:21 +01:00
|
|
|
|
2016-03-09 18:17:50 +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++) {
|
2016-03-09 18:17:50 +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
|
2016-03-09 18:17:50 +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-31 15:00:33 +01:00
|
|
|
mydb.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);
|