@@ -37,7 +37,6 @@ if (getOptions === true) {
37
37
const db = require ( '@arangodb' ) . db ;
38
38
const jsunity = require ( 'jsunity' ) ;
39
39
const getMetric = require ( '@arangodb/test-helper' ) . getMetricSingle ;
40
- const time = require ( 'internal' ) . time ;
41
40
42
41
const cn = 'UnitTestsCollection' ;
43
42
const n = 5000 ;
@@ -46,6 +45,31 @@ const waitForPendingRefills = () => {
46
45
// wait for pending refill operations to have finished, using an informal API
47
46
arango . POST ( '/_api/index/sync-caches' , { } ) ;
48
47
} ;
48
+
49
+ const runWithRetry = ( cb ) => {
50
+ let tries = 0 ;
51
+ while ( true ) {
52
+ try {
53
+ cb ( ) ;
54
+ // return upon first successful execution of the callback function
55
+ return ;
56
+ } catch ( err ) {
57
+ // if it fails, check how many failures we got. fail only if we failed
58
+ // 3 times in a row
59
+ if ( tries ++ === 3 ) {
60
+ throw err ;
61
+ }
62
+ // attempt failed. this can happen because inserting data into
63
+ // the cache can fail under the following circumstances:
64
+ // - cache global budget exceeded
65
+ // - cache hash table migration in progress
66
+
67
+ // start over...
68
+ db [ cn ] . truncate ( ) ;
69
+ require ( "internal" ) . sleep ( 2 ) ;
70
+ }
71
+ }
72
+ } ;
49
73
50
74
function AutoRefillIndexCachesEdge ( ) {
51
75
'use strict' ;
@@ -142,12 +166,14 @@ function AutoRefillIndexCachesEdge() {
142
166
} ,
143
167
144
168
testInsertEdgeEnabled : function ( ) {
145
- const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
146
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
147
- const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
148
-
149
- assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
150
- runCheck ( true ) ;
169
+ runWithRetry ( ( ) => {
170
+ const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
171
+ db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
172
+ const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
173
+
174
+ assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
175
+ runCheck ( true ) ;
176
+ } ) ;
151
177
} ,
152
178
153
179
testUpdateEdgeDefault : function ( ) {
@@ -177,14 +203,16 @@ function AutoRefillIndexCachesEdge() {
177
203
} ,
178
204
179
205
testUpdateEdgeEnabled : function ( ) {
180
- insertInitialEdges ( ) ;
206
+ runWithRetry ( ( ) => {
207
+ insertInitialEdges ( ) ;
181
208
182
- const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
183
- db . _query ( `FOR doc IN ${ cn } UPDATE doc WITH {value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
184
- const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
209
+ const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
210
+ db . _query ( `FOR doc IN ${ cn } UPDATE doc WITH {value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
211
+ const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
185
212
186
- assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
187
- runCheck ( true ) ;
213
+ assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
214
+ runCheck ( true ) ;
215
+ } ) ;
188
216
} ,
189
217
190
218
testReplaceEdgeDefault : function ( ) {
@@ -214,14 +242,16 @@ function AutoRefillIndexCachesEdge() {
214
242
} ,
215
243
216
244
testReplaceEdgeEnabled : function ( ) {
217
- insertInitialEdges ( ) ;
245
+ runWithRetry ( ( ) => {
246
+ insertInitialEdges ( ) ;
218
247
219
- const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
220
- db . _query ( `FOR doc IN ${ cn } REPLACE doc WITH {_from: doc._from, _to: doc._to, value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
221
- const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
248
+ const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
249
+ db . _query ( `FOR doc IN ${ cn } REPLACE doc WITH {_from: doc._from, _to: doc._to, value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
250
+ const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
222
251
223
- assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
224
- runCheck ( true ) ;
252
+ assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
253
+ runCheck ( true ) ;
254
+ } ) ;
225
255
} ,
226
256
227
257
testRemoveEdgeDefault : function ( ) {
@@ -251,14 +281,16 @@ function AutoRefillIndexCachesEdge() {
251
281
} ,
252
282
253
283
testRemoveEdgeEnabled : function ( ) {
254
- insertInitialEdges ( ) ;
284
+ runWithRetry ( ( ) => {
285
+ insertInitialEdges ( ) ;
255
286
256
- const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
257
- db . _query ( `FOR i IN 0..${ n / 2 - 1 } REMOVE CONCAT('test', i) INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
258
- const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
287
+ const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
288
+ db . _query ( `FOR i IN 0..${ n / 2 - 1 } REMOVE CONCAT('test', i) INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
289
+ const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
259
290
260
- assertTrue ( newValue - oldValue >= n / 2 , { oldValue, newValue } ) ;
261
- runRemoveCheck ( true ) ;
291
+ assertTrue ( newValue - oldValue >= n / 2 , { oldValue, newValue } ) ;
292
+ runRemoveCheck ( true ) ;
293
+ } ) ;
262
294
} ,
263
295
264
296
} ;
@@ -327,13 +359,15 @@ function AutoRefillIndexCachesVPack() {
327
359
} ,
328
360
329
361
testInsertVPackEnabled : function ( ) {
330
- const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
331
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {value: i} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
332
- const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
333
-
334
- assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
335
- waitForPendingRefills ( ) ;
336
- runCheck ( 0 , true ) ;
362
+ runWithRetry ( ( ) => {
363
+ const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
364
+ db . _query ( `FOR i IN 0..${ n - 1 } INSERT {value: i} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
365
+ const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
366
+
367
+ assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
368
+ waitForPendingRefills ( ) ;
369
+ runCheck ( 0 , true ) ;
370
+ } ) ;
337
371
} ,
338
372
339
373
testUpdateVPackDefault : function ( ) {
@@ -363,14 +397,16 @@ function AutoRefillIndexCachesVPack() {
363
397
} ,
364
398
365
399
testUpdateVPackEnabled : function ( ) {
366
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {value: i} INTO ${ cn } ` ) ;
367
- const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
368
- db . _query ( `FOR doc IN ${ cn } UPDATE doc WITH {value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
369
- const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
370
-
371
- assertTrue ( newValue - oldValue >= n , { oldValue, newValue } <
10000
span class=pl-kos>);
372
- waitForPendingRefills ( ) ;
373
- runCheck ( 1 , true ) ;
400
+ runWithRetry ( ( ) => {
401
+ db . _query ( `FOR i IN 0..${ n - 1 } INSERT {value: i} INTO ${ cn } ` ) ;
402
+ const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
403
+ db . _query ( `FOR doc IN ${ cn } UPDATE doc WITH {value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
404
+ const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
405
+
406
+ assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
407
+ waitForPendingRefills ( ) ;
408
+ runCheck ( 1 , true ) ;
409
+ } ) ;
374
410
} ,
375
411
376
412
testReplaceVPackDefault : function ( ) {
@@ -398,14 +434,16 @@ function AutoRefillIndexCachesVPack() {
398
434
} ,
399
435
400
436
testReplaceVPackEnabled : function ( ) {
401
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {value: i} INTO ${ cn } ` ) ;
402
- const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
403
- db . _query ( `FOR doc IN ${ cn } REPLACE doc WITH {value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
404
- const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
405
-
406
- assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
407
- waitForPendingRefills ( ) ;
408
- runCheck ( 1 , true ) ;
437
+ runWithRetry ( ( ) => {
438
+ db . _query ( `FOR i IN 0..${ n - 1 } INSERT {value: i} INTO ${ cn } ` ) ;
439
+ const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
440
+ db . _query ( `FOR doc IN ${ cn } REPLACE doc WITH {value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
441
+ const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
442
+
443
+ assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
444
+ waitForPendingRefills ( ) ;
445
+ runCheck ( 1 , true ) ;
446
+ } ) ;
409
447
} ,
410
448
411
449
testRemoveVPackDefault : function ( ) {
@@ -433,14 +471,16 @@ function AutoRefillIndexCachesVPack() {
433
471
} ,
434
472
435
473
testRemoveVPackEnabled : function ( ) {
436
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_key: CONCAT('test', i), value: i} INTO ${ cn } ` ) ;
437
- const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
438
- db . _query ( `FOR i IN 0..${ n / 2 - 1 } REMOVE CONCAT('test', i) INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
439
- const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
440
-
441
- assertTrue ( newValue - oldValue >= n / 2 , { oldValue, newValue } ) ;
442
- waitForPendingRefills ( ) ;
443
- runRemoveCheck ( true ) ;
474
+ runWithRetry ( ( ) => {
475
+ db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_key: CONCAT('test', i), value: i} INTO ${ cn } ` ) ;
476
+ const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
477
+ db . _query ( `FOR i IN 0..${ n / 2 - 1 } REMOVE CONCAT('test', i) INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
478
+ const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
479
+
480
+ assertTrue ( newValue - oldValue >= n / 2 , { oldValue, newValue } ) ;
481
+ waitForPendingRefills ( ) ;
482
+ runRemoveCheck ( true ) ;
483
+ } ) ;
444
484
} ,
445
485
446
486
} ;
0 commit comments