Commit 14e12451 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] add `trim-indexes` command: manually trims the indexes if necessary

parent f6eb360c
......@@ -239,13 +239,7 @@ export class DuniterBlockchain {
await this.updateWallets(indexes.sindex, indexes.dividends, dal)
if (trim) {
const TAIL = await dal.bindexDAL.tail();
const MAX_BINDEX_SIZE = requiredBindexSizeForTail(TAIL, conf)
const currentSize = indexes.HEAD.number - TAIL.number + 1
if (currentSize > MAX_BINDEX_SIZE) {
await dal.archiveBlocks()
await dal.trimIndexes(indexes.HEAD.number - MAX_BINDEX_SIZE);
}
await DuniterBlockchain.trimIndexes(dal, indexes.HEAD, conf)
}
const dbb = DBBlock.fromBlockDTO(block)
......@@ -573,6 +567,15 @@ export class DuniterBlockchain {
throw err;
}
}
public static async trimIndexes(dal: FileDAL, HEAD: { number: number }, conf: ConfDTO) {
const TAIL = await dal.bindexDAL.tail();
const MAX_BINDEX_SIZE = requiredBindexSizeForTail(TAIL, conf)
const currentSize = HEAD.number - TAIL.number + 1
if (currentSize > MAX_BINDEX_SIZE) {
await dal.trimIndexes(HEAD.number - MAX_BINDEX_SIZE);
}
}
}
export function requiredBindexSizeForTail(TAIL: { issuersCount: number, issuersFrame: number }, conf: { medianTimeBlocks: number, dtDiffEval: number, forksize: number }) {
......
......@@ -76,6 +76,18 @@ module.exports = {
// Save DB
await server.disconnect();
}
}, {
name: 'trim-indexes',
desc: 'Force trimming of indexes',
logs: true,
preventIfRunning: true,
onConfiguredExecute: async (server:Server) => {
await server.dal.init(server.conf)
await server.BlockchainService.trimIndexes()
// Save DB
await server.disconnect();
}
}, {
name: 'dump [what] [name] [cond]',
desc: 'Dumps data of the blockchain.',
......
......@@ -459,4 +459,10 @@ export class BlockchainService extends FIFOService {
return this.dal.getBlocksBetween(from, from + count - 1);
}
async trimIndexes() {
const HEAD = await this.dal.getCurrentBlockOrNull()
if (HEAD) {
return DuniterBlockchain.trimIndexes(this.dal, HEAD, this.conf)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment