sliftutils 1.4.22 → 1.4.44

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "1.4.22",
3
+ "version": "1.4.44",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -110,6 +110,13 @@ function nullJoin(a: string, b: string): string {
110
110
  return a + NULL + b;
111
111
  }
112
112
 
113
+ function fmtBytes(n: number): string {
114
+ if (n < 1024) return n + "B";
115
+ if (n < 1024 * 1024) return (n / 1024).toFixed(1) + "KB";
116
+ if (n < 1024 * 1024 * 1024) return (n / 1024 / 1024).toFixed(1) + "MB";
117
+ return (n / 1024 / 1024 / 1024).toFixed(2) + "GB";
118
+ }
119
+
113
120
  // A tiny reactivity seam so this file has zero dependency on mobx (or any specific UI framework). The
114
121
  // reactive in-memory state (the overlay map + the load/reset lifecycle) is plain; whenever it's read
115
122
  // we "observe" a signal, and whenever it changes we "invalidate" that signal. A consumer that wants
@@ -1108,6 +1115,16 @@ export class BulkDatabaseBase<T extends { key: string }> {
1108
1115
  const readers = streamReader ? [streamReader, ...bulkReaders] : bulkReaders;
1109
1116
  if (!readers.length) return false;
1110
1117
 
1118
+ // Log the inputs of a REAL merge (files + on-disk sizes). Only here, never for the planning checks
1119
+ // in testMerge/findDuplicateGroups, so the log marks actual rewrites and their before/after I/O.
1120
+ const inputs = [
1121
+ ...await Promise.all(consumedBulk.map(async f => ({ name: f.fileName, size: (await storage.getInfo(f.fileName).catch(() => undefined))?.size ?? 0 }))),
1122
+ ...streamFiles.map(f => ({ name: f.fileName, size: streamData.sizes.get(f.fileName) ?? 0 })),
1123
+ ];
1124
+ const inTotal = inputs.reduce((a, f) => a + f.size, 0);
1125
+ console.log(`${blue(this.name)} merge: reading ${inputs.length} files (${fmtBytes(inTotal)})`);
1126
+ for (const f of inputs) console.log(` in ${f.name} ${fmtBytes(f.size)}`);
1127
+
1111
1128
  const { rows, times, deletes } = await this.resolveReaders(readers);
1112
1129
 
1113
1130
  // Write all outputs BEFORE deleting any input, so a throw mid-write just leaves duplicates.
@@ -1122,11 +1139,19 @@ export class BulkDatabaseBase<T extends { key: string }> {
1122
1139
  // Carry surviving tombstones forward only if older files exist outside this merge that they still
1123
1140
  // need to suppress; when this merge includes the oldest data there's nothing older to suppress.
1124
1141
  const carriedDeletes = includesOldest ? 0 : deletes.size;
1142
+ const outNames = [...newNames];
1125
1143
  if (carriedDeletes) {
1126
1144
  const carryName = `stream_${Date.now()}_${Math.random().toString(36).slice(2, 10)}${STREAM_EXTENSION}`;
1127
1145
  await storage.set(carryName, frameDeletes([...deletes].map(([key, time]) => ({ time, key }))));
1146
+ outNames.push(carryName);
1128
1147
  }
1129
1148
 
1149
+ // Log the result (files + on-disk sizes), so the before→after of the merge is visible.
1150
+ const outputs = await Promise.all(outNames.map(async n => ({ name: n, size: (await storage.getInfo(n).catch(() => undefined))?.size ?? 0 })));
1151
+ const outTotal = outputs.reduce((a, f) => a + f.size, 0);
1152
+ console.log(`${blue(this.name)} merge: wrote ${outputs.length} files (${fmtBytes(outTotal)}, from ${fmtBytes(inTotal)})${carriedDeletes ? `, ${carriedDeletes} tombstones carried` : ""}`);
1153
+ for (const f of outputs) console.log(` out ${f.name} ${fmtBytes(f.size)}`);
1154
+
1130
1155
  const remove = async (name: string) => { try { await storage.remove(name); } catch { /* already gone */ } };
1131
1156
  for (const f of consumedBulk) await remove(f.fileName);
1132
1157
  for (const f of streamFiles) {
@@ -1224,12 +1249,16 @@ export class BulkDatabaseBase<T extends { key: string }> {
1224
1249
  if (recentBytes >= FIRST_MERGE_BYTES) break;
1225
1250
  }
1226
1251
  const span = recent.length ? recent[0].time - recent[recent.length - 1].time : 0;
1227
- // Fold when there's enough fragmentation to consolidate, OR when a foldable stream has grown too
1228
- // big to keep reading whole (even if it's the only recent file) see streamNeedsFold.
1229
- const heavyStreamRecent = this.streamNeedsFold() && recent.some(i => i.kind === "stream");
1252
+ // Fold when there's enough fragmentation to consolidate, OR when the foldable stream data here
1253
+ // has grown past the byte threshold (stream data can't be read per-cell, so a big stream is
1254
+ // costly to pull whole). The stream size is derived from THIS fresh listing — not a cached
1255
+ // counter — so it's correct even for an instance that never built a reader (e.g. the host's
1256
+ // autocompactor) and for streams that grew in place since the index was last loaded.
1257
+ const recentStreamBytes = recent.reduce((a, it) => a + (it.kind === "stream" ? it.bytes : 0), 0);
1258
+ const heavyStream = recentStreamBytes > bulkDatabase2Timing.streamFoldTriggerBytes;
1230
1259
  const triggered =
1231
1260
  recent.length >= 2 && (recent.length > bulkDatabase2Timing.firstMergeTriggerFiles || span > bulkDatabase2Timing.firstMergeTriggerRangeMs)
1232
- || heavyStreamRecent && recent.length >= 1;
1261
+ || heavyStream;
1233
1262
  if (triggered) {
1234
1263
  const rb = recent.filter(i => i.kind === "bulk").map(i => (i.file as BulkFileInfo));
1235
1264
  const rs = recent.filter(i => i.kind === "stream").map(i => (i.file as StreamFileInfo));