Skip to content

Commit ed2e881

Browse files
committed
Vacuum fix. Release 0.16.4.
1 parent c830907 commit ed2e881

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## 0.16.4
2+
3+
- Refactor of file locks during a vacuum
4+
5+
## 0.16.3
6+
7+
- Added `KV.defer(promiseToHandle, [errorHandler], [timeoutMs])` method to allow
8+
non-awaited promises to be tracked and settled during `KV.close()`.
9+
- `errorHandler` (optional): A function to handle errors that occur during
10+
promise resolution/rejection. If not provided, errors will silently ignored.
11+
- `timeoutMs` (optional): A timeout (in milliseconds) for promise resolution.
12+
If the promise doesn't settle within this time during `KV.close()`, a
13+
warning will be logged. Defaults to 5000ms.
14+
- Fix cli tool not being able to open any database after a failed open
15+
- Code refactors
16+
117
## 0.16.3
218

319
- Added `KV.defer(promiseToHandle, [errorHandler], [timeoutMs])` method to allow

deno.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
{
22
"name": "@cross/kv",
3-
"version": "0.16.3",
3+
"version": "0.16.4",
44
"exports": {
55
".": "./mod.ts",
66
"./cli": "./src/cli/mod.ts"
77
},
8+
"lint": {
9+
"rules": {
10+
"exclude": [
11+
"no-node-globals"
12+
]
13+
}
14+
},
815
"imports": {
916
"@cross/fs": "jsr:@cross/fs@^0.1.11",
1017
"@cross/runtime": "jsr:@cross/runtime@^1.0.0",
1118
"@cross/test": "jsr:@cross/test@^0.0.9",
12-
"@cross/utils": "jsr:@cross/utils@^0.13.0",
13-
"@std/assert": "jsr:@std/assert@^0.226.0",
14-
"@std/path": "jsr:@std/path@^0.225.1",
19+
"@cross/utils": "jsr:@cross/utils@^0.14.0",
20+
"@std/assert": "jsr:@std/assert@^1.0.4",
21+
"@std/path": "jsr:@std/path@^1.0.4",
1522
"cbor-x": "npm:cbor-x@^1.5.9",
1623
"ohash": "npm:ohash@^1.1.3"
1724
},

src/cli/commands/stats.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ async function stats(
7676
ledgerSetCount++;
7777
} else if (entry.operation === KVOperation.DELETE) {
7878
ledgerDeleteCount++;
79+
} else {
80+
ledgerInvalidCount++;
7981
}
8082
}
8183
} catch (_e) {
@@ -89,7 +91,6 @@ async function stats(
8991
console.log(Colors.dim(` Delete Ops: `), ledgerDeleteCount);
9092
if (ledgerInvalidCount) {
9193
console.log(Colors.red(` Invalid Ops: `), ledgerInvalidCount);
92-
console.error(" Counting aborted due to invalid operations");
9394
}
9495

9596
console.log("");

src/lib/ledger.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ export class KVLedger {
461461
);
462462
await tempLedger.open(true);
463463

464+
// Lock the temporary ledger to prevent multiple vacuums against the same tempfile
465+
// - Will be unlocked in the finally clause
466+
await tempLedger.lock();
467+
464468
// 5. Append valid transactions to the new file.
465469
for (const validTransaction of validTransactions) {
466470
const transaction = await this.rawGetTransaction(
@@ -478,7 +482,6 @@ export class KVLedger {
478482
this.prefetch.clear();
479483

480484
// 7. Replace Original File
481-
// - The lock flag is now set independently, no need to unlock from this point on
482485
await unlink(this.dataPath);
483486
await rename(tempFilePath, this.dataPath);
484487
ledgerIsReplaced = true;

0 commit comments

Comments
 (0)