[SERVER-31435] Creating an index through applyOps is not replicated Created: 06/Oct/17  Updated: 30/Oct/23  Resolved: 06/Nov/17

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Replication
Affects Version/s: None
Fix Version/s: 3.6.0-rc3

Type: Bug Priority: Critical - P2
Reporter: Tess Avitabile (Inactive) Assignee: Maria van Keulen
Resolution: Fixed Votes: 0
Labels: todo_in_code
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-29828 createIndexes oplog entry should prod... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

On a 1-node replica set:

> db.createCollection("c")
> db.getCollectionInfos()
[
	{
		"name" : "c",
		"type" : "collection",
		"options" : {
			
		},
		"info" : {
			"readOnly" : false,
			"uuid" : UUID("44dd4cdb-4889-43e1-bd2c-f7375d92c8f8")
		},
		"idIndex" : {
			"v" : 2,
			"key" : {
				"_id" : 1
			},
			"name" : "_id_",
			"ns" : "test.c"
		}
	}
]
> db.runCommand({applyOps: [{op: "c", ns: "test.c", ui: UUID("44dd4cdb-4889-43e1-bd2c-f7375d92c8f8"), o: {createIndexes: "c", v: 2, key: {a: 1}, name: "a_1"}}]})
> db.c.getIndexes()
[
	{
		"v" : 2,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_",
		"ns" : "test.c"
	},
	{
		"v" : 2,
		"key" : {
			"a" : 1
		},
		"name" : "a_1",
		"ns" : "test.c"
	}
]
> use local
> db.oplog.rs.find().pretty()
{
	"ts" : Timestamp(1507299002, 1),
	"h" : NumberLong("4324269916467276683"),
	"v" : 2,
	"op" : "n",
	"ns" : "",
	"o" : {
		"msg" : "initiating set"
	}
}
{
	"ts" : Timestamp(1507299004, 1),
	"t" : NumberLong(1),
	"h" : NumberLong("8480815567193554397"),
	"v" : 2,
	"op" : "n",
	"ns" : "",
	"wall" : ISODate("2017-10-06T14:10:04.886Z"),
	"o" : {
		"msg" : "new primary"
	}
}
{
	"ts" : Timestamp(1507299004, 2),
	"t" : NumberLong(1),
	"h" : NumberLong("1378629489624595755"),
	"v" : 2,
	"op" : "c",
	"ns" : "config.$cmd",
	"ui" : UUID("87ad6081-0db2-46cb-9d00-149ecb46d6d1"),
	"wall" : ISODate("2017-10-06T14:10:04.952Z"),
	"o" : {
		"create" : "transactions",
		"idIndex" : {
			"v" : 2,
			"key" : {
				"_id" : 1
			},
			"name" : "_id_",
			"ns" : "config.transactions"
		}
	}
}
{
	"ts" : Timestamp(1507299029, 1),
	"t" : NumberLong(1),
	"h" : NumberLong("-7494492021434764735"),
	"v" : 2,
	"op" : "c",
	"ns" : "admin.$cmd",
	"ui" : UUID("c46411b5-27fa-4a07-869f-0ab592b27245"),
	"wall" : ISODate("2017-10-06T14:10:29.769Z"),
	"o" : {
		"create" : "system.keys",
		"idIndex" : {
			"v" : 2,
			"key" : {
				"_id" : 1
			},
			"name" : "_id_",
			"ns" : "admin.system.keys"
		}
	}
}
{
	"ts" : Timestamp(1507299029, 2),
	"t" : NumberLong(1),
	"h" : NumberLong("-3000009358249085337"),
	"v" : 2,
	"op" : "i",
	"ns" : "admin.system.keys",
	"ui" : UUID("c46411b5-27fa-4a07-869f-0ab592b27245"),
	"wall" : ISODate("2017-10-06T14:10:29.769Z"),
	"o" : {
		"_id" : NumberLong("6473799927473373186"),
		"purpose" : "HMAC",
		"key" : BinData(0,"ysjEJXM2UXNCJ9GepIlvYuvq+KM="),
		"expiresAt" : Timestamp(1515075004, 0)
	}
}
{
	"ts" : Timestamp(1507299029, 3),
	"t" : NumberLong(1),
	"h" : NumberLong("4654173349023495145"),
	"v" : 2,
	"op" : "i",
	"ns" : "admin.system.keys",
	"ui" : UUID("c46411b5-27fa-4a07-869f-0ab592b27245"),
	"wall" : ISODate("2017-10-06T14:10:29.783Z"),
	"o" : {
		"_id" : NumberLong("6473799927473373187"),
		"purpose" : "HMAC",
		"key" : BinData(0,"GVzdBk6CjLMjVMo9aZId1oBxOb4="),
		"expiresAt" : Timestamp(1522851004, 0)
	}
}
{
	"ts" : Timestamp(1507299095, 1),
	"t" : NumberLong(1),
	"h" : NumberLong("2281830126279321321"),
	"v" : 2,
	"op" : "c",
	"ns" : "test.$cmd",
	"ui" : UUID("44dd4cdb-4889-43e1-bd2c-f7375d92c8f8"),
	"wall" : ISODate("2017-10-06T14:11:35.888Z"),
	"o" : {
		"create" : "c",
		"idIndex" : {
			"v" : 2,
			"key" : {
				"_id" : 1
			},
			"name" : "_id_",
			"ns" : "test.c"
		}
	}
}

Sprint: Storage 2017-10-23, Storage 2017-11-13
Participants:

 Description   

Running applyOps with a createIndexes-style oplog entry (which is produced in featureCompatibilityVersion 3.6) does not produce an oplog entry, so it is not replicated.



 Comments   
Comment by Githook User [ 06/Nov/17 ]

Author:

{'name': 'Maria van Keulen', 'username': 'mvankeulen94', 'email': 'maria@mongodb.com'}

Message: SERVER-31435 Move applyOps index collation test into jsCore
Branch: master
https://github.com/mongodb/mongo/commit/880a044852cc099ab9edb61a3b1b173e68ec5deb

Comment by Eric Milkie [ 03/Nov/17 ]

Yes, I believe we can do that. Thanks for the reminder!

Comment by Tess Avitabile (Inactive) [ 03/Nov/17 ]

Would it be possible to handle this TODO to move apply_ops_index_collation.js into core in a follow-on commit?

Comment by Githook User [ 03/Nov/17 ]

Author:

{'name': 'Maria van Keulen', 'username': 'mvankeulen94', 'email': 'maria@mongodb.com'}

Message: SERVER-31435 Ensure applyOps with createIndexes replicates
Branch: master
https://github.com/mongodb/mongo/commit/3004e7b34d79187cc4691bef3038e4c69285fc78

Comment by Andy Schwerin [ 06/Oct/17 ]

mongomirror and mongorestore both use applyOps and may restore to replica sets, so this seems severe.

Comment by Tess Avitabile (Inactive) [ 06/Oct/17 ]

schwerin, spencer, can you advise on the severity of this bug? It seems bad that you can run an operation on a primary that is not replicated. However, applyOps may not be used much outside of backup, which uses standalones, and it requires special privilege to use applyOps.

Note that the bug does not exist for index creations using insertion into system.indexes, which is done on 3.4 and in featureCompatibilityVersion 3.4.

Generated at Thu Feb 08 04:27:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.