@@ -97,22 +97,19 @@ getShard(): Gets a list shard needed to issue a VC. This will be called by
97
97
this._readActiveBlockAssignmentDocs(LMD): Reads all active BADs to enable
98
98
choosing an IAD.
99
99
100
- 1. While active BADs cache is not read :
100
+ 1. While index allocation active cache is not set :
101
101
1.1. Call _tryAddCapacity(LMD, target=1).
102
- 1.2. Read all active BADs.
103
- 1.2.1. If any BAD does not exist, CW create it.
104
- 1.2.2. If any BAD has an SL sequence number that is behind an LMD item,
105
- CW update it. If conflict, read the BAD.
106
- 1.2.3. If any BAD has an SL sequence number that is ahead of the
107
- LMD "active" set item, read the LMD and loop to 1.
108
- 1.3. If any BADs have fully assigned blocks of indexes:
109
- 1.3.1. Move BAD IDs to the "inactive" set; if all BADs are fully assigned,
102
+ 1.2. Read all active BADs into an index allocation cache, `cache`.
103
+ 1.3. If any BAD has an SL sequence number that is ahead of the
104
+ LMD "active" set item, read the LMD and loop to 1.
105
+ 1.4. If any BADs have fully assigned blocks of indexes:
106
+ 1.4.1. Move BAD IDs to the "inactive" set; if all BADs are fully assigned,
110
107
choose one to leave as active and update its SL ID and SL sequence number.
111
- 1.3 .2. CW update LMD.
112
- 1.3 .3. If conflict, read LMD and loop to 1.
113
- 1.3 .4. CW update active BAD, if one was updated.
114
- 1.3 .5. If conflict, read LMD and loop to 1.
115
- 1.4 . Set read BADs as the active cache.
108
+ 1.4 .2. CW update LMD.
109
+ 1.4 .3. If conflict, read LMD and loop to 1.
110
+ 1.4 .4. CW update active BAD, if one was updated.
111
+ 1.4 .5. If conflict, read LMD and loop to 1.
112
+ 1.5 . Set `cache` as the active cache.
116
113
117
114
this._selectShard(LMD, activeCache): Select an IAD to use for assigning
118
115
indexes:
@@ -262,37 +259,32 @@ export class ListManager {
262
259
// latest docs are used
263
260
const { documentStore : { edvClient} , statusListConfig} = this ;
264
261
265
- // 1. While active BADs cache not read :
262
+ // 1. While index allocation active cache is not set :
266
263
this . activeCache = null ;
267
264
while ( ! this . activeCache ) {
268
265
// FIXME: can `_tryAddCapacity` be moved after reading cache records?
269
266
// 1.1. Call _tryAddCapacity(LMD, target=1).
270
267
await this . _tryAddCapacity ( { target : 1 } ) ;
271
- // 1.2. Read all active BADs.
272
- // 1.2.1. If any BAD does not exist, CW create it.
273
- // 1.2.2. If any BAD has an SL sequence number that is behind an LMD item,
274
- // CW update it. If conflict, read the BAD.
268
+ // 1.2. Read all active BADs into an index allocation cache, `cache`.
275
269
const { blockAssignment} = this . lmDoc . content ;
276
- // FIXME: create `new IndexAllocatorCache()`
277
- let cacheRecords = await Promise . all ( blockAssignment . active . map (
278
- item => this . _readBlockAssignmentDoc ( { item} ) ) ) ;
279
- // 1.2.3. If any BAD has an SL sequence number that is ahead of the
270
+ const cache = new IndexAllocationCache ( { edvClient, statusListConfig} ) ;
271
+ await cache . populate ( { items : blockAssignment . active } ) ;
272
+ // 1.3. If any BAD has an SL sequence number that is ahead of the
280
273
// LMD "active" set item, read the LMD and loop to 1.
281
- if ( cacheRecords . some ( ( { blockAssignmentDoc : { content} , item} ) =>
282
- content . slSequence > item . slSequence ) ) {
274
+ if ( cache . outOfSync ( ) ) {
283
275
this . lmDoc = await edvClient . get ( { id : this . lmDoc . id } ) ;
284
276
continue ;
285
277
}
286
278
287
279
// FIXME: can this be moved to `tryAddCapacity()` such that it will only
288
280
// execute when another BAD is required?
289
281
290
- // 1.3 . If any BADs have fully assigned blocks of indexes:
291
- const fullyAssigned = cacheRecords . filter (
282
+ // 1.4 . If any BADs have fully assigned blocks of indexes:
283
+ const fullyAssigned = cache . records . filter (
292
284
( { blockAssignmentDoc : { content} } ) =>
293
285
content . assignedBlockCount === content . blockCount ) ;
294
286
if ( fullyAssigned . length > 0 ) {
295
- // 1.3 .1. Move BAD IDs to the "inactive" set; if all BADs are fully
287
+ // 1.4 .1. Move BAD IDs to the "inactive" set; if all BADs are fully
296
288
// assigned, choose one to leave as active and update its SL ID and
297
289
// SL sequence number.
298
290
const items = fullyAssigned . map ( ( { item} ) => item ) ;
@@ -304,7 +296,8 @@ export class ListManager {
304
296
if ( blockAssignment . active . length > 0 ) {
305
297
// "active" items remain, so we can filter cache records by those
306
298
// items with remaining blocks to be assigned and get >= 1 result
307
- cacheRecords = cacheRecords . filter (
299
+ // FIXME: do internally
300
+ cache . records = cache . records . filter (
308
301
( { blockAssignmentDoc : { content} } ) =>
309
302
content . assignedBlockCount < content . blockCount ) ;
310
303
} else {
@@ -322,7 +315,7 @@ export class ListManager {
322
315
blockAssignment . inactive = blockAssignment . inactive . filter (
323
316
item => item !== toUpdate . item ) ;
324
317
blockAssignment . active = [ toUpdate . item ] ;
325
- cacheRecords = [ toUpdate ] ;
318
+ cache . records = [ toUpdate ] ;
326
319
// FIXME: determine how SLC IDs will be stored
327
320
// toUpdate.item.slcIds = slcIds;
328
321
toUpdate . item . statusListCredential = slcIds [ 0 ] . id ;
@@ -335,7 +328,7 @@ export class ListManager {
335
328
content, slSequence : toUpdate . item . slSequence , statusListConfig
336
329
} ) ;
337
330
}
338
- // 1.3 .2. CW update LMD.
331
+ // 1.4 .2. CW update LMD.
339
332
try {
340
333
this . lmDoc = await edvClient . update ( { doc : this . lmDoc } ) ;
341
334
} catch ( e ) {
@@ -346,7 +339,7 @@ export class ListManager {
346
339
this . lmDoc = await edvClient . get ( { id : this . lmDoc . id } ) ;
347
340
continue ;
348
341
}
349
- // 1.3 .4. CW update active BAD, if one was updated.
342
+ // 1.4 .4. CW update active BAD, if one was updated.
350
343
if ( toUpdate ) {
351
344
/* Note: If `continue` were just called here instead, it would work
352
345
properly, but be slower because the active items all have to be
@@ -361,17 +354,14 @@ export class ListManager {
361
354
if ( e . name !== 'InvalidStateError' ) {
362
355
throw e ;
363
356
}
364
- // 1.3 .5. If conflict, read LMD and loop to 1.
357
+ // 1.4 .5. If conflict, read LMD and loop to 1.
365
358
this . lmDoc = await edvClient . get ( { id : this . lmDoc . id } ) ;
366
359
continue ;
367
360
}
368
361
}
369
362
}
370
- // 1.4. Set read BADs as the active cache.
371
- // FIXME: just to already instantiated cache above
372
- this . activeCache = new IndexAllocationCache ( {
373
- edvClient, records : cacheRecords
374
- } ) ;
363
+ // 1.5. Set `cache` as the active cache.
364
+ this . activeCache = cache ;
375
365
}
376
366
}
377
367
0 commit comments