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
|
'use strict';
/**
* rename_collection_dbname_chain.js
*
* Creates a collection and then repeatedly executes the renameCollection
* command against it, specifying a different database name in the namespace.
* The previous "to" namespace is used as the next "from" namespace.
*/
load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropDatabases
var $config = (function() {
var data = {
// Use the workload name as a prefix for the collection name,
// since the workload name is assumed to be unique.
prefix: 'rename_collection_dbname_chain'
};
var states = (function() {
function uniqueDBName(prefix, tid, num) {
return prefix + tid + '_' + num;
}
function init(db, collName) {
this.fromDBName = uniqueDBName(this.prefix, this.tid, 0);
this.num = 1;
var fromDB = db.getSiblingDB(this.fromDBName);
assertAlways.commandWorked(fromDB.createCollection(collName));
}
function rename(db, collName) {
var toDBName = uniqueDBName(this.prefix, this.tid, this.num++);
var renameCommand = {
renameCollection: this.fromDBName + '.' + collName,
to: toDBName + '.' + collName,
dropTarget: false
};
assertAlways.commandWorked(db.adminCommand(renameCommand));
// Remove any files associated with the "from" namespace
// to avoid having too many files open
var res = db.getSiblingDB(this.fromDBName).dropDatabase();
assertAlways.commandWorked(res);
assertAlways.eq(this.fromDBName, res.dropped);
this.fromDBName = toDBName;
}
return {
init: init,
rename: rename
};
})();
var transitions = {
init: { rename: 1 },
rename: { rename: 1 }
};
function teardown(db, collName, cluster) {
var pattern = new RegExp('^' + this.prefix + '\\d+_\\d+$');
dropDatabases(db, pattern);
}
return {
threadCount: 10,
iterations: 20,
data: data,
states: states,
transitions: transitions,
teardown: teardown
};
})();
|