@@ -42,15 +42,20 @@ const time = require('internal').time;
42
42
const cn = 'UnitTestsCollection' ;
43
43
const n = 5000 ;
44
44
45
- const waitForMetrics = ( ) => {
46
- // wait for metrics to settle , using an informal API
45
+ const waitForPendingRefills = ( ) => {
46
+ // wait for pending refill operations to have finished , using an informal API
47
47
arango . POST ( '/_api/index/sync-caches' , { } ) ;
48
48
} ;
49
49
50
50
function AutoRefillIndexCachesEdge ( ) {
51
51
'use strict' ;
52
52
53
53
let runCheck = ( expectHits ) => {
54
+ // need to wait here for all pending index cache refill ops to finish.
55
+ // if we wouldn't wait here, there would be a race between the refill background
56
+ // thread and the query executed here.
57
+ waitForPendingRefills ( ) ;
58
+
54
59
let crsr = db . _query ( `FOR i IN 0..${ n - 1 } FOR doc IN ${ cn } FILTER doc._from == CONCAT('v/test', i) RETURN doc._from` ) ;
55
60
let res = crsr . toArray ( ) ;
56
61
assertEqual ( n , res . length ) ;
@@ -79,6 +84,11 @@ function AutoRefillIndexCachesEdge() {
79
84
} ;
80
85
81
86
let runRemoveCheck = ( expectHits ) => {
87
+ // need to wait here for all pending index cache refill ops to finish.
88
+ // if we wouldn't wait here, there would be a race between the refill background
89
+ // thread and the query executed here.
90
+ waitForPendingRefills ( ) ;
91
+
82
92
let crsr = db . _query ( `FOR i IN 0..${ n - 1 } FOR doc IN ${ cn } FILTER doc._from == CONCAT('v/test', i) RETURN doc._from` ) ;
83
93
let res = crsr . toArray ( ) ;
84
94
assertTrue ( res . length > 0 , res . length ) ;
@@ -95,6 +105,10 @@ function AutoRefillIndexCachesEdge() {
95
105
assertTrue ( stats . cacheHits > 0 , stats ) ;
96
106
}
97
107
} ;
108
+
109
+ let insertInitialEdges = ( ) => {
110
+ db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_key: CONCAT('test', i), _from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } OPTIONS { refillIndexCaches: false }` ) ;
111
+ } ;
98
112
99
113
return {
100
114
setUp : function ( ) {
@@ -133,12 +147,12 @@ function AutoRefillIndexCachesEdge() {
133
147
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
134
148
135
149
assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
136
- waitForMetrics ( ) ;
137
150
runCheck ( true ) ;
138
151
} ,
139
152
140
153
testUpdateEdgeDefault : function ( ) {
141
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } ` ) ;
154
+ insertInitialEdges ( ) ;
155
+
142
156
const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
143
157
db . _query ( `FOR doc IN ${ cn } UPDATE doc WITH {value: doc.value + 1} INTO ${ cn } ` ) ;
144
158
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
@@ -150,7 +164,8 @@ function AutoRefillIndexCachesEdge() {
150
164
} ,
151
165
152
166
testUpdateEdgeDisabled : function ( ) {
153
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } ` ) ;
167
+ insertInitialEdges ( ) ;
168
+
154
169
const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
155
170
db . _query ( `FOR doc IN ${ cn } UPDATE doc WITH {value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: false }` ) ;
156
171
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
@@ -162,18 +177,19 @@ function AutoRefillIndexCachesEdge() {
162
177
} ,
163
178
164
179
testUpdateEdgeEnabled : function ( ) {
165
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } ` ) ;
180
+ insertInitialEdges ( ) ;
181
+
166
182
const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
167
183
db . _query ( `FOR doc IN ${ cn } UPDATE doc WITH {value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
168
184
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
169
185
170
186
assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
171
- waitForMetrics (
B41A
) ;
172
187
runCheck ( true ) ;
173
188
} ,
174
189
175
190
testReplaceEdgeDefault : function ( ) {
176
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } ` ) ;
191
+ insertInitialEdges ( ) ;
192
+
177
193
const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
178
194
db . _query ( `FOR doc IN ${ cn } REPLACE doc WITH {_from: doc._from, _to: doc._to, value: doc.value + 1} INTO ${ cn } ` ) ;
179
195
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
@@ -185,7 +201,8 @@ function AutoRefillIndexCachesEdge() {
185
201
} ,
186
202
187
203
testReplaceEdgeDisabled : function ( ) {
188
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } ` ) ;
204
+ insertInitialEdges ( ) ;
205
+
189
206
const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
190
207
db . _query ( `FOR doc IN ${ cn } REPLACE doc WITH {_from: doc._from, _to: doc._to, value: doc.value + 1} INTO ${ cn } OPTIONS { refillIndexCaches: false }` ) ;
191
208
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
@@ -197,18 +214,19 @@ function AutoRefillIndexCachesEdge() {
197
214
} ,
198
215
199
216
testReplaceEdgeEnabled : function ( ) {
200
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } ` ) ;
217
+ insertInitialEdges ( ) ;
218
+
201
219
const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
202
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 }` ) ;
203
221
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
204
222
205
223
assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
206
- waitForMetrics ( ) ;
207
224
runCheck ( true ) ;
208
225
} ,
209
226
210
227
testRemoveEdgeDefault : function ( ) {
211
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_key: CONCAT('test', i), _from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } ` ) ;
228
+ insertInitialEdges ( ) ;
229
+
212
230
const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
213
231
db . _query ( `FOR i IN 0..${ n / 2 - 1 } REMOVE CONCAT('test', i) INTO ${ cn } ` ) ;
214
232
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
@@ -220,7 +238,8 @@ function AutoRefillIndexCachesEdge() {
220
238
} ,
221
239
222
240
testRemoveEdgeDisabled : function ( ) {
223
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_key: CONCAT('test', i), _from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } ` ) ;
241
+ insertInitialEdges ( ) ;
242
+
224
243
const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
225
244
db . _query ( `FOR i IN 0..${ n / 2 - 1 } REMOVE CONCAT('test', i) INTO ${ cn } OPTIONS { refillIndexCaches: false }` ) ;
226
245
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
@@ -232,13 +251,13 @@ function AutoRefillIndexCachesEdge() {
232
251
} ,
233
252
234
253
testRemoveEdgeEnabled : function ( ) {
235
- db . _query ( `FOR i IN 0..${ n - 1 } INSERT {_key: CONCAT('test', i), _from: CONCAT('v/test', i), _to: CONCAT('v/test', (i % 25))} INTO ${ cn } ` ) ;
254
+ insertInitialEdges ( ) ;
255
+
236
256
const oldValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
237
257
db . _query ( `FOR i IN 0..${ n / 2 - 1 } REMOVE CONCAT('test', i) INTO ${ cn } OPTIONS { refillIndexCaches: true }` ) ;
238
258
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
239
259
240
260
assertTrue ( newValue - oldValue >= n / 2 , { oldValue, newValue } ) ;
241
- waitForMetrics ( ) ;
242
261
runRemoveCheck ( true ) ;
243
262
} ,
244
263
@@ -313,7 +332,7 @@ function AutoRefillIndexCachesVPack() {
313
332
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
314
333
315
334
assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
316
- waitForMetrics ( ) ;
335
+ waitForPendingRefills ( ) ;
317
336
runCheck ( 0 , true ) ;
318
337
} ,
319
338
@@ -326,7 +345,7 @@ function AutoRefillIndexCachesVPack() {
326
345
// 10 here because there may be background operations running that
327
346
// could affect the metrics
328
347
assertTrue ( newValue - oldValue <= 10 , { oldValue, newValue } ) ;
329
- waitForMetrics ( ) ;
348
+ waitForPendingRefills ( ) ;
330
349
runCheck ( 1 , false ) ;
331
350
} ,
332
351
@@ -339,7 +358,7 @@ function AutoRefillIndexCachesVPack() {
339
358
// 10 here because there may be background operations running that
340
359
// could affect the metrics
341
360
assertTrue ( newValue - oldValue <= 10 , { oldValue, newValue } ) ;
342
- waitForMetrics ( ) ;
361
+ waitForPendingRefills ( ) ;
343
362
runCheck ( 1 , false ) ;
344
363
} ,
345
364
@@ -350,7 +369,7 @@ function AutoRefillIndexCachesVPack() {
350
369
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
351
370
352
371
assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
353
- waitForMetrics ( ) ;
372
+ waitForPendingRefills ( ) ;
354
373
runCheck ( 1 , true ) ;
355
374
} ,
356
375
@@ -385,7 +404,7 @@ function AutoRefillIndexCachesVPack() {
385
404
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
386
405
387
406
assertTrue ( newValue - oldValue >= n , { oldValue, newValue } ) ;
388
- waitForMetrics ( ) ;
407
+ waitForPendingRefills ( ) ;
389
408
runCheck ( 1 , true ) ;
390
409
} ,
391
410
@@ -420,7 +439,7 @@ function AutoRefillIndexCachesVPack() {
420
439
const newValue = getMetric ( "rocksdb_cache_auto_refill_loaded_total" ) ;
421
440
422
441
assertTrue ( newValue - oldValue >= n / 2 , { oldValue, newValue } ) ;
423
- waitForMetrics ( ) ;
442
+ waitForPendingRefills ( ) ;
424
443
runRemoveCheck ( true ) ;
425
444
} ,
426
445
0 commit comments