@@ -357,9 +357,9 @@ class SystemStore extends EventEmitter {
357
357
this . START_REFRESH_THRESHOLD = 10 * 60 * 1000 ;
358
358
this . FORCE_REFRESH_THRESHOLD = 60 * 60 * 1000 ;
359
359
this . SYSTEM_STORE_LOAD_CONCURRENCY = config . SYSTEM_STORE_LOAD_CONCURRENCY || 5 ;
360
- //load from core if enabled and this is an endpoint
360
+ //load from core is enabled and this is an endpoint
361
361
const is_endpoint = process . env . HOSTNAME && process . env . HOSTNAME . indexOf ( "endpoint" ) !== - 1 ;
362
- this . source = ( config . SYSTEM_STORE_SOURCE . toLowerCase ( ) === 'core ' && is_endpoint ) ? SOURCE . CORE : SOURCE . DB ;
362
+ this . source = ( config . SYSTEM_STORE_SOURCE . toUpperCase ( ) === 'CORE ' && is_endpoint ) ? SOURCE . CORE : SOURCE . DB ;
363
363
dbg . log0 ( "system store source is" , this . source ) ;
364
364
this . _load_serial = new semaphore . Semaphore ( 1 , { warning_timeout : this . START_REFRESH_THRESHOLD } ) ;
365
365
for ( const col of COLLECTIONS ) {
@@ -416,7 +416,16 @@ class SystemStore extends EventEmitter {
416
416
}
417
417
}
418
418
419
- async load ( since ) {
419
+ async load ( since , load_from_core_step ) {
420
+ //if endpoints load from core, and this load is for core
421
+ //(ie, the first load_system_store() out of two with load_from_core_step === 'CORE'),
422
+ //then endpoints skip it.
423
+ //endpoints will be updated in the next load_system_store()
424
+ //once core's in memory system store is updated.
425
+ if ( this . source . toUpperCase ( ) === 'CORE' && load_from_core_step && load_from_core_step . toUpperCase ( ) === 'CORE' ) {
426
+ return ;
427
+ }
428
+
420
429
// serializing load requests since we have to run a fresh load after the previous one will finish
421
430
// because it might not see the latest changes if we don't reload right after make_changes.
422
431
return this . _load_serial . surround ( async ( ) => {
@@ -674,20 +683,20 @@ class SystemStore extends EventEmitter {
674
683
method_api : 'server_inter_process_api' ,
675
684
method_name : 'load_system_store' ,
676
685
target : '' ,
677
- request_params : { since : last_update , load_from_core_step : 'core ' }
686
+ request_params : { since : last_update , load_from_core_step : 'CORE ' }
678
687
} ) ;
679
688
680
689
//if endpoints are loading system store from core, we need to wait until
681
690
//above publish_to_cluster() will update core's in-memory db.
682
691
//the next publist_to_cluster() will make endpoints load the updated
683
692
//system store from core
684
- if ( config . SYSTEM_STORE_SOURCE . toLowerCase ( ) === 'core ' ) {
693
+ if ( config . SYSTEM_STORE_SOURCE . toUpperCase ( ) === 'CORE ' ) {
685
694
dbg . log2 ( "second phase publish" ) ;
686
695
await server_rpc . client . redirector . publish_to_cluster ( {
687
696
method_api : 'server_inter_process_api' ,
688
697
method_name : 'load_system_store' ,
689
698
target : '' ,
690
- request_params : { since : last_update , load_from_core_step : 'endpoint ' }
699
+ request_params : { since : last_update , load_from_core_step : 'ENDPOINT ' }
691
700
} ) ;
692
701
}
693
702
}
0 commit comments