|
|
|
@ -32,6 +32,25 @@ Env = {
|
|
|
|
|
|
|
|
|
|
module.exports = function (Env, cb) {
|
|
|
|
|
var complete = Util.once(Util.mkAsync(cb));
|
|
|
|
|
var report = {
|
|
|
|
|
// archivedChannelsRemoved,
|
|
|
|
|
// archivedAccountsRemoved,
|
|
|
|
|
// archivedBlobProofsRemoved,
|
|
|
|
|
// archivedBlobsRemoved,
|
|
|
|
|
|
|
|
|
|
// totalChannels,
|
|
|
|
|
// activeChannels,
|
|
|
|
|
|
|
|
|
|
// totalBlobs,
|
|
|
|
|
// activeBlobs,
|
|
|
|
|
|
|
|
|
|
// totalAccounts,
|
|
|
|
|
// activeAccounts,
|
|
|
|
|
|
|
|
|
|
// channelsArchived,
|
|
|
|
|
|
|
|
|
|
// runningTime,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// the administrator should have set an 'inactiveTime' in their config
|
|
|
|
|
// if they didn't, just exit.
|
|
|
|
@ -154,6 +173,8 @@ module.exports = function (Env, cb) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return Log.error('EVICT_ARCHIVED_FINAL_ERROR', err);
|
|
|
|
|
}
|
|
|
|
|
report.archivedChannelsRemoved = removed;
|
|
|
|
|
report.archivedAccountsRemoved = accounts;
|
|
|
|
|
Log.info('EVICT_ARCHIVED_CHANNELS_REMOVED', removed);
|
|
|
|
|
Log.info('EVICT_ARCHIVED_ACCOUNTS_REMOVED', accounts);
|
|
|
|
|
};
|
|
|
|
@ -183,6 +204,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
next();
|
|
|
|
|
}));
|
|
|
|
|
}, w(function () {
|
|
|
|
|
report.archivedBlobProofsRemoved = removed;
|
|
|
|
|
Log.info('EVICT_ARCHIVED_BLOB_PROOFS_REMOVED', removed);
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
@ -209,6 +231,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
}, w(function () {
|
|
|
|
|
report.archivedBlobsRemoved = removed;
|
|
|
|
|
Log.info('EVICT_ARCHIVED_BLOBS_REMOVED', removed);
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
@ -236,6 +259,8 @@ module.exports = function (Env, cb) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var done = function () {
|
|
|
|
|
report.activeChannels = active;
|
|
|
|
|
report.totalChannels = channels;
|
|
|
|
|
Log.info('EVICT_CHANNELS_CATEGORIZED', {
|
|
|
|
|
active: active,
|
|
|
|
|
channels: channels,
|
|
|
|
@ -267,6 +292,8 @@ module.exports = function (Env, cb) {
|
|
|
|
|
}
|
|
|
|
|
next();
|
|
|
|
|
}, w(function () {
|
|
|
|
|
report.totalBlobs = n_blobs;
|
|
|
|
|
report.activeBlobs = active;
|
|
|
|
|
Log.info('EVICT_BLOBS_CATEGORIZED', {
|
|
|
|
|
active: active,
|
|
|
|
|
blobs: n_blobs,
|
|
|
|
@ -333,6 +360,10 @@ module.exports = function (Env, cb) {
|
|
|
|
|
// we plan to delete them, because it may be interesting information
|
|
|
|
|
inactive++;
|
|
|
|
|
if (PRESERVE_INACTIVE_ACCOUNTS) {
|
|
|
|
|
Log.info('EVICT_INACTIVE_ACCOUNT_PRESERVED', {
|
|
|
|
|
id: id,
|
|
|
|
|
mtime: mtime,
|
|
|
|
|
});
|
|
|
|
|
pinAll(pinList);
|
|
|
|
|
return void next();
|
|
|
|
|
}
|
|
|
|
@ -362,9 +393,8 @@ module.exports = function (Env, cb) {
|
|
|
|
|
"EVICT_COUNT_ACCOUNTS":
|
|
|
|
|
"EVICT_INACTIVE_ACCOUNTS";
|
|
|
|
|
|
|
|
|
|
// update the number of known active accounts in Env for statistics
|
|
|
|
|
Env.knownActiveAccounts = accounts - inactive;
|
|
|
|
|
|
|
|
|
|
report.totalAccounts = accounts;
|
|
|
|
|
report.activeAccounts = accounts - inactive;
|
|
|
|
|
Log.info(label, {
|
|
|
|
|
accounts: accounts,
|
|
|
|
|
inactive: inactive,
|
|
|
|
@ -381,7 +411,9 @@ module.exports = function (Env, cb) {
|
|
|
|
|
// iterate over blobs and remove them
|
|
|
|
|
// if they have not been accessed within the specified retention time
|
|
|
|
|
var removed = 0;
|
|
|
|
|
var total = 0;
|
|
|
|
|
blobs.list.blobs(function (err, item, next) {
|
|
|
|
|
next = Util.mkAsync(next, THROTTLE_FACTOR);
|
|
|
|
|
if (err) {
|
|
|
|
|
Log.error("EVICT_BLOB_LIST_BLOBS_ERROR", err);
|
|
|
|
|
return void next();
|
|
|
|
@ -390,6 +422,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
next();
|
|
|
|
|
return void Log.error('EVICT_BLOB_LIST_BLOBS_NO_ITEM', item);
|
|
|
|
|
}
|
|
|
|
|
total++;
|
|
|
|
|
if (pinnedDocs.test(item.blobId)) { return void next(); }
|
|
|
|
|
if (activeDocs.test(item.blobId)) { return void next(); }
|
|
|
|
|
|
|
|
|
@ -398,6 +431,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
// unless we address this race condition with this last-minute double-check
|
|
|
|
|
if (getNewestTime(item) > inactiveTime) { return void next(); }
|
|
|
|
|
|
|
|
|
|
removed++;
|
|
|
|
|
blobs.archive.blob(item.blobId, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
Log.error("EVICT_ARCHIVE_BLOB_ERROR", {
|
|
|
|
@ -409,10 +443,11 @@ module.exports = function (Env, cb) {
|
|
|
|
|
Log.info("EVICT_ARCHIVE_BLOB", {
|
|
|
|
|
item: item,
|
|
|
|
|
});
|
|
|
|
|
removed++;
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
}, w(function () {
|
|
|
|
|
report.totalBlobs = total;
|
|
|
|
|
report.activeBlobs = total - removed;
|
|
|
|
|
Log.info('EVICT_BLOBS_REMOVED', removed);
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
@ -522,6 +557,7 @@ module.exports = function (Env, cb) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var done = function () {
|
|
|
|
|
report.channelsArchived = archived;
|
|
|
|
|
return void Log.info('EVICT_CHANNELS_ARCHIVED', archived);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -547,8 +583,9 @@ module.exports = function (Env, cb) {
|
|
|
|
|
.nThen(archiveInactiveBlobProofs)
|
|
|
|
|
.nThen(archiveInactiveChannels)
|
|
|
|
|
.nThen(function () {
|
|
|
|
|
Log.info("EVICT_TIME_TO_RUN_SCRIPT", msSinceStart());
|
|
|
|
|
var runningTime = report.runningTime = msSinceStart();
|
|
|
|
|
Log.info("EVICT_TIME_TO_RUN_SCRIPT", runningTime);
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
complete();
|
|
|
|
|
complete(void 0, report);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|