diff --git a/CHANGELOG.md b/CHANGELOG.md index 391139e..11007fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +## 0.16.4 + +- Refactor of file locks during a vacuum + +## 0.16.3 + +- Added `KV.defer(promiseToHandle, [errorHandler], [timeoutMs])` method to allow + non-awaited promises to be tracked and settled during `KV.close()`. + - `errorHandler` (optional): A function to handle errors that occur during + promise resolution/rejection. If not provided, errors will silently ignored. + - `timeoutMs` (optional): A timeout (in milliseconds) for promise resolution. + If the promise doesn't settle within this time during `KV.close()`, a + warning will be logged. Defaults to 5000ms. +- Fix cli tool not being able to open any database after a failed open +- Code refactors + ## 0.16.3 - Added `KV.defer(promiseToHandle, [errorHandler], [timeoutMs])` method to allow diff --git a/deno.json b/deno.json index a8496ef..5c3a39b 100644 --- a/deno.json +++ b/deno.json @@ -1,17 +1,24 @@ { "name": "@cross/kv", - "version": "0.16.3", + "version": "0.16.4", "exports": { ".": "./mod.ts", "./cli": "./src/cli/mod.ts" }, + "lint": { + "rules": { + "exclude": [ + "no-node-globals" + ] + } + }, "imports": { "@cross/fs": "jsr:@cross/fs@^0.1.11", "@cross/runtime": "jsr:@cross/runtime@^1.0.0", "@cross/test": "jsr:@cross/test@^0.0.9", - "@cross/utils": "jsr:@cross/utils@^0.13.0", - "@std/assert": "jsr:@std/assert@^0.226.0", - "@std/path": "jsr:@std/path@^0.225.1", + "@cross/utils": "jsr:@cross/utils@^0.14.0", + "@std/assert": "jsr:@std/assert@^1.0.4", + "@std/path": "jsr:@std/path@^1.0.4", "cbor-x": "npm:cbor-x@^1.5.9", "ohash": "npm:ohash@^1.1.3" }, diff --git a/src/cli/commands/stats.ts b/src/cli/commands/stats.ts index c6d8264..a7b1a09 100644 --- a/src/cli/commands/stats.ts +++ b/src/cli/commands/stats.ts @@ -76,6 +76,8 @@ async function stats( ledgerSetCount++; } else if (entry.operation === KVOperation.DELETE) { ledgerDeleteCount++; + } else { + ledgerInvalidCount++; } } } catch (_e) { @@ -89,7 +91,6 @@ async function stats( console.log(Colors.dim(` Delete Ops: `), ledgerDeleteCount); if (ledgerInvalidCount) { console.log(Colors.red(` Invalid Ops: `), ledgerInvalidCount); - console.error(" Counting aborted due to invalid operations"); } console.log(""); diff --git a/src/lib/ledger.ts b/src/lib/ledger.ts index 12d0463..ceaede0 100644 --- a/src/lib/ledger.ts +++ b/src/lib/ledger.ts @@ -461,6 +461,10 @@ export class KVLedger { ); await tempLedger.open(true); + // Lock the temporary ledger to prevent multiple vacuums against the same tempfile + // - Will be unlocked in the finally clause + await tempLedger.lock(); + // 5. Append valid transactions to the new file. for (const validTransaction of validTransactions) { const transaction = await this.rawGetTransaction( @@ -478,7 +482,6 @@ export class KVLedger { this.prefetch.clear(); // 7. Replace Original File - // - The lock flag is now set independently, no need to unlock from this point on await unlink(this.dataPath); await rename(tempFilePath, this.dataPath); ledgerIsReplaced = true;