浏览代码

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

Book Pauk 3 年之前
父节点
当前提交
02d458d192
共有 5 个文件被更改,包括 24 次插入29 次删除
  1. 7 7
      package-lock.json
  2. 1 1
      package.json
  3. 6 9
      server/core/AsyncExit.js
  4. 10 11
      server/db/JembaConnManager.js
  5. 0 1
      server/index.js

+ 7 - 7
package-lock.json

@@ -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",

+ 1 - 1
package.json

@@ -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",

+ 6 - 9
server/core/AsyncExit.js

@@ -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) {

+ 10 - 11
server/db/JembaConnManager.js

@@ -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,21 +47,23 @@ class JembaConnManager {
             } else {
                 dbConn = new JembaDb();
             }
+            this._db[dbConfig.dbName] = dbConn;
 
             log(`Open "${dbConfig.dbName}" begin`);
             await dbConn.lock({
                 dbPath,
                 create: true,
                 softLock: true,
-                
+
                 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 = {};

+ 0 - 1
server/index.js

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