@wowoengine/sawitdb 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -11
- package/bin/sawit-server.js +8 -1
- package/cli/benchmark.js +145 -0
- package/cli/local.js +83 -20
- package/cli/remote.js +50 -11
- package/cli/test.js +165 -0
- package/docs/index.html +580 -325
- package/package.json +1 -1
- package/src/SawitServer.js +27 -12
- package/src/WowoEngine.js +619 -129
- package/src/modules/BTreeIndex.js +64 -23
- package/src/modules/Pager.js +212 -6
- package/src/modules/QueryParser.js +93 -50
- package/src/modules/WAL.js +340 -0
package/package.json
CHANGED
package/src/SawitServer.js
CHANGED
|
@@ -35,6 +35,8 @@ class SawitServer {
|
|
|
35
35
|
|
|
36
36
|
this._log('info', `Data directory: ${this.dataDir}`);
|
|
37
37
|
this._log('info', `Max connections: ${this.maxConnections}`);
|
|
38
|
+
|
|
39
|
+
this.walConfig = config.wal || { enabled: false };
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
_validatePort(port) {
|
|
@@ -65,7 +67,7 @@ class SawitServer {
|
|
|
65
67
|
|
|
66
68
|
this.server.listen(this.port, this.host, () => {
|
|
67
69
|
console.log(`╔══════════════════════════════════════════════════╗`);
|
|
68
|
-
console.log(`║ 🌴 SawitDB Server - Version 2.
|
|
70
|
+
console.log(`║ 🌴 SawitDB Server - Version 2.5.0 ║`);
|
|
69
71
|
console.log(`╚══════════════════════════════════════════════════╝`);
|
|
70
72
|
console.log(`[Server] Listening on ${this.host}:${this.port}`);
|
|
71
73
|
console.log(`[Server] Protocol: sawitdb://${this.host}:${this.port}/[database]`);
|
|
@@ -85,6 +87,17 @@ class SawitServer {
|
|
|
85
87
|
client.destroy();
|
|
86
88
|
}
|
|
87
89
|
|
|
90
|
+
// Close all open databases to release file locks
|
|
91
|
+
for (const [name, db] of this.databases) {
|
|
92
|
+
try {
|
|
93
|
+
console.log(`[Server] Closing database: ${name}`);
|
|
94
|
+
db.close();
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.error(`[Server] Error closing database ${name}:`, e.message);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.databases.clear();
|
|
100
|
+
|
|
88
101
|
// Close server
|
|
89
102
|
if (this.server) {
|
|
90
103
|
this.server.close(() => {
|
|
@@ -181,7 +194,7 @@ class SawitServer {
|
|
|
181
194
|
this._sendResponse(socket, {
|
|
182
195
|
type: 'welcome',
|
|
183
196
|
message: 'SawitDB Server',
|
|
184
|
-
version: '2.
|
|
197
|
+
version: '2.5.0',
|
|
185
198
|
protocol: 'sawitdb'
|
|
186
199
|
});
|
|
187
200
|
}
|
|
@@ -402,29 +415,30 @@ class SawitServer {
|
|
|
402
415
|
}
|
|
403
416
|
const dbName = parts[2];
|
|
404
417
|
|
|
405
|
-
// Reuse existing logic
|
|
406
|
-
const payload = { database: dbName };
|
|
407
|
-
// We need to adapt the existing _handleDropDatabase to generic usage or call it.
|
|
408
|
-
// _handleDropDatabase sends its own response. We want query_result format preferably for consistency in CLI?
|
|
409
|
-
// The existing _handleDropDatabase sends 'drop_success'. CLI might not print that as a query result string.
|
|
410
|
-
// Let's reimplement logic here for 'query' flow to ensure 'query_result' type.
|
|
411
|
-
|
|
412
418
|
try {
|
|
413
419
|
const dbPath = path.join(this.dataDir, `${dbName}.sawit`);
|
|
414
420
|
if (!fs.existsSync(dbPath)) {
|
|
415
421
|
return this._sendError(socket, `Wilayah '${dbName}' tidak ditemukan.`);
|
|
416
422
|
}
|
|
417
423
|
|
|
424
|
+
// FIX: Close database before deletion to release file lock
|
|
418
425
|
if (this.databases.has(dbName)) {
|
|
426
|
+
const db = this.databases.get(dbName);
|
|
427
|
+
try { db.close(); } catch (e) { }
|
|
419
428
|
this.databases.delete(dbName);
|
|
420
429
|
}
|
|
421
430
|
|
|
422
|
-
|
|
423
|
-
|
|
431
|
+
// If current user is in this db, kick them out
|
|
424
432
|
if (context.currentDatabase === dbName) {
|
|
425
433
|
context.setDatabase(null);
|
|
426
434
|
}
|
|
427
435
|
|
|
436
|
+
try { fs.unlinkSync(dbPath); } catch (e) {
|
|
437
|
+
// Retry once after short delay if locked? Or just throw.
|
|
438
|
+
// If close() works, this should succeed.
|
|
439
|
+
throw e;
|
|
440
|
+
}
|
|
441
|
+
|
|
428
442
|
return this._sendResponse(socket, {
|
|
429
443
|
type: 'query_result',
|
|
430
444
|
result: `Wilayah '${dbName}' telah hangus terbakar.`,
|
|
@@ -531,6 +545,7 @@ class SawitServer {
|
|
|
531
545
|
|
|
532
546
|
// Close database if open
|
|
533
547
|
if (this.databases.has(database)) {
|
|
548
|
+
this.databases.get(database).close(); // Fix: Close first
|
|
534
549
|
this.databases.delete(database);
|
|
535
550
|
}
|
|
536
551
|
|
|
@@ -555,7 +570,7 @@ class SawitServer {
|
|
|
555
570
|
_getOrCreateDatabase(name) {
|
|
556
571
|
if (!this.databases.has(name)) {
|
|
557
572
|
const dbPath = path.join(this.dataDir, `${name}.sawit`);
|
|
558
|
-
const db = new SawitDB(dbPath);
|
|
573
|
+
const db = new SawitDB(dbPath, { wal: this.walConfig });
|
|
559
574
|
this.databases.set(name, db);
|
|
560
575
|
}
|
|
561
576
|
return this.databases.get(name);
|