[SERVER-28285] renameCollection should only generate one oplog entry Created: 13/Mar/17  Updated: 06/Dec/17  Resolved: 21/Apr/17

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

Type: Bug Priority: Major - P3
Reporter: Geert Bosch Assignee: Geert Bosch
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-30371 Separate renameCollection across DB c... Closed
is related to SERVER-27989 Add collection UUIDs to oplog entries Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Run the following test:

(function(){
    let rs = new ReplSetTest({nodes:1});
    rs.startSet();
    rs.initiate();
 
    let prim = rs.getPrimary();
    let test = prim.getDB("test");
    let local = prim.getDB("local");
 
    test.x.drop();
    test.x.insert({});
    test.y.insert({});
    let ts = local.oplog.rs.find().sort({$natural:-1}).limit(1).next().ts;
    test.y.renameCollection("x", true);
 
    ops = local.oplog.rs.find({ts:{$gt: ts}}).sort({$natural:1}).toArray();
    assert.eq(ops.length, 1,
        "renameCollection was supposed to only generate a single oplog entry: " + tojson(ops));
})();

Current output is:

assert: [2] != [1] are not equal : renameCollection was supposed to only generate a single oplog entry: [
	{
		"ts" : Timestamp(1489385287, 6),
		"t" : NumberLong(1),
		"h" : NumberLong("-3656781107160762734"),
		"v" : 2,
		"op" : "c",
		"ns" : "test.$cmd",
		"o" : {
			"drop" : "x"
		}
	},
	{
		"ts" : Timestamp(1489385287, 7),
		"t" : NumberLong(1),
		"h" : NumberLong("-5606475750286919212"),
		"v" : 2,
		"op" : "c",
		"ns" : "test.$cmd",
		"o" : {
			"renameCollection" : "test.y",
			"to" : "test.x",
			"stayTemp" : false,
			"dropTarget" : true
		}
	}
]

Sprint: Storage 2017-05-08
Participants:

 Description   

With dropTarget : True, the renameCollection command will generate two oplog entries.

One use of renameCollection is to atomically replace a collection x with an updated version of that collection. However, a read on a secondary could fail to see any version of x at all. Similarly, a crash at that point in time on the primary could result in the secondary taking over without a collection x present. Instead, we should not write the oplog entry for the implicit dropCollection.


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