sliftutils 1.4.74 → 1.4.76
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.
package/index.d.ts
CHANGED
|
@@ -1547,7 +1547,7 @@ declare module "sliftutils/storage/BulkDatabase2/mergeMarkers" {
|
|
|
1547
1547
|
}): Promise<void>;
|
|
1548
1548
|
export declare function readDeleteMarkers(storage: FileStorage, allNames: string[]): Promise<DeleteMarker[]>;
|
|
1549
1549
|
export declare function markerExclusions(markers: DeleteMarker[]): Set<string>;
|
|
1550
|
-
export declare function processDeleteMarkers(storage: FileStorage, markers: DeleteMarker[], allNames: string[]): Promise<void>;
|
|
1550
|
+
export declare function processDeleteMarkers(name: string, storage: FileStorage, markers: DeleteMarker[], allNames: string[]): Promise<void>;
|
|
1551
1551
|
|
|
1552
1552
|
}
|
|
1553
1553
|
|
package/package.json
CHANGED
|
@@ -573,7 +573,7 @@ export class BulkDatabaseBase<T extends { key: string }> {
|
|
|
573
573
|
const storage = await this.storage();
|
|
574
574
|
const names = await storage.getKeys();
|
|
575
575
|
const markers = await readDeleteMarkers(storage, names);
|
|
576
|
-
if (markers.length) await processDeleteMarkers(storage, markers, names);
|
|
576
|
+
if (markers.length) await processDeleteMarkers(this.name, storage, markers, names);
|
|
577
577
|
});
|
|
578
578
|
|
|
579
579
|
private async writeBulkFile(rows: Record<string, unknown>[]): Promise<void> {
|
|
@@ -396,7 +396,7 @@ async function executeBatch(
|
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
|
-
log(`${magenta("input")} ${sourceNames[si]}: ${fmtBytes(bytesRead)} read`);
|
|
399
|
+
log(`${magenta("input")} ${si + 1}/${sources.length} ${sourceNames[si]}: ${fmtBytes(bytesRead)} read`);
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
// Assemble + write each output file in this batch.
|
|
@@ -408,7 +408,7 @@ async function executeBatch(
|
|
|
408
408
|
const { name, size } = await writeFile(fileBuf);
|
|
409
409
|
const sourcesNamed = new Map<string, number>();
|
|
410
410
|
for (const [si, n] of plan.sourceCounts) sourcesNamed.set(sourceNames[si], n);
|
|
411
|
-
log(`${magenta("output")}: ${formatNumber(plan.keys.length)} rows from ${plan.sourceCounts.size} input(s), ${fmtBytes(size)}`);
|
|
411
|
+
log(`${magenta("output")} ${fi + 1}/${plans.length}: ${formatNumber(plan.keys.length)} rows from ${plan.sourceCounts.size} input(s), ${fmtBytes(size)}`);
|
|
412
412
|
outputs.push({ name, minKey: plan.minKey, maxKey: plan.maxKey, rowCount: plan.keys.length, size, sources: sourcesNamed });
|
|
413
413
|
}
|
|
414
414
|
return outputs;
|
|
@@ -12,4 +12,4 @@ export declare function writeDeleteMarker(storage: FileStorage, config: {
|
|
|
12
12
|
}): Promise<void>;
|
|
13
13
|
export declare function readDeleteMarkers(storage: FileStorage, allNames: string[]): Promise<DeleteMarker[]>;
|
|
14
14
|
export declare function markerExclusions(markers: DeleteMarker[]): Set<string>;
|
|
15
|
-
export declare function processDeleteMarkers(storage: FileStorage, markers: DeleteMarker[], allNames: string[]): Promise<void>;
|
|
15
|
+
export declare function processDeleteMarkers(name: string, storage: FileStorage, markers: DeleteMarker[], allNames: string[]): Promise<void>;
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
// the marker itself (kept around briefly so a concurrent reader still excludes the files consistently).
|
|
16
16
|
|
|
17
17
|
import type { FileStorage } from "../FileFolderAPI";
|
|
18
|
+
import { blue, magenta } from "socket-function/src/formatting/logColors";
|
|
18
19
|
|
|
19
20
|
const MARKER_PREFIX = ".delete-marker_";
|
|
20
21
|
const MARKER_GRACE_MS = 5 * 60 * 1000;
|
|
@@ -67,7 +68,7 @@ export function markerExclusions(markers: DeleteMarker[]): Set<string> {
|
|
|
67
68
|
|
|
68
69
|
// Act on each marker (see file header). Idempotent and best-effort: every removal is guarded, so two
|
|
69
70
|
// processes (or two reads) running this at once just race to the same already-correct end state.
|
|
70
|
-
export async function processDeleteMarkers(storage: FileStorage, markers: DeleteMarker[], allNames: string[]): Promise<void> {
|
|
71
|
+
export async function processDeleteMarkers(name: string, storage: FileStorage, markers: DeleteMarker[], allNames: string[]): Promise<void> {
|
|
71
72
|
const present = new Set(allNames);
|
|
72
73
|
const now = Date.now();
|
|
73
74
|
for (const marker of markers) {
|
|
@@ -81,9 +82,12 @@ export async function processDeleteMarkers(storage: FileStorage, markers: Delete
|
|
|
81
82
|
}
|
|
82
83
|
const replacedExists = marker.replacedBy.length > 0 && marker.replacedBy.every(n => present.has(n));
|
|
83
84
|
if (replacedExists || now - marker.time > MARKER_GRACE_MS) {
|
|
85
|
+
const reason = replacedExists ? `replacements landed` : `marker aged ${Math.round((now - marker.time) / 1000)}s`;
|
|
86
|
+
let deleted = 0;
|
|
84
87
|
for (const n of stillPresent) {
|
|
85
|
-
try { await storage.remove(n); } catch { /* already gone */ }
|
|
88
|
+
try { await storage.remove(n); deleted++; } catch { /* already gone */ }
|
|
86
89
|
}
|
|
90
|
+
if (deleted) console.log(`${blue(name)} ${magenta("retire")}: deleted ${deleted} merged-away input file(s) (${reason})`);
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
}
|