* Cleanup shard files by removing them from disk. * Coordinator-only: throws error if not coordinator to prevent race conditions. * Idempotent: returns early if already cleaned.
()
| 396 | * Idempotent: returns early if already cleaned. |
| 397 | */ |
| 398 | cleanup() { |
| 399 | if (!this.isCoordinator()) { |
| 400 | throw new Error('cleanup() can only be called by coordinator'); |
| 401 | } |
| 402 | |
| 403 | if (this.#state === 'cleaned') { |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | this.shardFiles() |
| 408 | .filter(f => fs.existsSync(f)) |
| 409 | .forEach(f => { |
| 410 | fs.unlinkSync(f); |
| 411 | }); |
| 412 | |
| 413 | this.#state = 'cleaned'; |
| 414 | } |
| 415 | |
| 416 | get stats() { |
| 417 | // When finalized, count all shard files from filesystem (for multi-process scenarios) |
no test coverage detected