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
|
'use strict';
/**
* sharded_moveChunk_drop_shard_key_index.js
*
* Tests that dropping the shard key index while migrating a chunk doesn't cause the shard to abort.
*
* This workload was designed to reproduce SERVER-24994.
*
* @tags: [requires_sharding, assumes_balancer_off]
*/
load("jstests/concurrency/fsm_workload_helpers/assert_handle_fail_in_transaction.js");
var $config = (function() {
var data = {numSplitPoints: 100, shardKey: {key: 1}};
var states = {
init: function init(db, collName) {
// No-op
},
moveChunk: function moveChunk(db, collName) {
var configDB = db.getSiblingDB('config');
var shards = configDB.shards.aggregate([{$sample: {size: 1}}]).toArray();
assertAlways.eq(1, shards.length, tojson(shards));
var shardName = shards[0]._id;
var chunkBoundary = Random.randInt(this.numSplitPoints);
// We don't assert that the command succeeded when migrating a chunk because it's
// possible another thread has already started migrating a chunk. (see exception below)
try {
db.adminCommand({
moveChunk: db[collName].getFullName(),
find: {key: chunkBoundary},
to: shardName,
_waitForDelete: true,
});
} catch (ex) {
// SERVER-42781: if the runInsideTransaction TestOption is true
// then runCommandCheckForOperationNotSupportedInTransaction (in
// check_for_operation_not_supported_in_transaction.js) will assert that the command
// worked. We ignore the InvalidOptions error below since we can get this error due
// to concurrent moveChunks.
if (ex.code == ErrorCodes.InvalidOptions &&
ex.errmsg.valueOf() === "Destination shard cannot be the same as source") {
print(`ignored InvalidOptions exception: ${tojson(ex)}`);
} else {
throw ex;
}
}
},
dropIndex: function dropIndex(db, collName) {
// We don't assert that the command succeeded when dropping an index because it's
// possible another thread has already dropped this index.
db[collName].dropIndex(this.shardKey);
// Re-create the index that was dropped.
assertWorkedHandleTxnErrors(db[collName].createIndex(this.shardKey),
ErrorCodes.IndexBuildAlreadyInProgress);
}
};
var transitions = {
init: {moveChunk: 0.5, dropIndex: 0.5},
moveChunk: {moveChunk: 0.5, dropIndex: 0.5},
dropIndex: {moveChunk: 0.5, dropIndex: 0.5}
};
function setup(db, collName, cluster) {
var bulk = db[collName].initializeUnorderedBulkOp();
for (var i = 0; i < this.numSplitPoints; ++i) {
bulk.insert({key: i});
}
var res = bulk.execute();
assertAlways.commandWorked(res);
assertAlways.eq(this.numSplitPoints, res.nInserted, tojson(res));
for (i = 0; i < this.numSplitPoints; ++i) {
assertWhenOwnColl.commandWorked(
db.adminCommand({split: db[collName].getFullName(), middle: {key: i}}));
}
}
return {
threadCount: 10,
iterations: 100,
data: data,
states: states,
transitions: transitions,
setup: setup,
};
})();
|