blob: f8394b090cc546d06ccbd4f35f475adaac5fa35a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/**
* Tests that standalone nodes with replica set data are unable to upgrade or downgrade FCV while
* the config.transactions collection is non-empty.
* @tags: [uses_transactions, requires_persistence]
*/
(function() {
"use strict";
load("jstests/libs/feature_compatibility_version.js");
let replTest = new ReplSetTest({nodes: 1});
replTest.startSet();
replTest.initiate();
const primary = replTest.getPrimary();
const dbName = "test";
const collName = "set_fcv_42_on_standalone";
let adminDB = primary.getDB('admin');
assert.commandWorked(primary.getDB(dbName).createCollection(collName));
jsTestLog("Downgrade the featureCompatibilityVersion.");
assert.commandWorked(adminDB.adminCommand({setFeatureCompatibilityVersion: lastStableFCV}));
checkFCV(adminDB, lastStableFCV);
const session = primary.startSession();
const sessionDB = session.getDatabase(dbName);
session.startTransaction();
assert.commandWorked(sessionDB[collName].insert({_id: 1}));
assert.commandWorked(session.commitTransaction_forTesting());
// Restarting as a standalone causes the node to restart from the stable timestamp without applying
// operations from the oplog.
replTest.awaitLastStableRecoveryTimestamp();
jsTestLog(
"Test upgrade on a standalone with replica set data and a non-empty config.transactions table.");
const standalone = replTest.restart(0, {noReplSet: true});
adminDB = standalone.getDB('admin');
const localDB = standalone.getDB('local');
const replSetData = localDB.getCollection('system.replset').findOne();
assert.neq(null, replSetData);
// Make sure the config.transactions table is not empty.
const configDB = standalone.getDB('config');
const txnRecord = configDB.getCollection('transactions').findOne();
assert.neq(null, txnRecord);
// Should fail on featureCompatibilityVersion upgrade attempt.
assert.commandFailedWithCode(
standalone.getDB('admin').adminCommand({setFeatureCompatibilityVersion: latestFCV}),
ErrorCodes.IllegalOperation);
jsTestLog(
"Empty the config.transactions table and successfully upgrade featureCompatibilityVersion.");
assert.commandWorked(configDB.getCollection('transactions').remove({}));
assert.commandWorked(configDB.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
checkFCV(adminDB, latestFCV);
jsTestLog(
"Test downgrade on a standalone with replica set data and a non-empty config.transactions table.");
assert.commandWorked(configDB.getCollection('transactions').insertOne(txnRecord));
// Should fail on featureCompatibilityVersion downgrade attempt.
assert.commandFailedWithCode(
standalone.getDB('admin').adminCommand({setFeatureCompatibilityVersion: lastStableFCV}),
ErrorCodes.IllegalOperation);
jsTestLog(
"Empty the config.transactions table and successfully downgrade featureCompatibilityVersion.");
assert.commandWorked(configDB.getCollection('transactions').remove({}));
assert.commandWorked(configDB.adminCommand({setFeatureCompatibilityVersion: lastStableFCV}));
checkFCV(adminDB, lastStableFCV);
replTest.stopSet();
})();
|