Revert "diskdown to overwrite values when changed (if space available) (#202)"
This reverts commit 07af959b15.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
"@polkadot/util": "^0.28.23",
|
||||
"@types/mkdirp": "^0.5.2",
|
||||
"abstract-leveldown": "^5.0.0",
|
||||
"lru_map": "^0.3.3",
|
||||
"mkdirp": "^0.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
import { DiskStore, ProgressValue } 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';
|
||||
|
||||
// const LRU_SIZE = 16384;
|
||||
const KEY_LENGTH = 32;
|
||||
|
||||
const l = logger('disk/scatter');
|
||||
@@ -18,11 +20,13 @@ const noop = () =>
|
||||
|
||||
class DiskDown extends AbstractLevelDOWN {
|
||||
_disk: DiskStore;
|
||||
// _store: LRUMap<string, Buffer>;
|
||||
|
||||
constructor (location: string) {
|
||||
super(location);
|
||||
|
||||
this._disk = new Combined(location);
|
||||
// this._store = new LRUMap(LRU_SIZE);
|
||||
}
|
||||
|
||||
compact (progress: (value: ProgressValue) => void): void {
|
||||
@@ -69,6 +73,7 @@ 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);
|
||||
@@ -77,6 +82,9 @@ class DiskDown extends AbstractLevelDOWN {
|
||||
_get (key: Buffer, options: any, callback: Function) {
|
||||
l.debug(() => ['_get', key.toString('hex')]);
|
||||
|
||||
// FIXME _If_ LRU is re-instated, it needs to get set once a value is
|
||||
// retrieved from disk. (As of now, not needed since removed)
|
||||
// const value = this._store.get(key.toString()) || this._disk.get(key);
|
||||
const value = this._disk.get(key);
|
||||
|
||||
if (isUndefined(value)) {
|
||||
@@ -90,6 +98,7 @@ 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);
|
||||
|
||||
@@ -320,20 +320,14 @@ export default class Combined implements DiskStore {
|
||||
return result;
|
||||
}
|
||||
|
||||
private _extractValueInfo (keyValue: Buffer): { valueAt: number, valueLength: number } {
|
||||
return {
|
||||
valueLength: keyValue.readUIntBE(KEY_SIZE, UINT_SIZE),
|
||||
valueAt: keyValue.readUIntBE(KEY_SIZE + UINT_SIZE, UINT_SIZE)
|
||||
};
|
||||
}
|
||||
|
||||
private _readValue (key: Buffer, keyAt: number, keyValue: Buffer): Value {
|
||||
l.debug(() => ['readValue', debug({ key, keyAt, keyValue })]);
|
||||
|
||||
const { valueAt, valueLength } = this._extractValueInfo(keyValue);
|
||||
const length = keyValue.readUIntBE(KEY_SIZE, UINT_SIZE);
|
||||
const valueAt = keyValue.readUIntBE(KEY_SIZE + UINT_SIZE, UINT_SIZE);
|
||||
const value = Buffer.alloc(length);
|
||||
|
||||
fs.readSync(this._fd, value, 0, valueLength, valueAt);
|
||||
fs.readSync(this._fd, value, 0, length, valueAt);
|
||||
|
||||
return {
|
||||
key,
|
||||
@@ -355,13 +349,8 @@ export default class Combined implements DiskStore {
|
||||
private _writeValue (key: Buffer, keyAt: number, keyValue: Buffer, value: Buffer): Value {
|
||||
l.debug(() => ['writeValue', debug({ keyAt, keyValue, value })]);
|
||||
|
||||
let { valueAt, valueLength } = this._extractValueInfo(keyValue);
|
||||
|
||||
if (valueLength < value.length) {
|
||||
const stats = fs.fstatSync(this._fd);
|
||||
|
||||
valueAt = stats.size;
|
||||
}
|
||||
const stats = fs.fstatSync(this._fd);
|
||||
const valueAt = stats.size;
|
||||
|
||||
fs.writeSync(this._fd, value, 0, value.length, valueAt);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user