diff --git a/app/lib/dal/indexDAL/abstract/GenericDAO.ts b/app/lib/dal/indexDAL/abstract/GenericDAO.ts index 82bab5e6873d35c11b0f2d1e50f389b3c5b22edc..f43907cd7eca776be7071593d7ea5884f22baf4a 100644 --- a/app/lib/dal/indexDAL/abstract/GenericDAO.ts +++ b/app/lib/dal/indexDAL/abstract/GenericDAO.ts @@ -42,4 +42,6 @@ export interface GenericDAO<T> extends Initiable { * @returns {Promise<void>} */ removeBlock(blockstamp:string): Promise<void> + + count(): Promise<number> } diff --git a/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts b/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts index 972f4181f3bf61359a8e23aa903a65ad555bc6ff..8dfab34d878214c6be200dcbc9b775559bcd8702 100644 --- a/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts +++ b/app/lib/dal/indexDAL/leveldb/LevelDBCindex.ts @@ -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 + } } diff --git a/app/lib/dal/indexDAL/leveldb/LevelDBDividend.ts b/app/lib/dal/indexDAL/leveldb/LevelDBDividend.ts index 77d67cf18fc84baa40f6bd0acb60401b65e675f9..6d6f4bebcff10cb45791d63480035b8e778ffa18 100644 --- a/app/lib/dal/indexDAL/leveldb/LevelDBDividend.ts +++ b/app/lib/dal/indexDAL/leveldb/LevelDBDividend.ts @@ -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 + } } diff --git a/app/lib/dal/indexDAL/loki/LokiIndex.ts b/app/lib/dal/indexDAL/loki/LokiIndex.ts index 877cdc511c375456d8358d4057c81aa04d961d1d..db9f53bf9a77ba3a94ae62f8954d1e4e444ebc12 100644 --- a/app/lib/dal/indexDAL/loki/LokiIndex.ts +++ b/app/lib/dal/indexDAL/loki/LokiIndex.ts @@ -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 + } } diff --git a/app/lib/dal/indexDAL/loki/LokiProtocolIndex.ts b/app/lib/dal/indexDAL/loki/LokiProtocolIndex.ts index 90848ed997e145725805f3fd010efe8cde653dda..dafbba713450fe756cd430cd867367343a18f8a5 100644 --- a/app/lib/dal/indexDAL/loki/LokiProtocolIndex.ts +++ b/app/lib/dal/indexDAL/loki/LokiProtocolIndex.ts @@ -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 + } } diff --git a/app/lib/dal/indexDAL/sqlite/SqliteTable.ts b/app/lib/dal/indexDAL/sqlite/SqliteTable.ts index 23583c72076775e94a098f3ad13c871cb64aef68..c55e735af6c3ff660586d5d66f83a4567f6f39a2 100644 --- a/app/lib/dal/indexDAL/sqlite/SqliteTable.ts +++ b/app/lib/dal/indexDAL/sqlite/SqliteTable.ts @@ -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. diff --git a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts index 65ebab902f222a295a25409465b76fe4a53cf6df..1633a72d0af6991b813b837a6196711355c7e956 100644 --- a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts +++ b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts @@ -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() diff --git a/app/modules/dump.ts b/app/modules/dump.ts index 094e35a74651ae6905b1f230148523dd2e070066..af03c77942859119fcc555f0aaafa1b8cb4acb3f 100644 --- a/app/modules/dump.ts +++ b/app/modules/dump.ts @@ -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(',') || []