LevelDb string serialization of keys & values (#209)
* Remove RocksDb interface (or rather, mark as unused) * LevelDb de/serializes to utf8
This commit is contained in:
+11
-11
@@ -6,17 +6,17 @@ cache:
|
||||
directories:
|
||||
- node_modules
|
||||
install:
|
||||
- export ROCKSDB=$HOME/rocksdb-master
|
||||
- pushd $HOME
|
||||
- curl -sLO https://github.com/facebook/rocksdb/archive/master.zip
|
||||
- unzip master.zip
|
||||
- cd rocksdb-master
|
||||
- make shared_lib
|
||||
- popd
|
||||
- export CFLAGS="-I${ROCKSDB}/include/"
|
||||
- export CXXFLAGS="-I${ROCKSDB}/include/"
|
||||
- export LDFLAGS="-L${ROCKSDB} -lrocksdb -lstdc++ -lm -lz"
|
||||
- export LD_LIBRARY_PATH="${ROCKSDB}:/usr/local/lib"
|
||||
# - export ROCKSDB=$HOME/rocksdb-master
|
||||
# - pushd $HOME
|
||||
# - curl -sLO https://github.com/facebook/rocksdb/archive/master.zip
|
||||
# - unzip master.zip
|
||||
# - cd rocksdb-master
|
||||
# - make shared_lib
|
||||
# - popd
|
||||
# - export CFLAGS="-I${ROCKSDB}/include/"
|
||||
# - export CXXFLAGS="-I${ROCKSDB}/include/"
|
||||
# - export LDFLAGS="-L${ROCKSDB} -lrocksdb -lstdc++ -lm -lz"
|
||||
# - export LD_LIBRARY_PATH="${ROCKSDB}:/usr/local/lib"
|
||||
- yarn
|
||||
script:
|
||||
- yarn polkadot-dev-build-travis
|
||||
|
||||
+1
-1
@@ -21,6 +21,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/dev": "^0.20.18",
|
||||
"@polkadot/ts": "^0.1.22"
|
||||
"@polkadot/ts": "^0.1.23"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
"lru_map": "^0.3.3",
|
||||
"mkdirp": "^0.5.1",
|
||||
"nosql-leveldb": "^3.0.1",
|
||||
"rocksdb-node": "jacogr/rocksdb-node#00ebfdbf0462ee615f4f48f1db403fd4df8471ea",
|
||||
"snappy": "^6.0.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,19 @@ import mkdirp from 'mkdirp';
|
||||
import path from 'path';
|
||||
// import snappy from 'snappy';
|
||||
import logger from '@polkadot/util/logger';
|
||||
import bufferToU8a from '@polkadot/util/buffer/toU8a';
|
||||
import u8aToBuffer from '@polkadot/util/u8a/toBuffer';
|
||||
import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
import stringToU8a from '@polkadot/util/u8a/fromUtf8';
|
||||
import u8aToString from '@polkadot/util/u8a/toUtf8';
|
||||
// import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
|
||||
// import assert from '@polkadot/util/assert';
|
||||
// import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
|
||||
const l = logger('db/leveldb');
|
||||
|
||||
// NOTE Looking at the implementation, the getSync does a new Buffer when requested as a Buffer.
|
||||
// With this in mind, we always work with utf8 strings as encoded - serializing/deserializing
|
||||
// on the way in and out
|
||||
|
||||
export default class Level implements BaseDb {
|
||||
private db: LevelDb;
|
||||
|
||||
@@ -62,8 +66,8 @@ export default class Level implements BaseDb {
|
||||
return this._deserializeValue(
|
||||
this.db.getSync(
|
||||
this._serializeKey(key),
|
||||
{ asBuffer: true }
|
||||
)
|
||||
{ asBuffer: false }
|
||||
) as string
|
||||
);
|
||||
} catch (error) {
|
||||
return null;
|
||||
@@ -77,21 +81,24 @@ export default class Level implements BaseDb {
|
||||
);
|
||||
}
|
||||
|
||||
private _deserializeValue (value: Buffer): Uint8Array | null {
|
||||
private _deserializeValue (value: string): Uint8Array | null {
|
||||
return value
|
||||
? bufferToU8a(value)
|
||||
// ? bufferToU8a(
|
||||
// snappy.uncompressSync(value)
|
||||
// )
|
||||
? stringToU8a(value)
|
||||
: null;
|
||||
// return value
|
||||
// ? bufferToU8a(value)
|
||||
// // ? bufferToU8a(
|
||||
// // snappy.uncompressSync(value)
|
||||
// // )
|
||||
// : null;
|
||||
}
|
||||
|
||||
private _serializeKey (key: Uint8Array): string {
|
||||
return u8aToHex(key);
|
||||
return u8aToString(key);
|
||||
}
|
||||
|
||||
private _serializeValue (value: Uint8Array): Buffer {
|
||||
return u8aToBuffer(value);
|
||||
private _serializeValue (value: Uint8Array): string {
|
||||
return u8aToString(value);
|
||||
|
||||
// return snappy.compressSync(
|
||||
// u8aToBuffer(value)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
"rocksdb-node": "jacogr/rocksdb-node#00ebfdbf0462ee615f4f48f1db403fd4df8471ea",
|
||||
|
||||
import { BaseDb, ProgressCb } from '../types';
|
||||
|
||||
import rocksdb, { RocksDb } from 'rocksdb-node';
|
||||
@@ -1285,9 +1285,9 @@
|
||||
typedoc-plugin-markdown "^1.1.13"
|
||||
typescript "^3.0.1"
|
||||
|
||||
"@polkadot/ts@^0.1.22":
|
||||
version "0.1.22"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.22.tgz#8f89d87257ea515bfc79685f5fda70b531a3107b"
|
||||
"@polkadot/ts@^0.1.23":
|
||||
version "0.1.23"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.23.tgz#8515963f514ef62c1fa97b656a18553c01c32530"
|
||||
|
||||
"@types/base-x@*":
|
||||
version "1.0.29"
|
||||
@@ -5328,14 +5328,14 @@ mute-stream@0.0.7, mute-stream@~0.0.4:
|
||||
version "0.0.7"
|
||||
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
|
||||
|
||||
nan@2.11.0, nan@^2.10.0:
|
||||
version "2.11.0"
|
||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.11.0.tgz#574e360e4d954ab16966ec102c0c049fd961a099"
|
||||
|
||||
nan@^2.0.7, nan@^2.3.0:
|
||||
version "2.8.0"
|
||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a"
|
||||
|
||||
nan@^2.10.0:
|
||||
version "2.11.0"
|
||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.11.0.tgz#574e360e4d954ab16966ec102c0c049fd961a099"
|
||||
|
||||
nan@^2.9.2:
|
||||
version "2.10.0"
|
||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"
|
||||
@@ -6596,12 +6596,6 @@ rimraf@2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.
|
||||
dependencies:
|
||||
glob "^7.0.5"
|
||||
|
||||
rocksdb-node@jacogr/rocksdb-node#00ebfdbf0462ee615f4f48f1db403fd4df8471ea:
|
||||
version "1.7.2"
|
||||
resolved "https://codeload.github.com/jacogr/rocksdb-node/tar.gz/00ebfdbf0462ee615f4f48f1db403fd4df8471ea"
|
||||
dependencies:
|
||||
nan "2.11.0"
|
||||
|
||||
run-async@^2.2.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
|
||||
|
||||
Reference in New Issue
Block a user