2013-08-27 13:24:43 -04:00
|
|
|
// Tests tracing where a document was inserted
|
2015-11-25 11:20:43 -05:00
|
|
|
load('jstests/libs/trace_missing_docs.js');
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
(function() {
|
|
|
|
|
'use strict';
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
var testDocMissing = function(useReplicaSet) {
|
|
|
|
|
var options = { rs: useReplicaSet,
|
|
|
|
|
shardOptions: { master: "", oplogSize: 10 },
|
|
|
|
|
rsOptions: { nodes: 1, oplogSize: 10 } };
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
var st = new ShardingTest({ shards: 2, mongos: 1, other: options });
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
var mongos = st.s0;
|
|
|
|
|
var coll = mongos.getCollection("foo.bar");
|
|
|
|
|
var admin = mongos.getDB("admin");
|
|
|
|
|
var shards = mongos.getCollection("config.shards").find().toArray();
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
assert.commandWorked(admin.runCommand({ enableSharding: coll.getDB() + "" }));
|
|
|
|
|
st.ensurePrimaryShard(coll.getDB() + "", shards[0]._id);
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
coll.ensureIndex({ sk: 1 });
|
|
|
|
|
assert.commandWorked(admin.runCommand({ shardCollection: coll + "", key: { sk: 1 } }));
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
assert.writeOK(coll.insert({ _id: 12345, sk: 67890, hello: "world" }));
|
|
|
|
|
assert.writeOK(coll.update({ _id: 12345 }, { $set: { baz: 'biz' } }));
|
|
|
|
|
assert.writeOK(coll.update({ sk: 67890 }, { $set: { baz: 'boz' } }));
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
assert.commandWorked(admin.runCommand({ moveChunk: coll + "",
|
|
|
|
|
find: { sk: 0 },
|
|
|
|
|
to: shards[1]._id,
|
|
|
|
|
_waitForDelete: true }));
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
st.printShardingStatus();
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
var ops = traceMissingDoc(coll, { _id: 12345, sk: 67890 });
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
assert.eq(ops[0].op, 'i');
|
|
|
|
|
assert.eq(ops.length, 5);
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
jsTest.log("DONE! " + (useReplicaSet ? "(using rs)": "(using master/slave)"));
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
st.stop();
|
|
|
|
|
};
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
testDocMissing(true);
|
|
|
|
|
testDocMissing(false);
|
2013-08-27 13:24:43 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
})();
|