@@ -341,6 +341,10 @@ class SystemStore extends EventEmitter {
341
341
*/
342
342
static get_instance ( options = { } ) {
343
343
const { standalone } = options ;
344
+ //load from core if enabled and this is an endpoint
345
+ const is_endpoint = process . env . HOSTNAME && process . env . HOSTNAME . indexOf ( "endpoint" ) !== - 1 ;
346
+ this . source = options . source ||
347
+ ( ( config . SYSTEM_STORE_SOURCE . toUpperCase ( ) === 'CORE' && is_endpoint ) ? SOURCE . CORE : SOURCE . DB ) ;
344
348
SystemStore . _instance = SystemStore . _instance || new SystemStore ( { standalone } ) ;
345
349
return SystemStore . _instance ;
346
350
}
@@ -357,13 +361,19 @@ class SystemStore extends EventEmitter {
357
361
this . START_REFRESH_THRESHOLD = 10 * 60 * 1000 ;
358
362
this . FORCE_REFRESH_THRESHOLD = 60 * 60 * 1000 ;
359
363
this . SYSTEM_STORE_LOAD_CONCURRENCY = config . SYSTEM_STORE_LOAD_CONCURRENCY || 5 ;
360
- //load from core is 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 . toUpperCase ( ) === 'CORE' && is_endpoint ) ? SOURCE . CORE : SOURCE . DB ;
364
+ this . source = options . source || SOURCE . DB ;
363
365
dbg . log0 ( "system store source is" , this . source ) ;
364
366
this . _load_serial = new semaphore . Semaphore ( 1 , { warning_timeout : this . START_REFRESH_THRESHOLD } ) ;
365
367
for ( const col of COLLECTIONS ) {
366
- db_client . instance ( ) . define_collection ( col ) ;
368
+ try {
369
+ db_client . instance ( ) . define_collection ( col ) ;
370
+ } catch ( e ) {
371
+ if ( e . message ?. indexOf ( "table already defined" ) > - 1 ) {
372
+ dbg . warn ( "Ignoring table already defined error" ) ;
373
+ } else {
374
+ throw e ;
375
+ }
376
+ }
367
377
}
368
378
js_utils . deep_freeze ( COLLECTIONS ) ;
369
379
js_utils . deep_freeze ( COLLECTIONS_BY_NAME ) ;
@@ -430,7 +440,7 @@ class SystemStore extends EventEmitter {
430
440
// because it might not see the latest changes if we don't reload right after make_changes.
431
441
return this . _load_serial . surround ( async ( ) => {
432
442
try {
433
- dbg . log3 ( 'SystemStore: loading ... this.last_update_time =' , this . last_update_time , ", since =" , since ) ;
443
+ dbg . log3 ( 'SystemStore: loading ... this.last_update_time =' , this . last_update_time , ", since =" , since , "load_from_core_step =" , load_from_core_step ) ;
434
444
435
445
// If we get a load request with an timestamp older then our last update time
436
446
// we ensure we load everyting from that timestamp by updating our last_update_time.
0 commit comments