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
|
'use strict';
/**
* Each thread uses its own LSID and performs `findAndModify`s with retries on documents while the
* `storeFindAndModifyImagesInSideCollection` server parameter gets flipped.
*
* @tags: [requires_replication, requires_non_retryable_commands, uses_transactions];
*/
var $config = (function() {
var data = {
numDocs: 100,
};
var states = (function() {
function init(db, collName) {
this._lastTxnId = 0;
this._lsid = UUID();
}
function findAndModifyUpsert(db, collName) {
// `auto_retry_transactions` is not compatible with explicitly testing retryable writes.
// This avoids issues regarding the multi_stmt tasks.
fsm.forceRunningOutsideTransaction(this);
this._lastTxnId += 1;
this._lastCmd = {
findandmodify: collName,
lsid: {id: this._lsid},
txnNumber: NumberLong(this._lastTxnId),
stmtId: NumberInt(1),
query: {_id: Math.round(Math.random() * this.numDocs)},
new: Math.random() > 0.5,
upsert: true,
update: {$inc: {counter: 1}},
};
this._lastResponse = assert.commandWorked(db.runCommand(this._lastCmd));
}
function findAndModifyUpdate(db, collName) {
// `auto_retry_transactions` is not compatible with explicitly testing retryable writes.
// This avoids issues regarding the multi_stmt tasks.
fsm.forceRunningOutsideTransaction(this);
this._lastTxnId += 1;
this._lastCmd = {
findandmodify: collName,
lsid: {id: this._lsid},
txnNumber: NumberLong(this._lastTxnId),
stmtId: NumberInt(1),
query: {_id: Math.round(Math.random() * this.numDocs)},
new: Math.random() > 0.5,
upsert: false,
update: {$inc: {counter: 1}},
};
this._lastResponse = assert.commandWorked(db.runCommand(this._lastCmd));
}
function findAndModifyDelete(db, collName) {
// `auto_retry_transactions` is not compatible with explicitly testing retryable writes.
// This avoids issues regarding the multi_stmt tasks.
fsm.forceRunningOutsideTransaction(this);
this._lastTxnId += 1;
this._lastCmd = {
findandmodify: collName,
lsid: {id: this._lsid},
txnNumber: NumberLong(this._lastTxnId),
stmtId: NumberInt(1),
query: {_id: Math.round(Math.random() * this.numDocs)},
// Deletes may not ask for the postImage
new: false,
remove: true,
};
this._lastResponse = assert.commandWorked(db.runCommand(this._lastCmd));
}
function findAndModifyRetry(db, collName) {
// `auto_retry_transactions` is not compatible with explicitly testing retryable writes.
// This avoids issues regarding the multi_stmt tasks.
fsm.forceRunningOutsideTransaction(this);
assert(this._lastCmd);
assert(this._lastResponse);
let response = assert.commandWorked(db.runCommand(this._lastCmd));
let debugMsg = {
"TID": this.tid,
"LastCmd": this._lastCmd,
"LastResponse": this._lastResponse,
"Response": response
};
assert.eq(this._lastResponse.hasOwnProperty("lastErrorObject"),
response.hasOwnProperty("lastErrorObject"),
debugMsg);
if (response.hasOwnProperty("lastErrorObject") &&
// If the original command affected `n=1` document, all retries must return
// identical results. If an original command receives `n=0`, then a retry may find a
// match and return `n=1`. Only compare `lastErrorObject` and `value` when retries
// must be identical.
this._lastResponse["lastErrorObject"].n === 1) {
assert.eq(
this._lastResponse["lastErrorObject"], response["lastErrorObject"], debugMsg);
}
assert.eq(this._lastResponse.hasOwnProperty("value"),
response.hasOwnProperty("value"),
debugMsg);
if (response.hasOwnProperty("value") && this._lastResponse["lastErrorObject"].n === 1) {
assert.eq(this._lastResponse["value"], response["value"], debugMsg);
}
// Have all workers participate in creating some chaos.
assert.commandWorked(db.adminCommand({
setParameter: 1,
storeFindAndModifyImagesInSideCollection: Math.random() > 0.5,
}));
}
return {
init: init,
findAndModifyUpsert: findAndModifyUpsert,
findAndModifyUpdate: findAndModifyUpdate,
findAndModifyDelete: findAndModifyDelete,
findAndModifyRetry: findAndModifyRetry
};
})();
var transitions = {
init: {findAndModifyUpsert: 1.0},
findAndModifyUpsert: {
findAndModifyRetry: 3.0,
findAndModifyUpsert: 1.0,
findAndModifyUpdate: 1.0,
findAndModifyDelete: 1.0
},
findAndModifyUpdate: {
findAndModifyRetry: 3.0,
findAndModifyUpsert: 1.0,
findAndModifyUpdate: 1.0,
findAndModifyDelete: 1.0
},
findAndModifyDelete: {
findAndModifyRetry: 3.0,
findAndModifyUpsert: 1.0,
findAndModifyUpdate: 1.0,
findAndModifyDelete: 1.0
},
findAndModifyRetry: {
findAndModifyRetry: 1.0,
findAndModifyUpsert: 1.0,
findAndModifyUpdate: 1.0,
findAndModifyDelete: 1.0
},
};
return {
threadCount: 10,
iterations: 100,
data: data,
states: states,
transitions: transitions,
setup: function() {},
};
})();
|