@iobroker/db-objects-jsonl 4.0.19 → 4.0.23
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.
|
@@ -20,6 +20,68 @@ const fs = require('fs');
|
|
|
20
20
|
const os = require('os');
|
|
21
21
|
const { tools } = require('@iobroker/js-controller-common');
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Normalizes options for the JsonlDB
|
|
25
|
+
* @param {Record<string, any> | undefined} conf The jsonlOptions options from iobroker.json
|
|
26
|
+
* @returns {import("@alcalzone/jsonl-db").JsonlDBOptions<any>}
|
|
27
|
+
*/
|
|
28
|
+
function normalizeJsonlOptions(conf = {}) {
|
|
29
|
+
/** @type {import("@alcalzone/jsonl-db").JsonlDBOptions<any>} */
|
|
30
|
+
const ret = {
|
|
31
|
+
autoCompress: {
|
|
32
|
+
sizeFactor: 2,
|
|
33
|
+
sizeFactorMinimumSize: 25000
|
|
34
|
+
},
|
|
35
|
+
ignoreReadErrors: true,
|
|
36
|
+
throttleFS: {
|
|
37
|
+
intervalMs: 60000,
|
|
38
|
+
maxBufferedCommands: 1000
|
|
39
|
+
},
|
|
40
|
+
lockfile: {
|
|
41
|
+
// 5 retries starting at 250ms add up to just above 2s,
|
|
42
|
+
// so the DB has 3 more seconds to load all data if it wants to stay within the 5s connectionTimeout
|
|
43
|
+
retries: 5,
|
|
44
|
+
retryMinTimeoutMs: 250,
|
|
45
|
+
// This makes sure the DB stays locked for maximum 2s even if the process crashes
|
|
46
|
+
staleMs: 2000
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Be really careful what we allow here. Incorrect settings may cause problems in production.
|
|
51
|
+
if (tools.isObject(conf.autoCompress)) {
|
|
52
|
+
const ac = conf.autoCompress;
|
|
53
|
+
// Letting the DB grow more than 100x is risky
|
|
54
|
+
if (typeof ac.sizeFactor === 'number' && ac.sizeFactor >= 2 && ac.sizeFactor <= 100) {
|
|
55
|
+
ret.autoCompress.sizeFactor = ac.sizeFactor;
|
|
56
|
+
}
|
|
57
|
+
// Also we should definitely compress once the DB has reached 100k lines or it might grow too big
|
|
58
|
+
if (
|
|
59
|
+
typeof ac.sizeFactorMinimumSize === 'number' &&
|
|
60
|
+
ac.sizeFactorMinimumSize >= 0 &&
|
|
61
|
+
ac.sizeFactorMinimumSize <= 100000
|
|
62
|
+
) {
|
|
63
|
+
ret.autoCompress.sizeFactorMinimumSize = ac.sizeFactorMinimumSize;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (tools.isObject(conf.throttleFS)) {
|
|
67
|
+
const thr = conf.throttleFS;
|
|
68
|
+
// Don't write more often than every second and write at least once every hour
|
|
69
|
+
if (typeof thr.intervalMs === 'number' && thr.intervalMs >= 1000 && thr.intervalMs <= 3600000) {
|
|
70
|
+
ret.throttleFS.intervalMs = thr.intervalMs;
|
|
71
|
+
}
|
|
72
|
+
// Don't keep too much in memory - 100k changes are more than enough
|
|
73
|
+
if (
|
|
74
|
+
typeof thr.maxBufferedCommands === 'number' &&
|
|
75
|
+
thr.maxBufferedCommands >= 0 &&
|
|
76
|
+
thr.maxBufferedCommands <= 100000
|
|
77
|
+
) {
|
|
78
|
+
ret.throttleFS.maxBufferedCommands = thr.maxBufferedCommands;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return ret;
|
|
83
|
+
}
|
|
84
|
+
|
|
23
85
|
/**
|
|
24
86
|
* This class inherits InMemoryFileDB class and adds all relevant logic for objects
|
|
25
87
|
* including the available methods for use by js-controller directly
|
|
@@ -32,26 +94,7 @@ class ObjectsInMemoryJsonlDB extends ObjectsInMemoryFileDB {
|
|
|
32
94
|
backupDirName: 'backup-objects'
|
|
33
95
|
};
|
|
34
96
|
|
|
35
|
-
|
|
36
|
-
const jsonlOptions = settings.connection.jsonlOptions || {
|
|
37
|
-
autoCompress: {
|
|
38
|
-
sizeFactor: 2,
|
|
39
|
-
sizeFactorMinimumSize: 25000
|
|
40
|
-
},
|
|
41
|
-
ignoreReadErrors: true,
|
|
42
|
-
throttleFS: {
|
|
43
|
-
intervalMs: 60000,
|
|
44
|
-
maxBufferedCommands: 1000
|
|
45
|
-
},
|
|
46
|
-
lockfile: {
|
|
47
|
-
// 5 retries starting at 250ms add up to just above 2s,
|
|
48
|
-
// so the DB has 3 more seconds to load all data if it wants to stay within the 5s connectionTimeout
|
|
49
|
-
retries: 5,
|
|
50
|
-
retryMinTimeoutMs: 250,
|
|
51
|
-
// This makes sure the DB stays locked for maximum 2s even if the process crashes
|
|
52
|
-
staleMs: 2000
|
|
53
|
-
}
|
|
54
|
-
};
|
|
97
|
+
const jsonlOptions = normalizeJsonlOptions(settings.connection.jsonlOptions);
|
|
55
98
|
settings.jsonlDB = {
|
|
56
99
|
fileName: 'objects.jsonl'
|
|
57
100
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/db-objects-jsonl",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.23",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=12.0.0"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@alcalzone/jsonl-db": "~2.5.1",
|
|
9
|
-
"@iobroker/db-base": "4.0.
|
|
10
|
-
"@iobroker/db-objects-file": "4.0.
|
|
11
|
-
"@iobroker/db-objects-redis": "4.0.
|
|
9
|
+
"@iobroker/db-base": "4.0.23",
|
|
10
|
+
"@iobroker/db-objects-file": "4.0.23",
|
|
11
|
+
"@iobroker/db-objects-redis": "4.0.23",
|
|
12
12
|
"deep-clone": "^3.0.3",
|
|
13
13
|
"fs-extra": "^10.0.0"
|
|
14
14
|
},
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"lib/",
|
|
38
38
|
"index.js"
|
|
39
39
|
],
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "ea1a72ac2d74317ad16234f7aeac90632374614c"
|
|
41
41
|
}
|