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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/**
* Tests upgrading a standalone node or replica set through several major versions.
*
* For each version downloaded by the multiversion setup:
* - Start a node or replica set of that version, without clearing data files from the previous
* iteration.
* - Create a new collection.
* - Insert a document into the new collection.
* - Create an index on the new collection.
*
* This test requires mmapv1 since 2.6 is tested. This can be removed when 2.6 is dropped.
* @tags: [requires_mmapv1]
*/
(function() {
'use strict';
load('jstests/libs/get_index_helpers.js');
load('jstests/multiVersion/libs/multi_rs.js');
load('jstests/multiVersion/libs/verify_versions.js');
// Setup the dbpath for this test.
const dbpath = MongoRunner.dataPath + 'major_version_upgrade';
resetDbpath(dbpath);
// We set noCleanData to true in order to preserve the data files between iterations.
const defaultOptions = {
dbpath: dbpath,
noCleanData: true,
};
// This lists all supported releases and needs to be kept up to date as versions are added and
// dropped.
// TODO SERVER-26792: In the future, we should have a common place from which both the
// multiversion setup procedure and this test get information about supported major releases.
const versions = [
{binVersion: '2.6', testCollection: 'two_six'},
{binVersion: '3.0', testCollection: 'three_zero'},
{binVersion: '3.2', testCollection: 'three_two'},
{binVersion: '3.2.1', testCollection: 'three_two_one'},
{binVersion: 'last-stable', testCollection: 'last_stable'},
{binVersion: 'latest', testCollection: 'latest'},
];
// Standalone
// Iterate from earliest to latest versions specified in the versions list, and follow the steps
// outlined at the top of this test file.
for (let i = 0; i < versions.length; i++) {
let version = versions[i];
let latestOptions = Object.extend({binVersion: version.binVersion}, defaultOptions);
var changedAuthMechanism = false;
if (TestData.authMechanism === "SCRAM-SHA-1" && version.binVersion === "2.6") {
TestData.authMechanism = undefined;
DB.prototype._defaultAuthenticationMechanism = "MONGODB-CR";
changedAuthMechanism = true;
}
// Start a mongod with specified version.
let conn = MongoRunner.runMongod(latestOptions);
assert.neq(
null, conn, 'mongod was unable to start up with options: ' + tojson(latestOptions));
assert.binVersion(conn, version.binVersion);
// Connect to the 'test' database.
let testDB = conn.getDB('test');
// Verify that the data and indices from previous iterations are still accessible.
for (let j = 0; j < i; j++) {
let oldVersionCollection = versions[j].testCollection;
assert.eq(1,
testDB[oldVersionCollection].count(),
`data from ${oldVersionCollection} should be available; options: ` +
tojson(latestOptions));
assert.neq(
null,
GetIndexHelpers.findByKeyPattern(testDB[oldVersionCollection].getIndexes(), {a: 1}),
`index from ${oldVersionCollection} should be available; options: ` +
tojson(latestOptions));
}
// Create a new collection.
assert.commandWorked(testDB.createCollection(version.testCollection));
// Insert a document into the new collection.
assert.writeOK(testDB[version.testCollection].insert({a: 1}));
assert.eq(
1,
testDB[version.testCollection].count(),
`mongo should have inserted 1 document into collection ${version.testCollection}; ` +
'options: ' + tojson(latestOptions));
// Create an index on the new collection.
assert.commandWorked(testDB[version.testCollection].createIndex({a: 1}));
// Shutdown the current mongod.
MongoRunner.stopMongod(conn);
if (version.binVersion === "2.6" && changedAuthMechanism) {
TestData.authMechanism = "SCRAM-SHA-1";
DB.prototype._defaultAuthenticationMechanism = "SCRAM-SHA-1";
changedAuthMechanisms = false;
}
}
// Replica Sets
// Setup the ReplSetTest object.
let nodes = {
n1: {binVersion: versions[0].binVersion},
n2: {binVersion: versions[0].binVersion},
n3: {binVersion: versions[0].binVersion},
};
var changedAuthMechanisms = false;
if (TestData.authMechanism === "SCRAM-SHA-1" && versions[0].binVersion === "2.6") {
TestData.authMechanism = undefined;
DB.prototype._defaultAuthenticationMechanism = "MONGODB-CR";
changedAuthMechanism = true;
}
let rst = new ReplSetTest({nodes});
// Start up and initiate the replica set.
rst.startSet();
// ReplSetTest.stepUp() requires replSetGetConfig, which is not available in 2.6, so we
// use initiateWithAnyNodeAsPrimary() instead.
rst.initiateWithAnyNodeAsPrimary();
// Iterate from earliest to latest versions specified in the versions list, and follow the steps
// outlined at the top of this test file.
for (let i = 0; i < versions.length; i++) {
let version = versions[i];
rst.upgradeSet({binVersion: version.binVersion});
if (version.binVersion != "2.6" && changedAuthMechanism) {
TestData.authMechanism = "SCRAM-SHA-1";
DB.prototype._defaultAuthenticationMechanism = "SCRAM-SHA-1";
changedAuthMechanisms = false;
}
// Connect to the primary to ensure that the test can insert and create indices.
let conn = rst.getPrimary();
assert.neq(
null, conn, `replica set was unable to start up with version: ${version.binVersion}`);
assert.binVersion(conn, version.binVersion);
// Connect to the 'test' database.
let testDB = conn.getDB('test');
// Verify that the data and indices from previous iterations are still accessible.
for (let j = 0; j < i; j++) {
let oldVersionCollection = versions[j].testCollection;
assert.eq(
1,
testDB[oldVersionCollection].count(),
`data from ${oldVersionCollection} should be available; nodes: ${tojson(nodes)}`);
assert.neq(
null,
GetIndexHelpers.findByKeyPattern(testDB[oldVersionCollection].getIndexes(), {a: 1}),
`index from ${oldVersionCollection} should be available; nodes: ${tojson(nodes)}`);
}
// Create a new collection.
assert.commandWorked(testDB.createCollection(version.testCollection));
// Insert a document into the new collection.
assert.writeOK(testDB[version.testCollection].insert({a: 1}));
assert.eq(
1,
testDB[version.testCollection].count(),
`mongo should have inserted 1 document into collection ${version.testCollection}; ` +
'nodes: ' + tojson(nodes));
// Create an index on the new collection.
assert.commandWorked(testDB[version.testCollection].createIndex({a: 1}));
}
// Stop the replica set.
rst.stopSet();
})();
|