archive pin logs instead of removing them outright

pull/1/head
ansuz 3 years ago
parent 3cbf4c9d6f
commit caece0123e

@ -115,8 +115,8 @@ Pinning.getTotalSize = function (Env, safeKey, cb) {
*/ */
Pinning.removePins = function (Env, safeKey, cb) { Pinning.removePins = function (Env, safeKey, cb) {
// FIXME respect the queue // FIXME respect the queue
Env.pinStore.removeChannel(safeKey, function (err) { Env.pinStore.archiveChannel(safeKey, function (err) {
Env.Log.info('DELETION_PIN_BY_OWNER_RPC', { Env.Log.info('ARCHIVAL_PIN_BY_OWNER_RPC', {
safeKey: safeKey, safeKey: safeKey,
status: err? String(err): 'SUCCESS', status: err? String(err): 'SUCCESS',
}); });

@ -123,6 +123,8 @@ module.exports.create = function (Env, cb) {
Store.create({ Store.create({
filePath: pinPath, filePath: pinPath,
archivePath: Env.paths.archive, archivePath: Env.paths.archive,
// indicate that archives should be put in a 'pins' archvie folder
volumeId: 'pins',
}, w(function (err, s) { }, w(function (err, s) {
if (err) { throw err; } if (err) { throw err; }
Env.pinStore = s; Env.pinStore = s;

@ -51,7 +51,7 @@ var mkPath = function (env, channelId) {
}; };
var mkArchivePath = function (env, channelId) { var mkArchivePath = function (env, channelId) {
return Path.join(env.archiveRoot, 'datastore', channelId.slice(0, 2), channelId) + '.ndjson'; return Path.join(env.archiveRoot, env.volumeId, channelId.slice(0, 2), channelId) + '.ndjson';
}; };
var mkMetadataPath = function (env, channelId) { var mkMetadataPath = function (env, channelId) {
@ -59,7 +59,7 @@ var mkMetadataPath = function (env, channelId) {
}; };
var mkArchiveMetadataPath = function (env, channelId) { var mkArchiveMetadataPath = function (env, channelId) {
return Path.join(env.archiveRoot, 'datastore', channelId.slice(0, 2), channelId) + '.metadata.ndjson'; return Path.join(env.archiveRoot, env.volumeId, channelId.slice(0, 2), channelId) + '.metadata.ndjson';
}; };
var mkTempPath = function (env, channelId) { var mkTempPath = function (env, channelId) {
@ -1044,6 +1044,9 @@ module.exports.create = function (conf, _cb) {
var env = { var env = {
root: conf.filePath || './datastore', root: conf.filePath || './datastore',
archiveRoot: conf.archivePath || './data/archive', archiveRoot: conf.archivePath || './data/archive',
// supply a volumeId if you want a store to archive channels to and from
// to its own subpath within the archive directory
volumeId: conf.volumeId || 'datastore',
channels: { }, channels: { },
batchGetChannel: BatchRead('store_batch_channel'), batchGetChannel: BatchRead('store_batch_channel'),
}; };
@ -1076,7 +1079,7 @@ module.exports.create = function (conf, _cb) {
} }
})); }));
// make sure the cold storage directory exists // make sure the cold storage directory exists
Fse.mkdirp(env.archiveRoot, PERMISSIVE, w(function (err) { Fse.mkdirp(Path.join(env.archiveRoot, env.volumeId), PERMISSIVE, w(function (err) {
if (err && err.code !== 'EEXIST') { if (err && err.code !== 'EEXIST') {
w.abort(); w.abort();
return void cb(err); return void cb(err);

@ -66,6 +66,9 @@ const init = function (config, _cb) {
Store.create({ Store.create({
filePath: config.pinPath, filePath: config.pinPath,
archivePath: config.archivePath, archivePath: config.archivePath,
// important to initialize the pinstore with its own volume id
// otherwise archived pin logs will get mixed in with channels
volumeId: 'pins',
}, w(function (err, _pinStore) { }, w(function (err, _pinStore) {
if (err) { if (err) {
w.abort(); w.abort();

@ -56,6 +56,8 @@ var prepareEnv = function (Env, cb) {
Store.create({ Store.create({
filePath: config.pinPath, filePath: config.pinPath,
// archive pin logs to their own subpath
volumeId: 'pins',
}, w(function (err, _) { }, w(function (err, _) {
if (err) { if (err) {
w.abort(); w.abort();

@ -56,6 +56,8 @@ var prepareEnv = function (Env, cb) {
Store.create({ Store.create({
filePath: config.pinPath, filePath: config.pinPath,
// archive pin logs to their own subpath
volumeId: 'pins',
}, w(function (err, _) { }, w(function (err, _) {
if (err) { if (err) {
w.abort(); w.abort();

@ -0,0 +1,8 @@
// TODO unify the following scripts
// unused-translations.js
// find-html-translations
// more linting
// Search for 'Cryptpad' string (should be 'CryptPad')
// Search English for -ise\s
Loading…
Cancel
Save