@@ -357,7 +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
- 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 ;
361
363
dbg . log0 ( "system store source is" , this . source ) ;
362
364
this . _load_serial = new semaphore . Semaphore ( 1 , { warning_timeout : this . START_REFRESH_THRESHOLD } ) ;
363
365
for ( const col of COLLECTIONS ) {
@@ -666,13 +668,28 @@ class SystemStore extends EventEmitter {
666
668
if ( this . is_standalone ) {
667
669
await this . load ( last_update ) ;
668
670
} else if ( publish ) {
671
+ dbg . log2 ( "first phase publish" ) ;
669
672
// notify all the cluster (including myself) to reload
670
673
await server_rpc . client . redirector . publish_to_cluster ( {
671
674
method_api : 'server_inter_process_api' ,
672
675
method_name : 'load_system_store' ,
673
676
target : '' ,
674
- request_params : { since : last_update }
677
+ request_params : { since : last_update , load_from_core_step : 'core' }
675
678
} ) ;
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
+ }
676
693
}
677
694
}
678
695
}
0 commit comments