From 219f12a65bf31e82b9139fd3735c60cd83583de4 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 28 Aug 2018 20:36:44 +0200 Subject: [PATCH] Remove db-diskdown LRU (#198) --- packages/db-diskdown/package.json | 1 - packages/db-diskdown/src/index.ts | 10 +--------- packages/db-diskdown/src/store/Combined.ts | 9 +++++---- yarn.lock | 4 ---- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/db-diskdown/package.json b/packages/db-diskdown/package.json index d8d81c7db..434327358 100644 --- a/packages/db-diskdown/package.json +++ b/packages/db-diskdown/package.json @@ -32,7 +32,6 @@ "@polkadot/util": "^0.28.16", "@types/mkdirp": "^0.5.2", "abstract-leveldown": "^5.0.0", - "lru_map": "^0.3.3", "mkdirp": "^0.5.1" }, "devDependencies": { diff --git a/packages/db-diskdown/src/index.ts b/packages/db-diskdown/src/index.ts index 5dc9fed1f..a59584cb5 100644 --- a/packages/db-diskdown/src/index.ts +++ b/packages/db-diskdown/src/index.ts @@ -5,14 +5,11 @@ import { DiskStore } from './types'; import { AbstractLevelDOWN } from 'abstract-leveldown'; -import { LRUMap } from 'lru_map'; import isUndefined from '@polkadot/util/is/undefined'; import logger from '@polkadot/util/logger'; import Combined from './store/Combined'; -// import Scatter from './store/Scatter'; -const LRU_SIZE = 8192; const KEY_LENGTH = 32; const l = logger('disk/scatter'); @@ -21,14 +18,11 @@ const noop = () => class DiskDown extends AbstractLevelDOWN { _disk: DiskStore; - _store: LRUMap; constructor (location: string) { super(location); - // this._disk = new Scatter(location); this._disk = new Combined(location); - this._store = new LRUMap(LRU_SIZE); } compact (progress: (message: string) => void): void { @@ -75,7 +69,6 @@ class DiskDown extends AbstractLevelDOWN { _del (key: Buffer, options: any, callback: Function) { l.debug(() => ['_del', key]); - this._store.delete(key.toString()); this._disk.delete(key); process.nextTick(callback); @@ -84,7 +77,7 @@ class DiskDown extends AbstractLevelDOWN { _get (key: Buffer, options: any, callback: Function) { l.debug(() => ['_get', key.toString('hex')]); - const value = this._store.get(key.toString()) || this._disk.get(key); + const value = this._disk.get(key); if (isUndefined(value)) { process.nextTick(callback, new Error('NotFound')); @@ -97,7 +90,6 @@ class DiskDown extends AbstractLevelDOWN { _put (key: Buffer, value: Buffer, options: any, callback: Function) { l.debug(() => ['_put', key.toString('hex'), value]); - this._store.set(key.toString(), value); this._disk.set(key, value); process.nextTick(callback); diff --git a/packages/db-diskdown/src/store/Combined.ts b/packages/db-diskdown/src/store/Combined.ts index 4505c85f2..26626d8c9 100644 --- a/packages/db-diskdown/src/store/Combined.ts +++ b/packages/db-diskdown/src/store/Combined.ts @@ -101,13 +101,14 @@ export default class Combined implements DiskStore { const newStat = fs.lstatSync(newFile); const oldStat = fs.lstatSync(this._file); const percentage = 100 * (newStat.size / oldStat.size); + const sizeMb = newStat.size / (1024 * 1024); const elapsed = (Date.now() - start) / 1000; - // fs.unlinkSync(this._file); - fs.renameSync(this._file, `${this._file}.old`); + fs.unlinkSync(this._file); + // fs.renameSync(this._file, `${this._file}.old`); fs.renameSync(newFile, this._file); - l.log(`compacted in ${elapsed.toFixed(2)}s, ${(count / 1000).toFixed(2)}k keys, ${(newStat.size / (1024 * 1024)).toFixed(2)}MB (${percentage.toFixed(2)}%)`); + l.log(`compacted in ${elapsed.toFixed(2)}s, ${(count / 1000).toFixed(2)}k keys, ${sizeMb.toFixed(2)}MB (${percentage.toFixed(2)}%)`); } delete (key: Buffer): void { @@ -231,7 +232,7 @@ export default class Combined implements DiskStore { count += indexCount; - if (oldAt === 0) { + if (depth === 0) { const percentage = ` ${(100 * (index + 1) / ENTRY_NUM).toFixed(2)}`; progress(`${percentage.slice(-6)}% compacted, ${count} keys`); diff --git a/yarn.lock b/yarn.lock index 0e42038a0..208c6860d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4920,10 +4920,6 @@ lru-cache@^4.1.2, lru-cache@^4.1.3: pseudomap "^1.0.2" yallist "^2.1.2" -lru_map@^0.3.3: - version "0.3.3" - resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd" - ltgt@~2.2.0: version "2.2.1" resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.2.1.tgz#f35ca91c493f7b73da0e07495304f17b31f87ee5"