[SERVER-33046] Test "create" and "drop" commands on views with applyOps. Created: 31/Jan/18  Updated: 06/Dec/22  Resolved: 07/Feb/18

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Shane Harvey Assignee: Backlog - Replication Team
Resolution: Won't Fix Votes: 0
Labels: read-only-views
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Replication
Participants:

 Description   

Please add a test that creating and dropping views works with applyOps.

For example, applying a "create" oplog entry should create a view:

> db.adminCommand({applyOps: [{"op" : "c", "ns" : "test.$cmd", "o" : { "create" : "viewColl", "viewOn" : "test", "pipeline" : [ ] } }]});
{ "applied" : 1, "results" : [ true ], "ok" : 1 }
> db.getCollectionInfos({name:"viewColl"})
[
	{
		"name" : "viewColl",
		"type" : "view",
		"options" : {
			"viewOn" : "test",
			"pipeline" : [ ]
		},
		"info" : {
			"readOnly" : true
		}
	}
]

Applying a "drop" oplog entry should delete the view:

> db.adminCommand({applyOps: [{op:"c", ns: "test.$cmd", o:{"drop":"viewColl"}}]})
{ "applied" : 1, "results" : [ true ], "ok" : 1 }
> db.getCollectionInfos({name:"viewColl"})
[ ]

This currently works on 3.4 and 3.6.



 Comments   
Comment by Spencer Brody (Inactive) [ 07/Feb/18 ]

applyOps only supports applying oplog entries. I don't think we should be supporting using applyOps to apply anything other than a valid oplog entry generated by a mongodb server.

Comment by Kyle Suarez [ 06/Feb/18 ]

Hey shane.harvey,

We discussed this in Repl Team standup, and it is dubious that applying an op representing the create command will always be exactly equivalent to an op representing an insertion into system.views. Some cursory testing suggests that this "just works", but it definitely is not something we had in mind when we implemented the system. I know that batch application is different for commands than for CRUD operations, and that there may not be any atomicity guarantees about using applyOps to execute commands. spencer would be able to speak to this in more detail than myself.

Would it be possible for MongoMirror to do something else to achieve what it wants to do? For example, could it simply run the create command directly, rather than rewriting oplog entries and using applyOps?

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