From faa7ebf399f368ad6f8df1b69d8971ea65603038 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 15 Oct 2020 13:11:09 +0530 Subject: [PATCH] Fix some bugs with integrated eviction 1. implement SET_LAST_EVICTION as an admin command, not a decree 2. expect a return value from Env.evictInactive and expose it via Env.evictionReport --- lib/commands/admin-rpc.js | 20 ++++++++++++++++++-- lib/decrees.js | 3 --- lib/env.js | 2 +- lib/eviction.js | 1 + lib/historyKeeper.js | 6 +++++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index 9278c09a6..e67f75f6c 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -211,6 +211,21 @@ the server adds two pieces of information to the supplied decree: Decrees.write(Env, decree, cb); }; +// CryptPad_AsyncStore.rpc.send('ADMIN', ['SET_LAST_EVICTION', 0], console.log) +var setLastEviction = function (Env, Server, cb, data, unsafeKey) { + var time = data && data[1]; + if (typeof(time) !== 'number') { + return void cb('INVALID_ARGS'); + } + + Env.lastEviction = time; + cb(); + Env.Log.info('LAST_EVICTION_TIME_SET', { + author: unsafeKey, + time: time, + }); +}; + // CryptPad_AsyncStore.rpc.send('ADMIN', ['INSTANCE_STATUS], console.log) var instanceStatus = function (Env, Server, cb) { cb(void 0, { @@ -225,8 +240,8 @@ var instanceStatus = function (Env, Server, cb) { defaultStorageLimit: Env.defaultStorageLimit, lastEviction: Env.lastEviction, - // FIXME eviction is run in a worker and this isn't returned - //knownActiveAccounts: Env.knownActiveAccounts, + evictionReport: Env.evictionReport, + disableIntegratedEviction: Env.disableIntegratedEviction, disableIntegratedTasks: Env.disableIntegratedTasks, @@ -257,6 +272,7 @@ var commands = { ADMIN_DECREE: adminDecree, INSTANCE_STATUS: instanceStatus, GET_LIMITS: getLimits, + SET_LAST_EVICTION: setLastEviction, }; Admin.command = function (Env, safeKey, data, _cb, Server) { diff --git a/lib/decrees.js b/lib/decrees.js index d7983c79c..2672efdd3 100644 --- a/lib/decrees.js +++ b/lib/decrees.js @@ -112,9 +112,6 @@ commands.SET_PREMIUM_UPLOAD_SIZE = makeIntegerSetter('premiumUploadSize'); // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['UPDATE_DEFAULT_STORAGE', [100 * 1024 * 1024]]], console.log) commands.UPDATE_DEFAULT_STORAGE = makeIntegerSetter('defaultStorageLimit'); -// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_LAST_EVICTION', [0]]], console.log) -commands.SET_LAST_EVICTION = makeIntegerSetter('lastEviction'); - // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_INACTIVE_TIME', [90]]], console.log) commands.SET_INACTIVE_TIME = makeIntegerSetter('inactiveTime'); diff --git a/lib/env.js b/lib/env.js index 8cc45fcc4..97ebd20ce 100644 --- a/lib/env.js +++ b/lib/env.js @@ -92,7 +92,7 @@ module.exports.create = function (config) { disableIntegratedTasks: config.disableIntegratedTasks || false, disableIntegratedEviction: config.disableIntegratedEviction || false, lastEviction: +new Date(), - knownActiveAccounts: 0, + evictionReport: {}, }; (function () { diff --git a/lib/eviction.js b/lib/eviction.js index 22f5dbee8..84db87d13 100644 --- a/lib/eviction.js +++ b/lib/eviction.js @@ -49,6 +49,7 @@ module.exports = function (Env, cb) { // channelsArchived, + launchTime: +new Date(), // runningTime, }; diff --git a/lib/historyKeeper.js b/lib/historyKeeper.js index fc71c9856..d95c0e99f 100644 --- a/lib/historyKeeper.js +++ b/lib/historyKeeper.js @@ -191,13 +191,17 @@ module.exports.create = function (Env, cb) { // evict inactive data once per day if ((now - ONE_DAY) < Env.lastEviction) { return; } active = true; - Env.evictInactive(function (err) { + Env.evictInactive(function (err, report) { if (err) { // NO_INACTIVE_TIME Log.error('EVICT_INACTIVE_MAIN_ERROR', err); } active = false; Env.lastEviction = now; + if (report) { + Log.info('EVICT_INACTIVE_REPORT', report); + } + Env.evictionReport = report || {}; }); }, 60 * 1000); }).nThen(function () {