Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
connect() {
if (this._db) return Promise.resolve(this._db);
// Ensure existence of directory.
if (!fs.existsSync(this._databaseDir)){
fs.mkdirSync(this._databaseDir);
}
let numDbs = 1;
for (const { /** @type {LMDBBackend} */ backend, upgradeCondition } of this._objectStoreBackends) {
numDbs += 1 + backend.indices.size;
}
this._db = new lmdb.Env();
this._db.open({
path: this._databaseDir,
mapSize: this._options.maxDbSize || (1024*1024*5), // 5MB default
maxDbs: (this._options.maxDbs + 1) || numDbs, // default, always add 1 for the internal db
useWritemap: this._options.useWritemap || false,
});
// Check if resize is needed.
if (this.autoResize && this.needsResize()) {
this.doResize();
}
this._mainDb = this._db.openDbi({
name: null,
create: true
});
const url = require('url')
const WSS = require('ws').Server;
const express = require('express')
const fs = require('fs')
const kclient = new kafka.Client()
const app = express()
const server = require('http').createServer(app)
const wss = new WSS({server, perfMessageDeflate: false})
app.use('/sp', express.static(__dirname + '/public'))
// This is important so we can hot-resume when the server starts without
// needing to read the entire kafka log. A file would almost be good enough,
// but we need to atomically write to it. So, this is easier.
const dbenv = new lmdb.Env()
if (!fs.existsSync('snapshot')) fs.mkdirSync('snapshot')
dbenv.open({ path: 'snapshot', mapSize: 100*1024*1024 })
const snapshotdb = dbenv.openDbi({create: true})
const randInt = max => (Math.random() * max) | 0
const loadSnapshot = () => {
// Read a snapshot from the database if we can.
const txn = dbenv.beginTxn({readOnly: true})
const _version = txn.getNumber(snapshotdb, 'version')
if (_version != null) {
const data = txn.getBinary(snapshotdb, 'current')
assert(data)
constructor(path) {
debug('Opening storage at ' + path);
mkdirp.sync(path);
this._env = new lmdb.Env();
this._env.open({
path: path,
});
this._db = this._env.openDbi({
name: 'shared',
create: true
});
}
constructor (base: string, name: string, options?: BaseDbOptions) {
this._env = new lmdb.Env();
this._path = path.join(base, name);
this._rtxn = null;
this._wtxn = null;
mkdirp.sync(this._path);
const dbsize = this.size(true);
const mapSize = Math.ceil(1 + (dbsize / GB)) * GB;
l.debug(() => `Current mapsize set to ${(mapSize / GB).toFixed(1)}GB`);
this._env.open({
path: this._path,
mapSize
});
}
var openDatabase = function () {
_this._databaseEnvironment = new lmdb.Env();
_this._databaseEnvironment.open({
//name: this._name,
path: _this._path
});
};
exports.open = function(dbPath, readOnly) {
var db = {};
db.env = new lmdb.Env();
db.env.open({
path: dbPath,
maxDbs: 15,
mapSize: 268435456 * 4096,
maxReaders: 126,
noMetaSync: true,
noSync: true,
readOnly: readOnly
});
db.addressesMap = db.env.openDbi({
name: 'addressesMap',
create: !readOnly
});
db.addresses = db.env.openDbi({
name: 'addresses',
create: !readOnly