@@ -351,6 +351,7 @@ class SystemStore extends EventEmitter {
351
351
this . is_finished_initial_load = false ;
352
352
this . START_REFRESH_THRESHOLD = 10 * 60 * 1000 ;
353
353
this . FORCE_REFRESH_THRESHOLD = 60 * 60 * 1000 ;
354
+ this . SYSTEM_STORE_LOAD_CONCURRENCY = config . SYSTEM_STORE_LOAD_CONCURRENCY || 5 ;
354
355
this . _load_serial = new semaphore . Semaphore ( 1 , { warning_timeout : this . START_REFRESH_THRESHOLD } ) ;
355
356
for ( const col of COLLECTIONS ) {
356
357
db_client . instance ( ) . define_collection ( col ) ;
@@ -393,44 +394,51 @@ class SystemStore extends EventEmitter {
393
394
if ( this . data ) {
394
395
load_time = this . data . time ;
395
396
}
397
+ let res ;
396
398
const since_load = Date . now ( ) - load_time ;
397
399
if ( since_load < this . START_REFRESH_THRESHOLD ) {
398
- return this . data ;
400
+ res = this . data ;
399
401
} else if ( since_load < this . FORCE_REFRESH_THRESHOLD ) {
400
402
dbg . warn ( `system_store.refresh: system_store.data.time > START_REFRESH_THRESHOLD, since_load = ${ since_load } , START_REFRESH_THRESHOLD = ${ this . START_REFRESH_THRESHOLD } ` ) ;
401
403
this . load ( ) . catch ( _ . noop ) ;
402
- return this . data ;
404
+ res = this . data ;
403
405
} else {
404
406
dbg . warn ( `system_store.refresh: system_store.data.time > FORCE_REFRESH_THRESHOLD, since_load = ${ since_load } , FORCE_REFRESH_THRESHOLD = ${ this . FORCE_REFRESH_THRESHOLD } ` ) ;
405
- return this . load ( ) ;
407
+ res = this . load ( ) ;
406
408
}
409
+ //call refresh periodically
410
+ P . delay_unblocking ( this . START_REFRESH_THRESHOLD ) . then ( this . refresh ) ;
411
+ return res ;
407
412
}
408
413
409
414
async load ( since ) {
410
415
// serializing load requests since we have to run a fresh load after the previous one will finish
411
416
// because it might not see the latest changes if we don't reload right after make_changes.
412
417
return this . _load_serial . surround ( async ( ) => {
413
418
try {
414
- dbg . log3 ( 'SystemStore: loading ...' ) ;
419
+ dbg . log3 ( 'SystemStore: loading ... this.last_update_time =' , this . last_update_time , ", since =" , since ) ;
420
+
421
+ const new_data = new SystemStoreData ( ) ;
415
422
416
423
// If we get a load request with an timestamp older then our last update time
417
424
// we ensure we load everyting from that timestamp by updating our last_update_time.
418
425
if ( ! _ . isUndefined ( since ) && since < this . last_update_time ) {
419
- dbg . log0 ( 'SystemStore.load: Got load request with a timestamp older then my last update time' ) ;
426
+ dbg . log0 ( 'SystemStore.load: Got load request with a timestamp' , since , ' older than my last update time', this . last_update_time ) ;
420
427
this . last_update_time = since ;
421
428
}
422
429
this . master_key_manager . load_root_key ( ) ;
423
- const new_data = new SystemStoreData ( ) ;
424
430
let millistamp = time_utils . millistamp ( ) ;
425
431
await this . _register_for_changes ( ) ;
426
432
await this . _read_new_data_from_db ( new_data ) ;
427
433
const secret = await os_utils . read_server_secret ( ) ;
428
434
this . _server_secret = secret ;
429
- dbg . log1 ( 'SystemStore: fetch took' , time_utils . millitook ( millistamp ) ) ;
430
- dbg . log1 ( 'SystemStore: fetch size' , size_utils . human_size ( JSON . stringify ( new_data ) . length ) ) ;
431
- dbg . log1 ( 'SystemStore: fetch data' , util . inspect ( new_data , {
432
- depth : 4
433
- } ) ) ;
435
+ if ( dbg . should_log ( 1 ) ) { //param should match below logs' level
436
+ dbg . log1 ( 'SystemStore: fetch took' , time_utils . millitook ( millistamp ) ) ;
437
+ dbg . log1 ( 'SystemStore: fetch size' , size_utils . human_size ( JSON . stringify ( new_data ) . length ) ) ;
438
+ dbg . log1 ( 'SystemStore: fetch data' , util . inspect ( new_data , {
439
+ depth : 4
440
+ } ) ) ;
441
+ }
434
442
this . old_db_data = this . _update_data_from_new ( this . old_db_data || { } , new_data ) ;
435
443
this . data = _ . cloneDeep ( this . old_db_data ) ;
436
444
millistamp = time_utils . millistamp ( ) ;
@@ -506,7 +514,7 @@ class SystemStore extends EventEmitter {
506
514
}
507
515
} ;
508
516
await db_client . instance ( ) . connect ( ) ;
509
- await P . map ( COLLECTIONS , async col => {
517
+ await P . map_with_concurrency ( this . SYSTEM_STORE_LOAD_CONCURRENCY , COLLECTIONS , async col => {
510
518
const res = await db_client . instance ( ) . collection ( col . name )
511
519
. find ( newly_updated_query , {
512
520
projection : { last_update : 0 }
@@ -598,7 +606,7 @@ class SystemStore extends EventEmitter {
598
606
* @property {Object } [remove]
599
607
*
600
608
*/
601
- async make_changes ( changes ) {
609
+ async make_changes ( changes , publish = true ) {
602
610
// Refreshing must be done outside the semapore lock because refresh
603
611
// might call load that is locking on the same semaphore.
604
612
await this . refresh ( ) ;
@@ -611,7 +619,7 @@ class SystemStore extends EventEmitter {
611
619
if ( any_news ) {
612
620
if ( this . is_standalone ) {
613
621
await this . load ( last_update ) ;
614
- } else {
622
+ } else if ( publish ) {
615
623
// notify all the cluster (including myself) to reload
616
624
await server_rpc . client . redirector . publish_to_cluster ( {
617
625
method_api : 'server_inter_process_api' ,
0 commit comments