@@ -34,37 +34,14 @@ const {
34
34
replicatedLogUpdatePlanParticipantsFlags,
35
35
replicatedLogSetPlanTerm,
36
36
createTermSpecification,
37
- dbservers
37
+ replicatedLogIsReady,
38
+ dbservers,
39
+ nextUniqueLogId,
40
+ registerAgencyTestBegin, registerAgencyTestEnd
38
41
} = require ( "@arangodb/testutils/replicated-logs-helper" ) ;
39
42
40
43
const database = 'ReplLogsMaintenanceTest' ;
41
44
42
- const replicatedLogIsReady = function ( logId , term , participants , leader ) {
43
- return function ( ) {
44
- let { current} = readReplicatedLogAgency ( database , logId ) ;
45
- if ( current === undefined ) {
46
- return Error ( "current not yet defined" ) ;
47
- }
48
-
49
- for ( const srv of participants ) {
50
- if ( ! current . localStatus || ! current . localStatus [ srv ] ) {
51
- return Error ( `Participant ${ srv } has not yet reported to current.` ) ;
52
- }
53
- if ( current . localStatus [ srv ] . term < term ) {
54
- return Error ( `Participant ${ srv } has not yet acknowledged the current term; ` +
55
- `found = ${ current . localStatus [ srv ] . term } , expected = ${ term } .` ) ;
56
- }
57
- }
58
-
59
- if ( leader !== undefined ) {
60
- if ( ! current . leader || current . leader . term < term || current . leader . serverId !== leader ) {
61
- return Error ( "Leader has not yet established its term" ) ;
62
- }
63
- }
64
- return true ;
65
- } ;
66
- } ;
67
-
68
45
const replicatedLogParticipantGeneration = function ( logId , generation ) {
69
46
return function ( ) {
70
47
let { current} = readReplicatedLogAgency ( database , logId ) ;
@@ -74,9 +51,14 @@ const replicatedLogParticipantGeneration = function (logId, generation) {
74
51
if ( ! current . leader ) {
75
52
return Error ( "Leader has not yet established its term" ) ;
76
53
}
77
- if ( ! current . leader . committedParticipantsConfig || current . leader . committedParticipantsConfig . generation < generation ) {
78
- return Error ( "Leader has not yet acked new generation" ) ;
54
+ if ( ! current . leader . committedParticipantsConfig ) {
55
+ return Error ( "Leader has not yet committed any participants config" ) ;
56
+ }
57
+ if ( current . leader . committedParticipantsConfig . generation < generation ) {
58
+ return Error ( "Leader has not yet acked new generation; "
59
+ + `found ${ current . leader . committedParticipantsConfig . generation } , expected = ${ generation } ` ) ;
79
60
}
61
+
80
62
return true ;
81
63
} ;
82
64
} ;
@@ -119,13 +101,6 @@ const replicatedLogParticipantsFlag = function (logId, flags, generation = undef
119
101
120
102
const replicatedLogSuite = function ( ) {
121
103
122
- const nextLogId = ( function ( ) {
123
- let logId = 100 ;
124
- return function ( ) {
125
- return logId ++ ;
126
- } ;
127
- } ( ) ) ;
128
-
129
104
const targetConfig = {
130
105
writeConcern : 2 ,
131
106
softWriteConcern : 2 ,
@@ -150,15 +125,17 @@ const replicatedLogSuite = function () {
150
125
if ( ! databaseExisted ) {
151
126
db . _dropDatabase ( database ) ;
152
127
}
153
- }
128
+ } ,
154
129
} ;
155
130
} ( ) ) ;
156
131
157
132
return {
158
133
setUpAll, tearDownAll,
134
+ setUp : registerAgencyTestBegin ,
135
+ tearDown : registerAgencyTestEnd ,
159
136
160
137
testCreateReplicatedLog : function ( ) {
161
- const logId = nextLogId ( ) ;
138
+ const logId = nextUniqueLogId ( ) ;
162
139
const servers = _ . sampleSize ( dbservers , targetConfig . replicationFactor ) ;
163
140
const leader = servers [ 0 ] ;
164
141
const term = 1 ;
@@ -169,13 +146,13 @@ const replicatedLogSuite = function () {
169
146
} ) ;
170
147
171
148
// wait for all servers to have reported in current
172
- waitFor ( replicatedLogIsReady ( logId , term , servers , leader ) ) ;
149
+ waitFor ( replicatedLogIsReady ( database , logId , term , servers , leader ) ) ;
173
150
174
151
replicatedLogDeletePlan ( database , logId ) ;
175
152
} ,
176
153
177
154
testCreateReplicatedLogWithoutLeader : function ( ) {
178
- const logId = nextLogId ( ) ;
155
+ const logId = nextUniqueLogId ( ) ;
179
156
const servers = _ . sampleSize ( dbservers , targetConfig . replicationFactor ) ;
180
157
const term = 1 ;
181
158
replicatedLogSetPlan ( database , logId , {
@@ -185,13 +162,13 @@ const replicatedLogSuite = function () {
185
162
} ) ;
186
163
187
164
// wait for all servers to have reported in current
188
- waitFor ( replicatedLogIsReady ( logId , term , servers ) ) ;
165
+ waitFor ( replicatedLogIsReady ( database , logId , term , servers ) ) ;
189
166
190
167
replicatedLogDeletePlan ( database , logId ) ;
191
168
} ,
192
169
193
170
testAddParticipantFlag : function ( ) {
194
- const logId = nextLogId ( ) ;
171
+ const logId = nextUniqueLogId ( ) ;
195
172
const servers = _ . sampleSize ( dbservers , targetConfig . replicationFactor ) ;
196
173
const leader = servers [ 0 ] ;
197
174
const term = 1 ;
@@ -202,7 +179,7 @@ const replicatedLogSuite = function () {
202
179
} ) ;
203
180
204
181
// wait for all servers to have reported in current
205
- waitFor ( replicatedLogIsReady ( logId , term , servers , leader ) ) ;
182
+ waitFor ( replicatedLogIsReady ( database , logId , term , servers , leader ) ) ;
206
183
207
184
// now update the excluded flag for one participant
208
185
const follower = servers [ 1 ] ;
@@ -217,7 +194,7 @@ const replicatedLogSuite = function () {
217
194
} ,
218
195
219
196
testUpdateTermInPlanLog : function ( ) {
220
- const logId = nextLogId ( ) ;
197
+ const logId = nextUniqueLogId ( ) ;
221
198
const servers = _ . sampleSize ( dbservers , targetConfig . replicationFactor ) ;
222
199
const leader = servers [ 0 ] ;
223
200
const term = 1 ;
@@ -228,16 +205,16 @@ const replicatedLogSuite = function () {
228
205
} ) ;
229
206
230
207
// wait for all servers to have reported in current
231
- waitFor ( replicatedLogIsReady ( logId , term , servers , leader ) ) ;
208
+ waitFor ( replicatedLogIsReady ( database , logId , term , servers , leader ) ) ;
232
209
replicatedLogSetPlanTerm ( database , logId , createTermSpecification ( term + 1 , servers , targetConfig , leader ) ) ;
233
210
234
211
// wait again for all servers to have acked term
235
- waitFor ( replicatedLogIsReady ( logId , term + 1 , servers , leader ) ) ;
212
+ waitFor ( replicatedLogIsReady ( database , logId , term + 1 , servers , leader ) ) ;
236
213
replicatedLogDeletePlan ( database , logId ) ;
237
214
} ,
238
215
239
216
testUpdateTermInPlanLogWithNewLeader : function ( ) {
240
- const logId = nextLogId ( ) ;
217
+ const logId = nextUniqueLogId ( ) ;
241
218
const servers = _ . sampleSize ( dbservers , targetConfig . replicationFactor ) ;
242
219
const leader = servers [ 0 ] ;
243
220
const term = 1 ;
@@ -248,16 +225,16 @@ const replicatedLogSuite = function () {
248
225
} ) ;
249
226
250
227
// wait for all servers to have reported in current
251
- waitFor ( replicatedLogIsReady ( logId , term , servers ) ) ;
228
+ waitFor ( replicatedLogIsReady ( database , logId , term , servers ) ) ;
252
229
// wait again for all servers to have acked term
253
230
const otherLeader = servers [ 1 ] ;
254
231
replicatedLogSetPlanTerm ( database , logId , createTermSpecification ( term + 1 , servers , targetConfig , otherLeader ) ) ;
255
- waitFor ( replicatedLogIsReady ( logId , term + 1 , servers , otherLeader ) ) ;
232
+ waitFor ( replicatedLogIsReady ( database , logId , term + 1 , servers , otherLeader ) ) ;
256
233
replicatedLogDeletePlan ( database , logId ) ;
257
234
} ,
258
235
259
236
testUpdateTermAddParticipant : function ( ) {
260
- const logId = nextLogId ( ) ;
237
+ const logId = nextUniqueLogId ( ) ;
261
238
const servers = _ . sampleSize ( dbservers , targetConfig . replicationFactor ) ;
262
239
const leader = servers [ 0 ] ;
263
240
const remaining = _ . difference ( dbservers , servers ) ;
@@ -269,16 +246,16 @@ const replicatedLogSuite = function () {
269
246
} ) ;
270
247
271
248
// wait for all servers to have reported in current
272
- waitFor ( replicatedLogIsReady ( logId , term , servers ) ) ;
249
+ waitFor ( replicatedLogIsReady ( database , logId , term , servers ) ) ;
273
250
// now rewrite the term with an additional participant
274
251
const newServers = [ ...servers , _ . sample ( remaining ) ] ;
275
252
replicatedLogSetPlanTerm ( database , logId , createTermSpecification ( term , newServers , targetConfig , leader ) ) ;
276
- waitFor ( replicatedLogIsReady ( logId , term , newServers , leader ) ) ;
253
+ waitFor ( replicatedLogIsReady ( database , logId , term , newServers , leader ) ) ;
277
254
replicatedLogDeletePlan ( database , logId ) ;
278
255
} ,
279
256
280
257
testUpdateTermRemoveParticipant : function ( ) {
281
- const logId = nextLogId ( ) ;
258
+ const logId = nextUniqueLogId ( ) ;
282
259
const servers = _ . sampleSize ( dbservers , targetConfig . replicationFactor ) ;
283
260
const remaining = _ . difference ( dbservers , servers ) ;
284
261
const toBeRemoved = _ . sample ( remaining ) ;
@@ -292,7 +269,7 @@ const replicatedLogSuite = function () {
292
269
} ) ;
293
270
294
271
// wait for all servers to have reported in current
295
- waitFor ( replicatedLogIsReady ( logId , term , newServers ) ) ;
272
+ waitFor ( replicatedLogIsReady ( database , logId , term , newServers ) ) ;
296
273
// now rewrite the term with an additional participant
297
274
replicatedLogSetPlanTerm ( database , logId , createTermSpecification ( term , servers , targetConfig , leader ) ) ;
298
275
// TODO waitFor(replicatedLogParticipantsFlag(logId, {[toBeRemoved]: null})); -- doesn't work yet
0 commit comments