Files
mongo/jstests/replsets/oplog_format_create_indexes.js
Max Hirschhorn 8302d0735b SERVER-24033 Write full index spec in oplog entry for index creation.
This ensures that the index version (aka the "v" field) is always
present in the oplog entry when creating indexes on a 3.4 primary.
We can therefore assume that if the "v" field isn't present in the
corresponding oplog entry, then a v=1 index should be built.

Changes MultiBlockIndex::init() to return the index specifications
that were actually created.

The "repairDatabase", "compact", "copydb", and "cloneCollection"
commands no longer automatically upgrade the index version to the
current default version. Instead, the only command that does so is
the "reIndex" command.
2016-09-14 20:49:17 -04:00

62 lines
2.7 KiB
JavaScript

/**
* Tests that the index's full specification is included in the oplog entry corresponding to its
* creation.
*/
(function() {
"use strict";
load("jstests/libs/get_index_helpers.js");
var rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();
var primary = rst.getPrimary();
var testDB = primary.getDB("test");
var oplogColl = primary.getDB("local").oplog.rs;
function testOplogEntryContainsIndexInfoObj(coll, keyPattern, indexOptions) {
assert.commandWorked(coll.createIndex(keyPattern, indexOptions));
var allIndexes = coll.getIndexes();
var indexSpec = GetIndexHelpers.findByKeyPattern(allIndexes, keyPattern);
assert.neq(
null,
indexSpec,
"Index with key pattern " + tojson(keyPattern) + " not found: " + tojson(allIndexes));
var indexCreationOplogQuery = {op: "i", ns: testDB.system.indexes.getFullName()};
var allOplogEntries = oplogColl.find(indexCreationOplogQuery).toArray();
var found = allOplogEntries.filter(function(entry) {
return bsonWoCompare(entry.o, indexSpec) === 0;
});
assert.eq(1,
found.length,
"Failed to find full index specification " + tojson(indexSpec) +
" in any oplog entry from index creation: " + tojson(allOplogEntries));
assert.commandWorked(coll.dropIndex(keyPattern));
}
// Test that options both explicitly included in the command and implicitly filled in with
// defaults by the server are serialized into the corresponding oplog entry.
testOplogEntryContainsIndexInfoObj(testDB.oplog_format, {withoutAnyOptions: 1});
testOplogEntryContainsIndexInfoObj(testDB.oplog_format, {withV1: 1}, {v: 1});
testOplogEntryContainsIndexInfoObj(testDB.oplog_format,
{partialIndex: 1},
{partialFilterExpression: {field: {$exists: true}}});
// Test that the representation of an index's collation in the oplog on a collection with a
// non-simple default collation exactly matches that of the index's full specification.
assert.commandWorked(
testDB.runCommand({create: "oplog_format_collation", collation: {locale: "fr"}}));
testOplogEntryContainsIndexInfoObj(testDB.oplog_format_collation, {withDefaultCollation: 1});
testOplogEntryContainsIndexInfoObj(
testDB.oplog_format_collation, {withNonDefaultCollation: 1}, {collation: {locale: "en"}});
testOplogEntryContainsIndexInfoObj(testDB.oplog_format_collation, {withV1: 1}, {v: 1});
testOplogEntryContainsIndexInfoObj(
testDB.oplog_format_collation, {withSimpleCollation: 1}, {collation: {locale: "simple"}});
rst.stopSet();
})();