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
pull/1/head
ansuz 4 years ago
parent ac322c8e82
commit faa7ebf399

@ -211,6 +211,21 @@ the server adds two pieces of information to the supplied decree:
Decrees.write(Env, decree, cb); 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) // CryptPad_AsyncStore.rpc.send('ADMIN', ['INSTANCE_STATUS], console.log)
var instanceStatus = function (Env, Server, cb) { var instanceStatus = function (Env, Server, cb) {
cb(void 0, { cb(void 0, {
@ -225,8 +240,8 @@ var instanceStatus = function (Env, Server, cb) {
defaultStorageLimit: Env.defaultStorageLimit, defaultStorageLimit: Env.defaultStorageLimit,
lastEviction: Env.lastEviction, lastEviction: Env.lastEviction,
// FIXME eviction is run in a worker and this isn't returned evictionReport: Env.evictionReport,
//knownActiveAccounts: Env.knownActiveAccounts,
disableIntegratedEviction: Env.disableIntegratedEviction, disableIntegratedEviction: Env.disableIntegratedEviction,
disableIntegratedTasks: Env.disableIntegratedTasks, disableIntegratedTasks: Env.disableIntegratedTasks,
@ -257,6 +272,7 @@ var commands = {
ADMIN_DECREE: adminDecree, ADMIN_DECREE: adminDecree,
INSTANCE_STATUS: instanceStatus, INSTANCE_STATUS: instanceStatus,
GET_LIMITS: getLimits, GET_LIMITS: getLimits,
SET_LAST_EVICTION: setLastEviction,
}; };
Admin.command = function (Env, safeKey, data, _cb, Server) { Admin.command = function (Env, safeKey, data, _cb, Server) {

@ -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) // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['UPDATE_DEFAULT_STORAGE', [100 * 1024 * 1024]]], console.log)
commands.UPDATE_DEFAULT_STORAGE = makeIntegerSetter('defaultStorageLimit'); 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) // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_INACTIVE_TIME', [90]]], console.log)
commands.SET_INACTIVE_TIME = makeIntegerSetter('inactiveTime'); commands.SET_INACTIVE_TIME = makeIntegerSetter('inactiveTime');

@ -92,7 +92,7 @@ module.exports.create = function (config) {
disableIntegratedTasks: config.disableIntegratedTasks || false, disableIntegratedTasks: config.disableIntegratedTasks || false,
disableIntegratedEviction: config.disableIntegratedEviction || false, disableIntegratedEviction: config.disableIntegratedEviction || false,
lastEviction: +new Date(), lastEviction: +new Date(),
knownActiveAccounts: 0, evictionReport: {},
}; };
(function () { (function () {

@ -49,6 +49,7 @@ module.exports = function (Env, cb) {
// channelsArchived, // channelsArchived,
launchTime: +new Date(),
// runningTime, // runningTime,
}; };

@ -191,13 +191,17 @@ module.exports.create = function (Env, cb) {
// evict inactive data once per day // evict inactive data once per day
if ((now - ONE_DAY) < Env.lastEviction) { return; } if ((now - ONE_DAY) < Env.lastEviction) { return; }
active = true; active = true;
Env.evictInactive(function (err) { Env.evictInactive(function (err, report) {
if (err) { if (err) {
// NO_INACTIVE_TIME // NO_INACTIVE_TIME
Log.error('EVICT_INACTIVE_MAIN_ERROR', err); Log.error('EVICT_INACTIVE_MAIN_ERROR', err);
} }
active = false; active = false;
Env.lastEviction = now; Env.lastEviction = now;
if (report) {
Log.info('EVICT_INACTIVE_REPORT', report);
}
Env.evictionReport = report || {};
}); });
}, 60 * 1000); }, 60 * 1000);
}).nThen(function () { }).nThen(function () {

Loading…
Cancel
Save