Миграция "jembadb" => "^2.3.0"

This commit is contained in:
Book Pauk
2022-03-29 15:49:48 +07:00
parent a349d8af68
commit 02d458d192
5 changed files with 24 additions and 29 deletions

14
package-lock.json generated
View File

@@ -22,7 +22,7 @@
"got": "^11.8.2",
"he": "^1.2.0",
"iconv-lite": "^0.6.3",
"jembadb": "^2.2.0",
"jembadb": "^2.3.0",
"localforage": "^1.10.0",
"lodash": "^4.17.21",
"minimist": "^1.2.5",
@@ -6379,9 +6379,9 @@
}
},
"node_modules/jembadb": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-2.2.0.tgz",
"integrity": "sha512-1ddK0F4hAvDPmiSqPkn8GMbG7O+mMTbEG8oSOM+XczW1gdpChKt699ewUdFlMmTAQsx4XC43WDfVZzulc4a+3w==",
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-2.3.0.tgz",
"integrity": "sha512-Jrvbe+4a3ULZvYmM6VnIK6mGFegPELbAppSYTTvPUeMmndNVOAVr1RDHKEiV8ccLanv1xWnJYiCo1mdnepR/Cg==",
"engines": {
"node": ">=14.4.0"
}
@@ -16229,9 +16229,9 @@
}
},
"jembadb": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-2.2.0.tgz",
"integrity": "sha512-1ddK0F4hAvDPmiSqPkn8GMbG7O+mMTbEG8oSOM+XczW1gdpChKt699ewUdFlMmTAQsx4XC43WDfVZzulc4a+3w=="
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-2.3.0.tgz",
"integrity": "sha512-Jrvbe+4a3ULZvYmM6VnIK6mGFegPELbAppSYTTvPUeMmndNVOAVr1RDHKEiV8ccLanv1xWnJYiCo1mdnepR/Cg=="
},
"jest-worker": {
"version": "27.3.1",

View File

@@ -60,7 +60,7 @@
"got": "^11.8.2",
"he": "^1.2.0",
"iconv-lite": "^0.6.3",
"jembadb": "^2.2.0",
"jembadb": "^2.3.0",
"localforage": "^1.10.0",
"lodash": "^4.17.21",
"minimist": "^1.2.5",

View File

@@ -1,27 +1,26 @@
let instance = null;
const defaultTimeout = 15*1000;//15 sec
const exitSignals = ['SIGINT', 'SIGTERM', 'SIGBREAK', 'SIGHUP', 'uncaughtException', 'SIGUSR2'];
const exitSignals = ['SIGINT', 'SIGTERM', 'SIGBREAK', 'SIGHUP', 'uncaughtException'];
//singleton
class AsyncExit {
constructor() {
constructor(signals = exitSignals, codeOnSignal = 2) {
if (!instance) {
this.onSignalCallbacks = new Map();
this.callbacks = new Map();
this.afterCallbacks = new Map();
this.exitTimeout = defaultTimeout;
this.inited = false;
this._init(signals, codeOnSignal);
instance = this;
}
return instance;
}
init(signals = exitSignals, codeOnSignal = 2) {
if (this.inited)
throw new Error('AsyncExit: initialized already');
_init(signals, codeOnSignal) {
const runSingalCallbacks = async(signal) => {
for (const signalCallback of this.onSignalCallbacks.keys()) {
try {
@@ -38,8 +37,6 @@ class AsyncExit {
this.exit(codeOnSignal);
});
}
this.inited = true;
}
onSignal(signalCallback) {

View File

@@ -14,6 +14,7 @@ class JembaConnManager {
constructor() {
if (!instance) {
this.inited = false;
this._db = {};
instance = this;
}
@@ -28,6 +29,8 @@ class JembaConnManager {
this.config = config;
this._db = {};
ayncExit.add(this.close.bind(this));
for (const dbConfig of this.config.jembaDb) {
const dbPath = `${this.config.dataDir}/db/${dbConfig.dbName}`;
@@ -44,6 +47,7 @@ class JembaConnManager {
} else {
dbConn = new JembaDb();
}
this._db[dbConfig.dbName] = dbConn;
log(`Open "${dbConfig.dbName}" begin`);
await dbConn.lock({
@@ -54,11 +58,12 @@ class JembaConnManager {
tableDefaults: {
cacheSize: dbConfig.cacheSize,
compressed: dbConfig.compressed,
forceFileClosing: dbConfig.forceFileClosing
forceFileClosing: dbConfig.forceFileClosing,
typeCompatMode: true,
},
});
if (dbConfig.openAll) {
if (dbConfig.openAll || forceAutoRepair || dbConfig.autoRepair) {
try {
await dbConn.openAll();
} catch(e) {
@@ -87,21 +92,15 @@ class JembaConnManager {
if (applied.length)
log(`${applied.length} migrations applied to "${dbConfig.dbName}"`);
}
this._db[dbConfig.dbName] = dbConn;
}
ayncExit.add(this.close.bind(this));
this.inited = true;
}
async close() {
if (!this.inited)
return;
for (const dbConfig of this.config.jembaDb) {
await this._db[dbConfig.dbName].unlock();
if (this._db[dbConfig.dbName])
await this._db[dbConfig.dbName].unlock();
}
this._db = {};

View File

@@ -8,7 +8,6 @@ const http = require('http');
const WebSocket = require ('ws');
const ayncExit = new (require('./core/AsyncExit'))();
ayncExit.init();
let log = null;