Commit 83b7b202 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] add `dump volumes` command

parent 6cfb3992
......@@ -42,4 +42,6 @@ export interface GenericDAO<T> extends Initiable {
* @returns {Promise<void>}
*/
removeBlock(blockstamp:string): Promise<void>
count(): Promise<number>
}
......@@ -6,6 +6,7 @@ import {Underscore} from "../../../common-libs/underscore"
import {pint} from "../../../common-libs/pint"
import {CIndexDAO} from "../abstract/CIndexDAO"
import {reduceConcat} from "../../../common-libs/reduce"
import {AbstractIteratorOptions} from "abstract-leveldown"
export interface LevelDBCindexEntry {
received: string[]
......@@ -249,4 +250,12 @@ export class LevelDBCindex extends LevelDBTable<LevelDBCindexEntry> implements C
trimExpiredCerts(belowNumber: number): Promise<void> {
return this.trimRecords(belowNumber)
}
async count(options?: AbstractIteratorOptions): Promise<number> {
let count = 0
await this.readAllKeyValue(entry => {
count += entry.value.issued.length
})
return count
}
}
......@@ -6,6 +6,7 @@ import {DataErrors} from "../../../common-libs/errors"
import {LevelUp} from 'levelup'
import {LevelDBTable} from "./LevelDBTable"
import {Underscore} from "../../../common-libs/underscore"
import {AbstractIteratorOptions} from "abstract-leveldown"
interface Consumption {
writtenOn: number
......@@ -229,4 +230,12 @@ export class LevelDBDividend extends LevelDBTable<DividendEntry> implements Divi
private static trimKey(writtenOn: number) {
return String(writtenOn).padStart(10, '0')
}
async count(options?: AbstractIteratorOptions): Promise<number> {
let count = 0
await this.readAllKeyValue(entry => {
count += entry.value.availables.length
})
return count
}
}
......@@ -32,4 +32,8 @@ export abstract class LokiIndex<T> extends LokiCollectionManager<T> implements G
abstract getWrittenOn(blockstamp: string): Promise<T[]>
abstract removeBlock(blockstamp: string): Promise<void>
async count() {
return this.collection.data.length
}
}
......@@ -20,4 +20,8 @@ export abstract class LokiProtocolIndex<T extends IndexData> extends LokiIndex<T
const data = await this.getWrittenOn(blockstamp)
data.map(d => this.collection.remove(d))
}
async count() {
return this.collection.data.length
}
}
......@@ -160,6 +160,10 @@ export class SqliteTable<T> {
ts.forEach(t => console.log(t))
}
async count() {
return ((await this.driver.sqlRead(`SELECT COUNT(*) as max FROM ${this.name}`, []))[0] as any).max
}
/**
* Debugging function: allows to make a hot copy of an SQLite database to a new file, even if the source is in-memory.
* @param {string} path The path where to write the copy.
......
......@@ -36,6 +36,8 @@ let sync_mindex: any[] = []
let sync_cindex: any[] = []
let sync_nextExpiring = 0
let sync_bindexSize = 0
let txCount = 0
let logger = NewLogger()
const sync_memoryWallets: any = {}
const sync_memoryDAL:AccountsGarbagingDAL = {
......@@ -328,6 +330,7 @@ export class GlobalIndexStream extends Duplex {
@MonitorExecutionTime()
private async beforeBlocks(blocks:BlockDTO[]) {
await this.dal.blockDAL.insertBatch(blocks.map(b => {
txCount += b.transactions.length
const block = DBBlock.fromBlockDTO(b)
block.fork = false
return block
......@@ -339,6 +342,8 @@ export class GlobalIndexStream extends Duplex {
// We only keep a bunch of days of blocks in memory, so memory consumption keeps approximately constant during the sync
await this.dal.blockDAL.trimBlocks(blocks[blocks.length - 1].number - CommonConstants.BLOCKS_IN_MEMORY_MAX)
logger.debug('Total tx count: %s', txCount)
}
@MonitorExecutionTime()
......
......@@ -38,6 +38,10 @@ module.exports = {
await dumpCurrent(server)
break
case 'volumes':
await dumpVolumes(server)
break
case 'table':
await dumpTable(server, name, cond)
break
......@@ -67,6 +71,19 @@ async function dumpCurrent(server: Server) {
}
}
async function dumpVolumes(server: Server) {
const nbUdo = await server.dal.dividendDAL.count()
const nbTxo = await server.dal.sindexDAL.count()
const iindex = await server.dal.iindexDAL.count()
const mindex = await server.dal.mindexDAL.count()
const cindex = await server.dal.cindexDAL.count()
console.log('Sindex : %s (%s UD, %s TX)', nbTxo + nbUdo, nbUdo, nbTxo)
console.log('Iindex : %s', iindex)
console.log('Mindex : %s', mindex)
console.log('Cindex : %s', cindex)
}
async function dumpTable(server: Server, name: string, condition?: string) {
const criterion: any = {}
const filters = condition && condition.split(',') || []
......
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