Update ipld-status table in reset and fill state CLI (#193)

This commit is contained in:
2022-10-04 11:22:04 +05:30
committed by GitHub
parent 00a9c247f5
commit 6149690126
6 changed files with 68 additions and 33 deletions
@@ -120,10 +120,10 @@ export class Database implements IPLDDatabaseInterface {
await this._baseDatabase.removeIPLDBlocks(repo, blockNumber, kind);
}
async removeIPLDBlocksInRange (dbTx: QueryRunner, startBlock: number, endBlock: number): Promise<void> {
async removeIPLDBlocksAfterBlock (dbTx: QueryRunner, blockNumber: number): Promise<void> {
const repo = dbTx.manager.getRepository(IPLDBlock);
await this._baseDatabase.removeIPLDBlocksInRange(repo, startBlock, endBlock);
await this._baseDatabase.removeIPLDBlocksAfterBlock(repo, blockNumber);
}
async getIPLDStatus (): Promise<IpldStatus | undefined> {
@@ -15,21 +15,13 @@ export const command = 'ipld-state';
export const desc = 'Reset IPLD state in the given range';
export const builder = {
startBlock: {
type: 'number'
},
endBlock: {
blockNumber: {
type: 'number'
}
};
export const handler = async (argv: any): Promise<void> => {
const { startBlock, endBlock } = argv;
if (startBlock > endBlock) {
log('endBlock should be greater than or equal to startBlock');
process.exit(1);
}
const { blockNumber } = argv;
const config = await getConfig(argv.configFile);
// Initialize database
@@ -39,9 +31,27 @@ export const handler = async (argv: any): Promise<void> => {
// Create a DB transaction
const dbTx = await db.createTransactionRunner();
console.time('time:reset-ipld-state');
try {
// Delete all IPLDBlock entries in the given range
await db.removeIPLDBlocksInRange(dbTx, startBlock, endBlock);
await db.removeIPLDBlocksAfterBlock(dbTx, blockNumber);
// Reset the IPLD status.
const ipldStatus = await db.getIPLDStatus();
if (ipldStatus) {
if (ipldStatus.latestHooksBlockNumber > blockNumber) {
await db.updateIPLDStatusHooksBlock(dbTx, blockNumber, true);
}
if (ipldStatus.latestCheckpointBlockNumber > blockNumber) {
await db.updateIPLDStatusCheckpointBlock(dbTx, blockNumber, true);
}
if (ipldStatus.latestIPFSBlockNumber > blockNumber) {
await db.updateIPLDStatusIPFSBlock(dbTx, blockNumber, true);
}
}
dbTx.commitTransaction();
} catch (error) {
@@ -50,6 +60,7 @@ export const handler = async (argv: any): Promise<void> => {
} finally {
await dbTx.release();
}
console.timeEnd('time:reset-ipld-state');
log(`Reset ipld-state successfully for range [${startBlock}, ${endBlock}]`);
log(`Reset ipld-state successfully to block ${blockNumber}`);
};