sliftutils 1.7.2 → 1.7.4
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
|
@@ -5,6 +5,9 @@ import { STREAM_EXTENSION, StreamEntry, parseStream, streamReaderFromEntries } f
|
|
|
5
5
|
import { formatNumber, formatTime } from "socket-function/src/formatting/format";
|
|
6
6
|
import { blue, red } from "socket-function/src/formatting/logColors";
|
|
7
7
|
|
|
8
|
+
// Duplicated from BulkDatabaseBase to avoid a circular import — used only to build a fuller storage-relative path for log messages.
|
|
9
|
+
const BULK_ROOT_FOLDER = "bulkDatabases2";
|
|
10
|
+
|
|
8
11
|
export type BulkFileInfo = { fileName: string; level: number; timestamp: number };
|
|
9
12
|
export type StreamFileInfo = { fileName: string; timestamp: number };
|
|
10
13
|
export type StreamReaderCacheEntry = { readSize: number; parsedPos: number; entries: StreamEntry[] };
|
|
@@ -257,7 +260,7 @@ export async function loadFileReader(name: string, storage: FileStorage, f: Bulk
|
|
|
257
260
|
const raw = await makeRawGetRange(storage, f.fileName);
|
|
258
261
|
const fileId = nullJoin(name, f.fileName);
|
|
259
262
|
const opened = await blockCache.open(fileId, raw.size, raw.rawGetRange);
|
|
260
|
-
const reader = await loadBulkDatabase({ totalBytes: opened.uncompressedSize, getRange: opened.getRange, name: f.fileName });
|
|
263
|
+
const reader = await loadBulkDatabase({ totalBytes: opened.uncompressedSize, getRange: opened.getRange, name: `${BULK_ROOT_FOLDER}/${name}/${f.fileName}` });
|
|
261
264
|
cache.set(f.fileName, reader);
|
|
262
265
|
return reader;
|
|
263
266
|
}
|
|
@@ -333,11 +336,11 @@ function pruneSubCaches(bulkFiles: BulkFileInfo[], streamFiles: StreamFileInfo[]
|
|
|
333
336
|
// visible without flooding the log on every rebuild.
|
|
334
337
|
const warnedCorruptReads = new Set<string>();
|
|
335
338
|
function warnCorruptRead(db: BaseBulkDatabaseReader, column: string, e: unknown): void {
|
|
336
|
-
const
|
|
337
|
-
const dedupeKey = nullJoin(
|
|
339
|
+
const path = db.name || "(unknown source)";
|
|
340
|
+
const dedupeKey = nullJoin(path, column);
|
|
338
341
|
if (warnedCorruptReads.has(dedupeKey)) return;
|
|
339
342
|
warnedCorruptReads.add(dedupeKey);
|
|
340
|
-
console.warn(`${red("corrupt read")}: file ${
|
|
343
|
+
console.warn(`${red("corrupt read")}: file ${path} column ${JSON.stringify(column)} could not be read - skipping it (its data is dropped from results): ${(e as Error).message}`);
|
|
341
344
|
}
|
|
342
345
|
|
|
343
346
|
function joinBulkDatabases(databases: BaseBulkDatabaseReader[]): ResolvedReader {
|
|
@@ -150,7 +150,11 @@ export class BlockCache {
|
|
|
150
150
|
let lastMeta = index.blocks[runEnd - 1];
|
|
151
151
|
let compEnd = index.offsets[runEnd - 1] + lastMeta.len;
|
|
152
152
|
let runCompressed = rawGetRange(compStart, compEnd);
|
|
153
|
-
//
|
|
153
|
+
// Hold this run's promises locally. Registering them in the LRU can evict earlier
|
|
154
|
+
// blocks of the same run (or of a concurrent run) before we get to await them, so
|
|
155
|
+
// reading them back out of the cache would silently drop blocks and return a short
|
|
156
|
+
// buffer. We still register in the LRU so concurrent reads dedupe onto them.
|
|
157
|
+
let runPromises: Promise<Buffer>[] = [];
|
|
154
158
|
for (let i = runStart; i < runEnd; i++) {
|
|
155
159
|
let meta = index.blocks[i];
|
|
156
160
|
let relOffset = index.offsets[i] - compStart;
|
|
@@ -159,17 +163,20 @@ export class BlockCache {
|
|
|
159
163
|
if (meta.c) return LZ4.decompress(stored);
|
|
160
164
|
return stored;
|
|
161
165
|
});
|
|
166
|
+
runPromises.push(blockPromise);
|
|
162
167
|
this.touch(`${fileId}:${i}`, blockPromise);
|
|
163
168
|
}
|
|
164
|
-
for (let
|
|
165
|
-
let promise = this.blocks.get(`${fileId}:${i}`);
|
|
166
|
-
if (promise) parts.push(await promise);
|
|
167
|
-
}
|
|
169
|
+
for (let promise of runPromises) parts.push(await promise);
|
|
168
170
|
block = runEnd;
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
let combined = parts.length === 1 && parts[0] || Buffer.concat(parts);
|
|
172
174
|
let sliceStart = start - firstBlock * blockSize;
|
|
175
|
+
// A short combined buffer means we lost blocks; subarray would clamp and hand back
|
|
176
|
+
// truncated data that every caller treats as valid. Fail loudly instead.
|
|
177
|
+
if (combined.length < sliceStart + (end - start)) {
|
|
178
|
+
throw new Error(`Expected ${sliceStart + (end - start)} bytes of blocks for range [${start}, ${end}) of ${fileId}, was ${combined.length}`);
|
|
179
|
+
}
|
|
173
180
|
return combined.subarray(sliceStart, sliceStart + (end - start));
|
|
174
181
|
};
|
|
175
182
|
}
|