[SERVER-33956] A sequence of rename and create collections that do not arrive at the correct end state Created: 16/Mar/18  Updated: 29/Oct/23  Resolved: 29/Mar/18

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: None
Fix Version/s: 3.6.5, 3.7.4

Type: Bug Priority: Major - P3
Reporter: Daniel Gottlieb (Inactive) Assignee: Benety Goh
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
is depended on by SERVER-33946 Decrease number of initial sync attem... Blocked
Duplicate
is duplicated by SERVER-34727 Rename collection during initial sync... Closed
Related
related to SERVER-34196 OpObserver::onRenameCollection() drop... Closed
is related to SERVER-33087 Fix the use of dropTarget in renameCo... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

var ops = [{ "ts" : Timestamp(1520987616, 1), "t" : NumberLong(1), "h" : NumberLong("4979632704283227657"), "v" : 2, "op" : "c", "ns" : "test.$cmd", "ui" : UUID("7b447a86-5a12-42bc-916f-edcbfcb71cc0"), "wall" : ISODate("2018-03-14T00:33:36.010Z"), "o" : { "create" : "bar", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.bar" } } },
	   { "ts" : Timestamp(1520987616, 1), "t" : NumberLong(1), "h" : NumberLong("4979632704283227657"), "v" : 2, "op" : "c", "ns" : "test.$cmd", "ui" : UUID("16ce21b8-320c-4bfc-af8c-05cae93bdadb"), "wall" : ISODate("2018-03-14T00:33:36.010Z"), "o" : { "create" : "shardedColl", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.shardedColl" } } },
	   { "ts" : Timestamp(1520987617, 29), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("78f0578a-1ecf-4ba3-af46-bfc13ebb46fa"), "wall" : ISODate("2018-03-14T00:33:37.571Z"),
	     "o" : { "renameCollection" : "test.bar", "to" : "test.shardedColl", "stayTemp" : false,
		     "dropTarget" : false } },
	   { "ts" : Timestamp(1520987618,  3), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("16ce21b8-320c-4bfc-af8c-05cae93bdadb"), "wall" : ISODate("2018-03-14T00:33:38.073Z"),
	     "o" : { "renameCollection" : "test.foo", "to" : "test.bar", "stayTemp" : false,
		     "dropTarget" : true } },
	   { "ts" : Timestamp(1520987621, 2), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("7b447a86-5a12-42bc-916f-edcbfcb71cc0"), "wall" : ISODate("2018-03-14T00:33:41.532Z"),
	     "o" : { "create" : "foo", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.foo" } } },
	   { "ts" : Timestamp(1520987622,  2), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("16ce21b8-320c-4bfc-af8c-05cae93bdadb"), "wall" : ISODate("2018-03-14T00:33:42.103Z"),
	     "o" : { "renameCollection" : "test.bar", "to" : "test.shardedColl", "stayTemp" : false,
		     "dropTarget" : UUID("78f0578a-1ecf-4ba3-af46-bfc13ebb46fa") } },
	   { "ts" : Timestamp(1520987622,  9), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("7b447a86-5a12-42bc-916f-edcbfcb71cc0"), "wall" : ISODate("2018-03-14T00:33:42.437Z"),
	     "o" : { "renameCollection" : "test.foo", "to" : "test.bar", "stayTemp" : false,
		     "dropTarget" : true } }]
db.adminCommand({applyOps: ops})

Sprint: Repl 2018-04-09
Participants:
Linked BF Score: 4

 Description   

Consider a node initial syncing from a primary. The initial syncing node, before the oplog application phase has the following collection -> UUID mappings:

test.foo -> Does not exist
test.bar -> UUID("7b447a86-5a12-42bc-916f-edcbfcb71cc0")
test.shardedColl -> UUID("16ce21b8-320c-4bfc-af8c-05cae93bdadb")

It also happens to be that this is the correct goal state.

Now consider the sequence of oplog entries that are played as part of the oplog application step of initial sync:

{ "ts" : Timestamp(1520987617, 29), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("78f0578a-1ecf-4ba3-af46-bfc13ebb46fa"), "wall" : ISODate("2018-03-14T00:33:37.571Z"),
  "o" : { "renameCollection" : "test.bar", "to" : "test.shardedColl", "stayTemp" : false,
	  "dropTarget" : true } }
 
{ "ts" : Timestamp(1520987618,  3), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("16ce21b8-320c-4bfc-af8c-05cae93bdadb"), "wall" : ISODate("2018-03-14T00:33:38.073Z"),
  "o" : { "renameCollection" : "test.foo", "to" : "test.bar", "stayTemp" : false,
	  "dropTarget" : true } }
 
{ "ts" : Timestamp(1520987621, 2), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("7b447a86-5a12-42bc-916f-edcbfcb71cc0"), "wall" : ISODate("2018-03-14T00:33:41.532Z"),
  "o" : { "create" : "foo", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.foo" } } }
 
{ "ts" : Timestamp(1520987622,  2), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("16ce21b8-320c-4bfc-af8c-05cae93bdadb"), "wall" : ISODate("2018-03-14T00:33:42.103Z"),
  "o" : { "renameCollection" : "test.bar", "to" : "test.shardedColl", "stayTemp" : false,
	  "dropTarget" : UUID("78f0578a-1ecf-4ba3-af46-bfc13ebb46fa") } }
 
{ "ts" : Timestamp(1520987622,  9), "op" : "c", "ns" : "test.$cmd", "ui" : UUID("7b447a86-5a12-42bc-916f-edcbfcb71cc0"), "wall" : ISODate("2018-03-14T00:33:42.437Z"),
  "o" : { "renameCollection" : "test.foo", "to" : "test.bar", "stayTemp" : false,
	  "dropTarget" : true } }

Those operations result in the initial syncing node to only have test.shardedColl -> UUID("16ce21b8-320c-4bfc-af8c-05cae93bdadb") while missing the expected test.bar collection.

I can make statements about behavior change that fix this specific sequence, but I can't speak to their correctness globally.

I do have two observations that might illuminate what's going wrong.

  1. judah.schvimer notes that when collections have UUIDs, a replicated renameCollection's dropTarget should never be true. It should be changed to false if the target did not exist, or it should be the UUID of the collection that was dropped.
  2. Perhaps more subtly, in this sequence (which is true for using applyOps, as well as what was observed on the initial syncing node), the creation of test.foo fails because the UUID already exists from the collection that was dropped as the target of the previous rename.

2018-03-16T19:13:59.519-0400 I COMMAND  [conn1] CMD: create test.foo - existing collection with conflicting UUID 7b447a86-5a12-42bc-916f-edcbfcb71cc0 is in a drop-pending state: test.system.drop.1521242039i3t1.bar

One clarification about the reproduction script. The first two "oplog entries" are simply to recreate the state of the initial syncing node before it began oplog application. Had a primary produced that sequence of oplog entries, including the initial creates would be a very different problem.



 Comments   
Comment by Githook User [ 24/Apr/18 ]

Author:

{'email': 'benety@mongodb.com', 'username': 'benety', 'name': 'Benety Goh'}

Message: SERVER-33956 renameCollection creates oplog entry with dropTarget set to false if target collection does not exist

(cherry picked from commit 0d02b8352e3f44385276fb2bbc6f5c09736afa04)
Branch: v3.6
https://github.com/mongodb/mongo/commit/644e8332bd1909284cab7d8b2046ae7af61ecf64

Comment by Githook User [ 24/Apr/18 ]

Author:

{'email': 'benety@mongodb.com', 'username': 'benety', 'name': 'Benety Goh'}

Message: SERVER-33956 add renameCollection characterization test case for dropTarget=true

This test case demonstrates the current behavior when the target collection does
not exist.

(cherry picked from commit c2d54f70ad7b23bba86776f60504dc4916dead27)
Branch: v3.6
https://github.com/mongodb/mongo/commit/76949ff635977cab46df44f1f10f1002f59755f6

Comment by Githook User [ 29/Mar/18 ]

Author:

{'email': 'benety@mongodb.com', 'name': 'Benety Goh', 'username': 'benety'}

Message: SERVER-33956 renameCollection creates oplog entry with dropTarget set to false if target collection does not exist
Branch: master
https://github.com/mongodb/mongo/commit/0d02b8352e3f44385276fb2bbc6f5c09736afa04

Comment by Githook User [ 29/Mar/18 ]

Author:

{'email': 'benety@mongodb.com', 'name': 'Benety Goh', 'username': 'benety'}

Message: SERVER-33956 add renameCollection characterization test case for dropTarget=true

This test case demonstrates the current behavior when the target collection does
not exist.
Branch: master
https://github.com/mongodb/mongo/commit/c2d54f70ad7b23bba86776f60504dc4916dead27

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