@@ -357,7 +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- this . source = config . SYSTEM_STORE_SOURCE . toLocaleLowerCase ( ) === 'core' ? SOURCE . CORE : SOURCE . DB ;
360+ //load from core if enabled and this is an endpoint
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 ;
361363 dbg . log0 ( "system store source is" , this . source ) ;
362364 this . _load_serial = new semaphore . Semaphore ( 1 , { warning_timeout : this . START_REFRESH_THRESHOLD } ) ;
363365 for ( const col of COLLECTIONS ) {
@@ -666,13 +668,28 @@ class SystemStore extends EventEmitter {
666668 if ( this . is_standalone ) {
667669 await this . load ( last_update ) ;
668670 } else if ( publish ) {
671+ dbg . log2 ( "first phase publish" ) ;
669672 // notify all the cluster (including myself) to reload
670673 await server_rpc . client . redirector . publish_to_cluster ( {
671674 method_api : 'server_inter_process_api' ,
672675 method_name : 'load_system_store' ,
673676 target : '' ,
674- request_params : { since : last_update }
677+ request_params : { since : last_update , load_from_core_step : 'core' }
675678 } ) ;
679+
680+ //if endpoints are loading system store from core, we need to wait until
681+ //above publish_to_cluster() will update core's in-memory db.
682+ //the next publist_to_cluster() will make endpoints load the updated
683+ //system store from core
684+ if ( config . SYSTEM_STORE_SOURCE . toLowerCase ( ) === 'core' ) {
685+ dbg . log2 ( "second phase publish" ) ;
686+ await server_rpc . client . redirector . publish_to_cluster ( {
687+ method_api : 'server_inter_process_api' ,
688+ method_name : 'load_system_store' ,
689+ target : '' ,
690+ request_params : { since : last_update , load_from_core_step : 'endpoint' }
691+ } ) ;
692+ }
676693 }
677694 }
678695 }
0 commit comments