0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00

SERVER-28154 Remove race condition in ttl_sharded.js

This commit is contained in:
Tess Avitabile 2017-03-01 11:09:47 -05:00
parent 0d40815359
commit cb2fdf4684

View File

@ -36,15 +36,14 @@ t.ensureIndex({x: 1}, {expireAfterSeconds: 20000});
s.adminCommand({split: ns, middle: {_id: 12}});
s.adminCommand({moveChunk: ns, find: {_id: 0}, to: s.getOther(s.getPrimaryShard(dbname)).name});
// one shard will lose 12/12 docs, the other 6/12, so count will go
// from 24 -> 18 or 12 -> 6
assert.soon(function() {
return t.count() < 7;
}, "TTL index on x didn't delete enough", 70 * 1000);
// ensure that count ultimately ends up at 6
assert.eq(0, t.find({x: {$lt: new Date(now - 20000000)}}).count());
assert.eq(6, t.count());
// Check that all expired documents are deleted.
assert.soon(
function() {
return t.count() === 6 && t.find({x: {$lt: new Date(now - 20000000)}}).count() === 0;
},
"TTL index did not successfully delete expired documents, all documents: " +
tojson(t.find().toArray()),
70 * 1000);
// now lets check things explicily on each shard
var shard0 = s._connections[0].getDB(dbname);
@ -73,10 +72,13 @@ s.getDB(dbname).runCommand({collMod: coll, index: {keyPattern: {x: 1}, expireAft
assert.eq(10000, getTTLTime(shard0.getCollection(coll), {x: 1}));
assert.eq(10000, getTTLTime(shard1.getCollection(coll), {x: 1}));
assert.soon(function() {
return t.count() < 6;
}, "new expireAfterSeconds value not taking effect", 70 * 1000);
assert.eq(0, t.find({x: {$lt: new Date(now - 10000000)}}).count());
assert.eq(3, t.count());
// Check that all expired documents are deleted.
assert.soon(
function() {
return t.count() === 3 && t.find({x: {$lt: new Date(now - 10000000)}}).count() === 0;
},
"new expireAfterSeconds did not successfully delete expired documents, all documents: " +
tojson(t.find().toArray()),
70 * 1000);
s.stop();