2015-01-14 22:45:39 +01:00
|
|
|
// SERVER-16676 Make sure compact doesn't leave the collection with bad indexes
|
2015-01-22 21:08:01 +01:00
|
|
|
// SERVER-16967 Make sure compact doesn't crash while collections are being dropped
|
|
|
|
// in a different database.
|
2018-04-11 20:09:01 +02:00
|
|
|
// @tags: [
|
2019-03-11 23:17:29 +01:00
|
|
|
// # compact command is not available on embedded
|
|
|
|
// incompatible_with_embedded,
|
|
|
|
// uses_multiple_connections,
|
2018-04-11 20:09:01 +02:00
|
|
|
// ]
|
2015-01-14 22:45:39 +01:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var coll = db.compact_keeps_indexes;
|
|
|
|
|
2015-01-22 21:08:01 +01:00
|
|
|
coll.drop();
|
2016-03-09 18:17:50 +01:00
|
|
|
coll.insert({_id: 1, x: 1});
|
|
|
|
coll.ensureIndex({x: 1});
|
2015-01-14 22:45:39 +01:00
|
|
|
|
|
|
|
assert.eq(coll.getIndexes().length, 2);
|
|
|
|
|
2015-02-04 22:29:56 +01:00
|
|
|
// force:true is for replset passthroughs
|
2016-03-09 18:17:50 +01:00
|
|
|
var res = coll.runCommand('compact', {force: true});
|
2015-01-22 21:08:01 +01:00
|
|
|
// Some storage engines (for example, inMemoryExperiment) do not support the compact command.
|
2016-03-09 18:17:50 +01:00
|
|
|
if (res.code == 115) { // CommandNotSupported
|
2015-01-22 21:08:01 +01:00
|
|
|
return;
|
2015-01-14 22:45:39 +01:00
|
|
|
}
|
2015-01-22 21:08:01 +01:00
|
|
|
assert.commandWorked(res);
|
2015-01-14 22:45:39 +01:00
|
|
|
|
|
|
|
assert.eq(coll.getIndexes().length, 2);
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.eq(coll.find({_id: 1}).itcount(), 1);
|
|
|
|
assert.eq(coll.find({x: 1}).itcount(), 1);
|
2015-01-22 21:08:01 +01:00
|
|
|
|
2018-02-14 23:19:14 +01:00
|
|
|
var dropCollectionShell = startParallelShell(function() {
|
|
|
|
var t = db.getSiblingDB('test_compact_keeps_indexes_drop').testcoll;
|
|
|
|
t.drop();
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
t.save({a: 1});
|
2015-01-22 21:08:01 +01:00
|
|
|
t.drop();
|
|
|
|
}
|
2018-02-14 23:19:14 +01:00
|
|
|
});
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
coll.runCommand('compact');
|
2015-01-22 21:08:01 +01:00
|
|
|
}
|
2018-02-14 23:19:14 +01:00
|
|
|
dropCollectionShell();
|
|
|
|
|
2016-02-04 18:29:01 +01:00
|
|
|
}());
|