summaryrefslogtreecommitdiff
path: root/jstests/mmap_v1
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-08-01 13:15:25 -0400
committerEliot Horowitz <eliot@10gen.com>2014-08-01 16:53:39 -0400
commitdaf68ad0c8a23459d490da94403ad97712f8991b (patch)
treeec5f436af4d749271471b7752c95c9bf5047e813 /jstests/mmap_v1
parenta3e39c37f750fe3b933a970a470a96780b71e54b (diff)
downloadmongo-daf68ad0c8a23459d490da94403ad97712f8991b.tar.gz
SERVER-13635: move compact tests into mmap_v1
Diffstat (limited to 'jstests/mmap_v1')
-rw-r--r--jstests/mmap_v1/compact.js76
-rw-r--r--jstests/mmap_v1/compact2.js52
-rw-r--r--jstests/mmap_v1/compactPreservePadding.js26
3 files changed, 154 insertions, 0 deletions
diff --git a/jstests/mmap_v1/compact.js b/jstests/mmap_v1/compact.js
new file mode 100644
index 00000000000..2121debc17e
--- /dev/null
+++ b/jstests/mmap_v1/compact.js
@@ -0,0 +1,76 @@
+// compact.js
+
+var mydb = db.getSiblingDB('compact');
+t = mydb.compacttest;
+t.drop();
+t.insert({ x: 3 });
+t.insert({ x: 3 });
+t.insert({ x: 5 });
+t.insert({ x: 4, z: 2, k: 'aaa' });
+t.insert({ x: 4, z: 2, k: 'aaa' });
+t.insert({ x: 4, z: 2, k: 'aaa' });
+t.insert({ x: 4, z: 2, k: 'aaa' });
+t.insert({ x: 4, z: 2, k: 'aaa' });
+t.insert({ x: 4, z: 2, k: 'aaa' });
+t.ensureIndex({ x: 1 });
+
+print("1");
+
+var res = mydb.runCommand({ compact: 'compacttest', dev: true, force: true });
+printjson(res);
+assert(res.ok);
+assert(t.count() == 9);
+var v = t.validate(true);
+assert(v.ok);
+assert(v.extentCount == 1);
+assert(v.deletedCount == 1);
+assert(t.getIndexes().length == 2);
+var ssize = t.stats().storageSize;
+
+print("2");
+res = mydb.runCommand({ compact: 'compacttest', dev: true,paddingBytes:1000, force:true });
+assert(res.ok);
+assert(t.count() == 9);
+var v = t.validate(true);
+assert(v.ok);
+assert(t.stats().storageSize > ssize, "expected more storage given padding is higher. however it rounds off so if something changed this could be");
+//printjson(t.stats());
+
+print("z");
+
+t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
+t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
+t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
+t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
+t.insert({ x: 4, z: null, k: { f: "", b: ""} });
+t.insert({ x: 4, z: null, k: { c: ""} });
+t.insert({ x: 4, z: null, k: { h: ""} });
+t.insert({ x: 4, z: null });
+t.insert({ x: 4, z: 3});
+t.insert({ x: 4, z: 2, k: { a: "", b: ""} });
+t.insert({ x: 4, z: null, k: { c: ""} });
+t.insert({ x: 4, z: null, k: { c: ""} });
+t.insert({ x: 4, z: 3, k: { c: ""} });
+
+t.ensureIndex({ z: 1, k: 1 });
+//t.ensureIndex({ z: 1, k: 1 }, { unique: true });
+//t.ensureIndex({ z: 1, k: 1 }, { dropDups: true, unique:true });
+
+res = mydb.runCommand({ compact: 'compacttest', dev: true, paddingFactor: 1.2, force:true });
+printjson(res);
+assert(res.ok);
+assert(t.count() > 13);
+var v = t.validate(true);
+assert(v.ok);
+
+print("3");
+
+// works on an empty collection?
+t.remove({});
+assert(mydb.runCommand({ compact: 'compacttest', dev: true, force:true }).ok);
+assert(t.count() == 0);
+v = t.validate(true);
+assert(v.ok);
+assert(v.extentCount == 1);
+assert(t.getIndexes().length == 3);
+
diff --git a/jstests/mmap_v1/compact2.js b/jstests/mmap_v1/compact2.js
new file mode 100644
index 00000000000..0a7c343a3f9
--- /dev/null
+++ b/jstests/mmap_v1/compact2.js
@@ -0,0 +1,52 @@
+// Compaction of a v0 index converts it to a v1 index using a v1 index comparator during external
+// sort. SERVER-6499
+
+t = db.jstests_compact2;
+t.drop();
+
+/**
+ * Assert that the index is of the expected version and its keys are ordered consistently with this
+ * version, and that the unique and background fields are set correctly.
+ */
+function assertIndex( expectedVersion, unique, background ) {
+ indexSpec = db.system.indexes.findOne( { ns:t.toString(), key:{ date:1 } } );
+ // The index version is as expected.
+ assert.eq( expectedVersion, indexSpec.v );
+ // The index uniqueness is as expected (treat missing and false unique specs as equivalent).
+ assert.eq( !unique, !indexSpec.unique );
+ // Background is as expected.
+ assert.eq( !background, !indexSpec.background );
+ // Check that 'date' key ordering is consistent with the index version.
+ dates = t.find().hint( { date:1 } ).toArray().map( function( x ) { return x.date; } );
+ if ( expectedVersion == 0 ) {
+ // Under v0 index comparison, new Date( -1 ) > new Date( 1 ).
+ assert.eq( [ new Date( 1 ), new Date( -1 ) ], dates );
+ }
+ else {
+ // Under v1 index comparsion, new Date( -1 ) < new Date( 1 ).
+ assert.eq( [ new Date( -1 ), new Date( 1 ) ], dates );
+ }
+}
+
+/** Compact a collection and check the resulting indexes. */
+function checkCompact( originalVersion, unique, background ) {
+ t.drop();
+ t.save( { date:new Date( 1 ) } );
+ t.save( { date:new Date( -1 ) } );
+ t.ensureIndex( { date:1 }, { unique:unique, v:originalVersion, background:background } );
+ assertIndex( originalVersion, unique, background );
+
+ // Under SERVER-6499, compact fails when a v0 index is converted to a v1 index and key
+ // comparisons are inconsistent, as with the date values in this test.
+ assert.commandWorked( t.runCommand( "compact" ) );
+ assert( !db.getLastError() );
+
+ // Compact built an index with the default index version (v1). Uniqueness is maintained, but
+ // background always becomes false.
+ assertIndex( 1, unique, false );
+}
+
+checkCompact( 0, true, true );
+checkCompact( 0, false, false );
+checkCompact( 1, true, false );
+checkCompact( 1, false, true );
diff --git a/jstests/mmap_v1/compactPreservePadding.js b/jstests/mmap_v1/compactPreservePadding.js
new file mode 100644
index 00000000000..4748afb9a82
--- /dev/null
+++ b/jstests/mmap_v1/compactPreservePadding.js
@@ -0,0 +1,26 @@
+// test preservePadding
+
+var mydb = db.getSiblingDB('compactPreservePadding');
+var collName = "compactPreservePadding";
+var t = mydb.getCollection(collName);
+t.drop();
+
+// use larger keyname to avoid hitting an edge case with extents
+for (i = 0; i < 10000; i++) {
+ t.insert({useLargerKeyName:i});
+}
+
+// remove half the entries
+t.remove({useLargerKeyName:{$mod:[2,0]}})
+printjson(t.stats());
+originalSize = t.stats().size;
+originalStorage = t.stats().storageSize;
+
+// compact!
+mydb.runCommand({compact: collName, preservePadding: true});
+printjson(t.stats());
+
+// 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);