Skip to content

Commit

Permalink
Vacuum fix. Release 0.16.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Sep 4, 2024
1 parent c830907 commit ed2e881
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 11 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ async function stats(
ledgerSetCount++;
} else if (entry.operation === KVOperation.DELETE) {
ledgerDeleteCount++;
} else {
ledgerInvalidCount++;
}
}
} catch (_e) {
Expand All @@ -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("");
Expand Down
5 changes: 4 additions & 1 deletion src/lib/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand Down

0 comments on commit ed2e881

Please sign in to comment.