Remove db-diskdown LRU (#198)

This commit is contained in:
Jaco Greeff
2018-08-28 20:36:44 +02:00
committed by GitHub
parent ff78c02eb5
commit 219f12a65b
4 changed files with 6 additions and 18 deletions
-1
View File
@@ -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": {
+1 -9
View File
@@ -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<string, Buffer>;
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);
+5 -4
View File
@@ -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`);
-4
View File
@@ -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"