@@ -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 ) ;
@@ -359,6 +360,8 @@ class SystemStore extends EventEmitter {
359
360
js_utils . deep_freeze ( COLLECTIONS_BY_NAME ) ;
360
361
this . refresh_middleware = ( ) => this . refresh ( ) ;
361
362
this . initial_load ( ) ;
363
+ //call refresh() periodically
364
+ setInterval ( this . refresh , this . START_REFRESH_THRESHOLD ) ;
362
365
}
363
366
364
367
[ util . inspect . custom ] ( ) { return 'SystemStore' ; }
@@ -411,26 +414,29 @@ class SystemStore extends EventEmitter {
411
414
// because it might not see the latest changes if we don't reload right after make_changes.
412
415
return this . _load_serial . surround ( async ( ) => {
413
416
try {
414
- dbg . log3 ( 'SystemStore: loading ...' ) ;
417
+ dbg . log3 ( 'SystemStore: loading ... this.last_update_time =' , this . last_update_time , ", since =" , since ) ;
418
+
419
+ const new_data = new SystemStoreData ( ) ;
415
420
416
421
// If we get a load request with an timestamp older then our last update time
417
422
// we ensure we load everyting from that timestamp by updating our last_update_time.
418
423
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' ) ;
424
+ dbg . log0 ( 'SystemStore.load: Got load request with a timestamp' , since , ' older than my last update time', this . last_update_time ) ;
420
425
this . last_update_time = since ;
421
426
}
422
427
this . master_key_manager . load_root_key ( ) ;
423
- const new_data = new SystemStoreData ( ) ;
424
428
let millistamp = time_utils . millistamp ( ) ;
425
429
await this . _register_for_changes ( ) ;
426
430
await this . _read_new_data_from_db ( new_data ) ;
427
431
const secret = await os_utils . read_server_secret ( ) ;
428
432
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
- } ) ) ;
433
+ if ( dbg . should_log ( 1 ) ) { //param should match below logs' level
434
+ dbg . log1 ( 'SystemStore: fetch took' , time_utils . millitook ( millistamp ) ) ;
435
+ dbg . log1 ( 'SystemStore: fetch size' , size_utils . human_size ( JSON . stringify ( new_data ) . length ) ) ;
436
+ dbg . log1 ( 'SystemStore: fetch data' , util . inspect ( new_data , {
437
+ depth : 4
438
+ } ) ) ;
439
+ }
434
440
this . old_db_data = this . _update_data_from_new ( this . old_db_data || { } , new_data ) ;
435
441
this . data = _ . cloneDeep ( this . old_db_data ) ;
436
442
millistamp = time_utils . millistamp ( ) ;
@@ -506,7 +512,7 @@ class SystemStore extends EventEmitter {
506
512
}
507
513
} ;
508
514
await db_client . instance ( ) . connect ( ) ;
509
- await P . map ( COLLECTIONS , async col => {
515
+ await P . map_with_concurrency ( this . SYSTEM_STORE_LOAD_CONCURRENCY , COLLECTIONS , async col => {
510
516
const res = await db_client . instance ( ) . collection ( col . name )
511
517
. find ( newly_updated_query , {
512
518
projection : { last_update : 0 }
@@ -598,7 +604,7 @@ class SystemStore extends EventEmitter {
598
604
* @property {Object } [remove]
599
605
*
600
606
*/
601
- async make_changes ( changes ) {
607
+ async make_changes ( changes , publish = true ) {
602
608
// Refreshing must be done outside the semapore lock because refresh
603
609
// might call load that is locking on the same semaphore.
604
610
await this . refresh ( ) ;
@@ -611,7 +617,7 @@ class SystemStore extends EventEmitter {
611
617
if ( any_news ) {
612
618
if ( this . is_standalone ) {
613
619
await this . load ( last_update ) ;
614
- } else {
620
+ } else if ( publish ) {
615
621
// notify all the cluster (including myself) to reload
616
622
await server_rpc . client . redirector . publish_to_cluster ( {
617
623
method_api : 'server_inter_process_api' ,
0 commit comments