@@ -357,9 +357,9 @@ class SystemStore extends EventEmitter {
357357 this . START_REFRESH_THRESHOLD = 10 * 60 * 1000 ;
358358 this . FORCE_REFRESH_THRESHOLD = 60 * 60 * 1000 ;
359359 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
361361 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 ;
363363 dbg . log0 ( "system store source is" , this . source ) ;
364364 this . _load_serial = new semaphore . Semaphore ( 1 , { warning_timeout : this . START_REFRESH_THRESHOLD } ) ;
365365 for ( const col of COLLECTIONS ) {
@@ -416,7 +416,16 @@ class SystemStore extends EventEmitter {
416416 }
417417 }
418418
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+
420429 // serializing load requests since we have to run a fresh load after the previous one will finish
421430 // because it might not see the latest changes if we don't reload right after make_changes.
422431 return this . _load_serial . surround ( async ( ) => {
@@ -674,20 +683,20 @@ class SystemStore extends EventEmitter {
674683 method_api : 'server_inter_process_api' ,
675684 method_name : 'load_system_store' ,
676685 target : '' ,
677- request_params : { since : last_update , load_from_core_step : 'core ' }
686+ request_params : { since : last_update , load_from_core_step : 'CORE ' }
678687 } ) ;
679688
680689 //if endpoints are loading system store from core, we need to wait until
681690 //above publish_to_cluster() will update core's in-memory db.
682691 //the next publist_to_cluster() will make endpoints load the updated
683692 //system store from core
684- if ( config . SYSTEM_STORE_SOURCE . toLowerCase ( ) === 'core ' ) {
693+ if ( config . SYSTEM_STORE_SOURCE . toUpperCase ( ) === 'CORE ' ) {
685694 dbg . log2 ( "second phase publish" ) ;
686695 await server_rpc . client . redirector . publish_to_cluster ( {
687696 method_api : 'server_inter_process_api' ,
688697 method_name : 'load_system_store' ,
689698 target : '' ,
690- request_params : { since : last_update , load_from_core_step : 'endpoint ' }
699+ request_params : { since : last_update , load_from_core_step : 'ENDPOINT ' }
691700 } ) ;
692701 }
693702 }
0 commit comments