Skip to content

Commit 63954aa

Browse files
committed
system store - load from core - PR notes
Signed-off-by: Amit Prinz Setter <[email protected]>
1 parent e738196 commit 63954aa

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ config.INTERNAL_STORAGE_POOL_NAME = 'system-internal-storage-pool';
250250
config.ALLOW_BUCKET_CREATE_ON_INTERNAL = true;
251251
config.BUCKET_AUTOCONF_TIER2_ENABLED = false;
252252
config.SYSTEM_STORE_LOAD_CONCURRENCY = parseInt(process.env.SYSTEM_STORE_LOAD_CONCURRENCY, 10) || 5;
253-
253+
config.SYSTEM_STORE_SOURCE = process.env.SYSTEM_STORE_SOURCE || "db";
254254
//////////////////////////
255255
// MD AGGREGATOR CONFIG //
256256
//////////////////////////

src/api/system_api.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ module.exports = {
463463

464464
get_system_store: {
465465
method: 'GET',
466+
reply: {
467+
type: 'object',
468+
properties: {
469+
// [RPC_BUFFERS].data
470+
},
471+
},
466472
auth: {
467473
system: false
468474
}

src/endpoint/endpoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async function main(options = {}) {
171171
// Load a system store instance for the current process and register for changes.
172172
// We do not wait for it in becasue the result or errors are not relevent at
173173
// this point (and should not kill the process);
174-
system_store.get_instance({source: system_store.SOURCE.CORE}).load();
174+
system_store.get_instance().load();
175175
// Register the process as an md_server.
176176
await md_server.register_rpc();
177177
}

src/server/system_services/system_server.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,13 @@ function get_system_status(req) {
299299
}
300300

301301
async function get_system_store() {
302-
return {
303-
[RPC_BUFFERS]: {data: Buffer.from(JSON.stringify(await system_store.recent_db_data()))},
304-
};
302+
try {
303+
return {
304+
[RPC_BUFFERS]: {data: Buffer.from(JSON.stringify(await system_store.recent_db_data()))},
305+
};
306+
} catch (e) {
307+
dbg.error("Failed getting system store", e);
308+
}
305309
}
306310

307311
async function _update_system_state(system_id, mode) {

src/server/system_services/system_store.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ 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 = (process.env.HOSTNAME && process.env.HOSTNAME.indexOf("endpoint") === -1) ? SOURCE.DB : SOURCE.CORE;
360+
this.source = config.SYSTEM_STORE_SOURCE.toLocaleLowerCase() === 'core' ? SOURCE.CORE : SOURCE.DB;
361361
dbg.log0("system store source is", this.source);
362362
this._load_serial = new semaphore.Semaphore(1, { warning_timeout: this.START_REFRESH_THRESHOLD });
363363
for (const col of COLLECTIONS) {
@@ -431,11 +431,20 @@ class SystemStore extends EventEmitter {
431431
const new_data = new SystemStoreData();
432432
let millistamp = time_utils.millistamp();
433433
await this._register_for_changes();
434-
if (this.source === SOURCE.DB) {
434+
let from_core_failure = false;
435+
436+
if (this.source === SOURCE.CORE) {
437+
try {
438+
this.data = new SystemStoreData();
439+
await this._read_new_data_from_core(this.data);
440+
} catch (e) {
441+
dbg.error("Failed to load system store from core. Will load from db.", e);
442+
from_core_failure = true;
443+
}
444+
}
445+
446+
if (this.source === SOURCE.DB || from_core_failure) {
435447
await this._read_new_data_from_db(new_data);
436-
} else {
437-
this.data = new SystemStoreData();
438-
await this._read_new_data_from_core(this.data);
439448
}
440449

441450
const secret = await os_utils.read_server_secret();
@@ -447,7 +456,7 @@ class SystemStore extends EventEmitter {
447456
depth: 4
448457
}));
449458
}
450-
if (this.source === SOURCE.DB) {
459+
if (this.source === SOURCE.DB || from_core_failure) {
451460
this.old_db_data = this._update_data_from_new(this.old_db_data || {}, new_data);
452461
this.data = _.cloneDeep(this.old_db_data);
453462
}

0 commit comments

Comments
 (0)