@cloudbitmaps/roaring 0.1.0-rc.0
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/LICENSE +202 -0
- package/NOTICE +12 -0
- package/PRIVACY.md +185 -0
- package/README.md +40 -0
- package/dist/azure/index.cjs +14 -0
- package/dist/azure/index.cjs.map +1 -0
- package/dist/azure/index.d.cts +9 -0
- package/dist/azure/index.d.ts +9 -0
- package/dist/azure/index.js +3 -0
- package/dist/azure/index.js.map +1 -0
- package/dist/bin/compact-segments.js +133 -0
- package/dist/bin/compact-segments.js.map +1 -0
- package/dist/bin/export-segments.js +131 -0
- package/dist/bin/export-segments.js.map +1 -0
- package/dist/cassandra/index.cjs +14 -0
- package/dist/cassandra/index.cjs.map +1 -0
- package/dist/cassandra/index.d.cts +1 -0
- package/dist/cassandra/index.d.ts +1 -0
- package/dist/cassandra/index.js +3 -0
- package/dist/cassandra/index.js.map +1 -0
- package/dist/chunk-JWCQLJUG.js +573 -0
- package/dist/chunk-JWCQLJUG.js.map +1 -0
- package/dist/dynamodb/index.cjs +14 -0
- package/dist/dynamodb/index.cjs.map +1 -0
- package/dist/dynamodb/index.d.cts +1 -0
- package/dist/dynamodb/index.d.ts +1 -0
- package/dist/dynamodb/index.js +3 -0
- package/dist/dynamodb/index.js.map +1 -0
- package/dist/gcs/index.cjs +14 -0
- package/dist/gcs/index.cjs.map +1 -0
- package/dist/gcs/index.d.cts +1 -0
- package/dist/gcs/index.d.ts +1 -0
- package/dist/gcs/index.js +3 -0
- package/dist/gcs/index.js.map +1 -0
- package/dist/index.cjs +561 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +446 -0
- package/dist/index.d.ts +446 -0
- package/dist/index.js +542 -0
- package/dist/index.js.map +1 -0
- package/dist/mongodb/index.cjs +14 -0
- package/dist/mongodb/index.cjs.map +1 -0
- package/dist/mongodb/index.d.cts +1 -0
- package/dist/mongodb/index.d.ts +1 -0
- package/dist/mongodb/index.js +3 -0
- package/dist/mongodb/index.js.map +1 -0
- package/dist/mysql/index.cjs +14 -0
- package/dist/mysql/index.cjs.map +1 -0
- package/dist/mysql/index.d.cts +1 -0
- package/dist/mysql/index.d.ts +1 -0
- package/dist/mysql/index.js +3 -0
- package/dist/mysql/index.js.map +1 -0
- package/dist/postgres/index.cjs +14 -0
- package/dist/postgres/index.cjs.map +1 -0
- package/dist/postgres/index.d.cts +1 -0
- package/dist/postgres/index.d.ts +1 -0
- package/dist/postgres/index.js +3 -0
- package/dist/postgres/index.js.map +1 -0
- package/dist/redis/index.cjs +14 -0
- package/dist/redis/index.cjs.map +1 -0
- package/dist/redis/index.d.cts +1 -0
- package/dist/redis/index.d.ts +1 -0
- package/dist/redis/index.js +3 -0
- package/dist/redis/index.js.map +1 -0
- package/dist/s3/index.cjs +14 -0
- package/dist/s3/index.cjs.map +1 -0
- package/dist/s3/index.d.cts +1 -0
- package/dist/s3/index.d.ts +1 -0
- package/dist/s3/index.js +3 -0
- package/dist/s3/index.js.map +1 -0
- package/package.json +183 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { bulkLoadCrbmGeneration as bulkLoadCrbmGeneration$1, compactSegment as compactSegment$1, runCompactionCycle as runCompactionCycle$1, runExport as runExport$1, CodecBitmap, CodecInterface, IColdDriver, ColdChunkSource, IWarmDriver, IRegistryDriver, IKeystore, Clock, Rng, RetryPolicy, IMetricsSink, BudgetOption, SegmentEngine, SegmentRef, PricingProfile, Workload, Topology, CostReport, IAuditSink, CompactionOptions, CompactionResult, ConsistencyReport, ExportSink, ExportOptions, ExportManifest, EstimateInput } from '@cloudbitmaps/core';
|
|
2
|
+
export * from '@cloudbitmaps/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Codec-bound wrappers over the public `@cloudbitmaps/core` entry points that need a bitmap codec.
|
|
6
|
+
*
|
|
7
|
+
* `core` is codec-agnostic and therefore cannot default the codec (the concrete codec lives *here*, in a package
|
|
8
|
+
* that depends on core — a default over there would invert the dependency arrow). But an application using
|
|
9
|
+
* `@cloudbitmaps/roaring` should never have to pass one. So this module re-binds each such entry point with
|
|
10
|
+
* {@link roaringCodec} and the facade re-exports these **explicitly**, which shadows the same names coming from
|
|
11
|
+
* `export * from '@cloudbitmaps/core'` (an explicit export always wins over a star export). Net effect: every
|
|
12
|
+
* call signature is unchanged from before the family split — you can still call
|
|
13
|
+
* `bulkLoadCrbmGeneration(driver, key, ids)` with no options at all.
|
|
14
|
+
*
|
|
15
|
+
* A caller who *wants* a different codec passes it explicitly; the binding only fills an absent one — via
|
|
16
|
+
* `?? roaringCodec` rather than spread order, so an explicit `codec: undefined` still gets the binding
|
|
17
|
+
* (`exactOptionalPropertyTypes` is off, so that call typechecks and must not fall through to the throw).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
type BulkLoad = typeof bulkLoadCrbmGeneration$1;
|
|
21
|
+
type CompactSegment = typeof compactSegment$1;
|
|
22
|
+
type RunCompactionCycle = typeof runCompactionCycle$1;
|
|
23
|
+
type RunExport = typeof runExport$1;
|
|
24
|
+
/** {@link coreBulkLoad} with the roaring codec pre-bound. */
|
|
25
|
+
declare const bulkLoadCrbmGeneration: BulkLoad;
|
|
26
|
+
/** {@link coreCompactSegment} with the roaring codec pre-bound. */
|
|
27
|
+
declare const compactSegment: CompactSegment;
|
|
28
|
+
/** {@link coreRunCompactionCycle} with the roaring codec pre-bound. */
|
|
29
|
+
declare const runCompactionCycle: RunCompactionCycle;
|
|
30
|
+
/** {@link coreRunExport} with the roaring codec pre-bound (only the `'roaring'` format needs it). */
|
|
31
|
+
declare const runExport: RunExport;
|
|
32
|
+
|
|
33
|
+
declare class SafeBitmap implements CodecBitmap {
|
|
34
|
+
private readonly bitmap;
|
|
35
|
+
private constructor();
|
|
36
|
+
static empty(): SafeBitmap;
|
|
37
|
+
static fromValues(values: Iterable<number>): SafeBitmap;
|
|
38
|
+
/**
|
|
39
|
+
* S1: validate size, then deserialize with the **portable** (validated) format.
|
|
40
|
+
* Throws `IntegrityError` if the input exceeds `maxBytes` or fails to decode — the
|
|
41
|
+
* native addon is never handed unbounded or unsafe-format input.
|
|
42
|
+
*/
|
|
43
|
+
static safeDeserialize(bytes: Uint8Array, maxBytes: number): SafeBitmap;
|
|
44
|
+
serialize(): Uint8Array;
|
|
45
|
+
add(value: number): void;
|
|
46
|
+
addMany(values: Iterable<number>): void;
|
|
47
|
+
remove(value: number): void;
|
|
48
|
+
removeMany(values: Iterable<number>): void;
|
|
49
|
+
has(value: number): boolean;
|
|
50
|
+
get size(): number;
|
|
51
|
+
get isEmpty(): boolean;
|
|
52
|
+
clone(): SafeBitmap;
|
|
53
|
+
/** In-place union: `this = this ∪ other`. */
|
|
54
|
+
orInPlace(other: CodecBitmap): void;
|
|
55
|
+
/** In-place difference: `this = this \ other`. */
|
|
56
|
+
andNotInPlace(other: CodecBitmap): void;
|
|
57
|
+
/** In-place intersection: `this = this ∩ other`. */
|
|
58
|
+
andInPlace(other: CodecBitmap): void;
|
|
59
|
+
/** Ascending iterator over the set values. */
|
|
60
|
+
[Symbol.iterator](): IterableIterator<number>;
|
|
61
|
+
toArray(): number[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The roaring {@link CodecInterface} — the flagship codec, delegating to {@link SafeBitmap}'s statics. This is
|
|
65
|
+
* the default the `CloudRoaring` facade injects into the engine; `core/` itself never hard-references it once a
|
|
66
|
+
* caller supplies a codec. Moves to `@cloudbitmaps/roaring` when the package split lands ([DECISIONS #58]).
|
|
67
|
+
*/
|
|
68
|
+
declare const roaringCodec: CodecInterface;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* CloudRoaring — distributed, cloud-native Roaring Bitmaps.
|
|
72
|
+
*
|
|
73
|
+
* The `CloudRoaring` class is the read/write engine over the tiered seams. You wire storage **once**, as a
|
|
74
|
+
* single config object: a Cold driver (`cold`), a Warm driver (`warm`), and optionally a `registry` (the
|
|
75
|
+
* authoritative generation pointer — needed to read encrypted segments and to resolve generations without a
|
|
76
|
+
* cold `list`-scan) and a `keystore` (encryption-at-rest / crypto-shred). Pass a **raw** {@link IColdDriver}
|
|
77
|
+
* as `cold` (e.g. `S3ColdDriver`, `LocalFsColdDriver`, `MemoryColdDriver`) and the store assembles the `.crbm`
|
|
78
|
+
* cold source ({@link CrbmColdChunkSource}) for you — so each driver is named exactly once. Or pass an
|
|
79
|
+
* already-built {@link ColdChunkSource} to control advanced reader options yourself.
|
|
80
|
+
*
|
|
81
|
+
* In-process lifecycle helpers — `compact`, `eraseSubject`, `subjectReport` — reuse the store's own drivers, so
|
|
82
|
+
* you never re-pass them (they need the store built with a raw cold driver + registry). Out-of-process cold
|
|
83
|
+
* writers (the compaction daemon, the seed/bulk-load CLI, `destroySegment`/`eraseNamespace`) wire their own deps
|
|
84
|
+
* against the same drivers — they run in separate processes.md + the
|
|
85
|
+
* getting-started guide.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Wiring for a {@link CloudRoaring} store. **Only `cold` and `warm` are required** — the minimal call is
|
|
90
|
+
* `new CloudRoaring({ cold, warm })`. Add a `registry` to unlock eject / compaction / encryption and to skip the
|
|
91
|
+
* cold list-scan (recommended for anything beyond a quick look). Everything else is **optional tuning with
|
|
92
|
+
* sensible defaults** — resilience/retries are already on, the hot cache is bounded, metrics are a no-op — so
|
|
93
|
+
* reach for them only when you need to.
|
|
94
|
+
*/
|
|
95
|
+
interface CloudRoaringOptions {
|
|
96
|
+
/**
|
|
97
|
+
* Cold tier. Pass a **raw** {@link IColdDriver} (`S3ColdDriver`, `LocalFsColdDriver`, `MemoryColdDriver`, …)
|
|
98
|
+
* and the store wraps it in a {@link CrbmColdChunkSource} using `registry`/`keystore` below — the common case,
|
|
99
|
+
* so you wire each driver **once**. Or pass an already-built {@link ColdChunkSource} (`MemoryColdChunkSource`,
|
|
100
|
+
* or a `CrbmColdChunkSource` you configured with advanced reader options) to use as-is.
|
|
101
|
+
*/
|
|
102
|
+
readonly cold: IColdDriver | ColdChunkSource;
|
|
103
|
+
/** Warm tier: the per-chunk delta store under OCC (`DynamoDbWarmDriver`, `LocalFsWarmDriver`, `MemoryWarmDriver`). */
|
|
104
|
+
readonly warm: IWarmDriver;
|
|
105
|
+
/**
|
|
106
|
+
* Authoritative registry — the per-segment `currentGen` pointer + wrapped-DEK holder. Applies when `cold` is a
|
|
107
|
+
* **raw driver**: it (a) resolves the current generation with one strong read instead of a cold `list`-scan,
|
|
108
|
+
* and (b) lets the store read **encrypted** segments (that's where wrapped DEKs live). Optional — a
|
|
109
|
+
* registry-less store reads the highest generation by list-scanning Cold (cleartext only). When you pass a
|
|
110
|
+
* pre-built `ColdChunkSource`, that source resolves its own generations, so a top-level `registry` is inert
|
|
111
|
+
* there and rejected as a wiring mistake — configure it on the source instead.
|
|
112
|
+
*/
|
|
113
|
+
readonly registry?: IRegistryDriver;
|
|
114
|
+
/**
|
|
115
|
+
* Keystore for encryption-at-rest / crypto-shred (Phase 4e). Required to read encrypted segments; needs a
|
|
116
|
+
* `registry` (that's where wrapped DEKs are stored). Applied only when `cold` is a raw driver — when you pass a
|
|
117
|
+
* pre-built {@link ColdChunkSource}, configure the keystore on that source instead.
|
|
118
|
+
*/
|
|
119
|
+
readonly keystore?: IKeystore;
|
|
120
|
+
/**
|
|
121
|
+
* Refuse to read a **cleartext** segment — a guard against silently reading data that should be encrypted.
|
|
122
|
+
* Needs a `registry`; applied only when `cold` is a raw driver. Off by default (encryption is opt-in).
|
|
123
|
+
*/
|
|
124
|
+
readonly requireEncryption?: boolean;
|
|
125
|
+
/** Injected for deterministic tests; defaults to a system clock. */
|
|
126
|
+
readonly clock?: Clock;
|
|
127
|
+
/** Injected for deterministic tests; defaults to `Math.random`-backed. Drives backoff jitter. */
|
|
128
|
+
readonly rng?: Rng;
|
|
129
|
+
/** HOT cache ceiling (decoded Cold chunks). */
|
|
130
|
+
readonly cacheMaxChunks?: number;
|
|
131
|
+
/** Optional TTL on cached chunks (ms). */
|
|
132
|
+
readonly cacheTtlMs?: number;
|
|
133
|
+
/**
|
|
134
|
+
* How long (ms) the store trusts a segment's resolved `currentGen` before re-resolving it on the next read
|
|
135
|
+
* (default 2000) — the bound on read staleness after a compaction commits a new generation (gap #4). Applies
|
|
136
|
+
* only when `cold` is a raw driver **and** a `registry` is wired (the cheap `currentGen` read the refresh
|
|
137
|
+
* needs; a registry-less store pins per source lifetime). Lazy — no timer; ≤ one registry read per segment per
|
|
138
|
+
* window, opening a new reader only when the generation actually advanced.
|
|
139
|
+
*/
|
|
140
|
+
readonly coldGenTtlMs?: number;
|
|
141
|
+
/**
|
|
142
|
+
* Ceiling on how many segments' `.crbm` readers (each holding a parsed index) the store keeps open at once
|
|
143
|
+
* (default 1024) — the steady-state memory bound for a long-running server that reads across many segments
|
|
144
|
+
* (gap #1). Past it the least-recently-used segment's reader is evicted; re-opening it later is one cheap tail
|
|
145
|
+
* GET. Applies only when `cold` is a raw driver (a pre-built `ColdChunkSource` manages its own reader cache).
|
|
146
|
+
*/
|
|
147
|
+
readonly coldReaderCacheMax?: number;
|
|
148
|
+
/**
|
|
149
|
+
* Aggregate byte ceiling on the parsed `.crbm` indices the open readers hold (default 64 MiB) — the byte
|
|
150
|
+
* half of the gap #1 memory bound, complementing the `coldReaderCacheMax` *count* bound. A wide/dense
|
|
151
|
+
* segment's parsed index can be several MB, so a count-only bound could let the open readers pin ~GBs and
|
|
152
|
+
* blow a small heap (e.g. a 128 MB Lambda); this evicts the least-recently-used reader once the summed index
|
|
153
|
+
* footprint would exceed the ceiling — whichever of the count/byte bounds binds first. Lower it for
|
|
154
|
+
* memory-tight deployments that read across wide segments. Applies only when `cold` is a raw driver.
|
|
155
|
+
*/
|
|
156
|
+
readonly coldReaderCacheMaxBytes?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Resilience: by default every warm/cold call retries **transient** faults (throttling, 5xx, dropped
|
|
159
|
+
* connections) with bounded, jittered exponential backoff (see {@link DEFAULT_RETRY_POLICY}), and OCC
|
|
160
|
+
* conflicts back off between retries. Pass a {@link RetryPolicy} to tune it, or `false` to disable the
|
|
161
|
+
* transient-retry wrappers entirely (e.g. if your injected client already retries). Deterministic errors
|
|
162
|
+
* (`ValidationError`/`IntegrityError`/`WriteConflictError`/…) are never retried by this layer.
|
|
163
|
+
*/
|
|
164
|
+
readonly retry?: RetryPolicy | false;
|
|
165
|
+
/** Backoff schedule between OCC conflict retries; defaults to a small, tight one. */
|
|
166
|
+
readonly occBackoff?: RetryPolicy;
|
|
167
|
+
/** Observability: called before each transient-retry backoff wait. */
|
|
168
|
+
readonly onRetry?: (info: {
|
|
169
|
+
attempt: number;
|
|
170
|
+
delayMs: number;
|
|
171
|
+
err: unknown;
|
|
172
|
+
}) => void;
|
|
173
|
+
/**
|
|
174
|
+
* Observability sink (Phase 5a): receives typed metric events (cold GET/bytes, warm read/write, cache
|
|
175
|
+
* hit/miss, retries, intersection efficiency, op latency). Defaults to a no-op — emission is skipped
|
|
176
|
+
* entirely when unused (near-zero overhead). Any exception the sink throws is swallowed — metrics can
|
|
177
|
+
* never break a read/write.
|
|
178
|
+
*/
|
|
179
|
+
readonly metrics?: IMetricsSink;
|
|
180
|
+
/**
|
|
181
|
+
* Warm read consistency for the READ paths (`has`/`count`/`iterate`/`intersect`). Default `'strong'`
|
|
182
|
+
* (read-your-writes). `'eventual'` trades read-after-write for **~½ the DynamoDB read cost** (a strong read
|
|
183
|
+
* bills 2× RCU) — a good fit for read-heavy, staleness-tolerant workloads (mirrors the cold tier's bounded
|
|
184
|
+
* eventual reads). The compaction/OCC write path is always strongly consistent regardless. No effect on the
|
|
185
|
+
* in-memory/LocalFs drivers (always strong). (Audit gap #9.)
|
|
186
|
+
*/
|
|
187
|
+
readonly warmReadConsistency?: 'strong' | 'eventual';
|
|
188
|
+
/**
|
|
189
|
+
* Max Warm chunk writes in flight per `addMany`/`removeMany` (the bounded flusher). Default **1** (serial —
|
|
190
|
+
* unchanged). Raise it to fan distinct-chunk writes out for throughput on wide multi-chunk batches; each
|
|
191
|
+
* chunk is its own OCC row so this is safe, and (as before) a mid-flush failure can leave a partial result.
|
|
192
|
+
*/
|
|
193
|
+
readonly writeConcurrency?: number;
|
|
194
|
+
/**
|
|
195
|
+
* Per-op **denial-of-wallet** budget (Decision #3 / invariant T3): the max backend requests a
|
|
196
|
+
* single `count`/`iterate`/`intersect`/`subjectReport`/`eraseSubject` may fan out into before it's refused
|
|
197
|
+
* with {@link BudgetExceededError} — so one runaway op can't drive unbounded RCU/GET cost on a shared backend.
|
|
198
|
+
* **On by default, generous** ({@link DEFAULT_BUDGET}: 1,000,000 requests — a normal op never hits it). Tune
|
|
199
|
+
* with `{ maxRequests }`, override per op (on `intersect`/`subjectReport`/`eraseSubject`), or set `false` to
|
|
200
|
+
* disable. The check is O(1) (before fan-out), so the hot path is untouched; per-request bytes are separately
|
|
201
|
+
* size-capped, so bounding requests transitively bounds bytes.
|
|
202
|
+
*/
|
|
203
|
+
readonly budget?: BudgetOption;
|
|
204
|
+
}
|
|
205
|
+
interface SegmentOptions {
|
|
206
|
+
readonly namespace?: string;
|
|
207
|
+
}
|
|
208
|
+
/** A segment reference in a subject report / erasure ledger. */
|
|
209
|
+
interface SubjectSegmentRef {
|
|
210
|
+
readonly segment: string;
|
|
211
|
+
readonly namespace?: string;
|
|
212
|
+
}
|
|
213
|
+
/** Result of {@link CloudRoaring.subjectReport} — the segments an id is a member of (over registered segments). */
|
|
214
|
+
interface SubjectReport {
|
|
215
|
+
readonly id: number;
|
|
216
|
+
/** The registered segments the id is currently a member of. */
|
|
217
|
+
readonly segments: SubjectSegmentRef[];
|
|
218
|
+
/** How many registered segments were scanned (the completeness denominator). */
|
|
219
|
+
readonly scannedSegments: number;
|
|
220
|
+
}
|
|
221
|
+
/** One segment's entry in an erasure ledger (see {@link EraseSubjectResult}). */
|
|
222
|
+
interface SubjectErasureEntry {
|
|
223
|
+
readonly segment: string;
|
|
224
|
+
readonly namespace?: string;
|
|
225
|
+
/** The id was present and a logical `remove` tombstone was written. */
|
|
226
|
+
readonly removed: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* True iff *this call* committed a new generation with the segment's tombstones applied — the bit is
|
|
229
|
+
* physically gone from Cold (assuming no concurrent re-add of the id; see {@link CloudRoaring.eraseSubject}).
|
|
230
|
+
* `false` is **conservative**: the purge may have been deferred (`note:'leased-by-other'`) or already done by
|
|
231
|
+
* a concurrent daemon (`note:'clean'`); the logical removal holds regardless.
|
|
232
|
+
*/
|
|
233
|
+
readonly physicallyPurged: boolean;
|
|
234
|
+
/** The generation that retired the bit (present when `physicallyPurged`). */
|
|
235
|
+
readonly toGen?: number;
|
|
236
|
+
/** Why physical purge wasn't committed by this call (compaction's `reason`, e.g. `'leased-by-other'`, `'clean'`). */
|
|
237
|
+
readonly note?: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The erasure ledger returned by {@link CloudRoaring.eraseSubject} — your proof-of-deletion artifact. It is a
|
|
241
|
+
* return value only (no library-side persistence): persist it / route it to your audit sink as you see fit.
|
|
242
|
+
*/
|
|
243
|
+
interface EraseSubjectResult {
|
|
244
|
+
readonly id: number;
|
|
245
|
+
/** Per-segment records for the segments the id was erased from (absent segments are not listed). */
|
|
246
|
+
readonly erasedFrom: SubjectErasureEntry[];
|
|
247
|
+
/** How many registered segments were scanned. */
|
|
248
|
+
readonly scannedSegments: number;
|
|
249
|
+
}
|
|
250
|
+
declare class CloudRoaring {
|
|
251
|
+
private readonly engine;
|
|
252
|
+
private readonly clock;
|
|
253
|
+
private readonly metrics;
|
|
254
|
+
private readonly coldDriver;
|
|
255
|
+
private readonly warmDriver;
|
|
256
|
+
private readonly registry;
|
|
257
|
+
private readonly keystore;
|
|
258
|
+
private readonly requireEncryption;
|
|
259
|
+
/** Resolved store-level per-op budget (null = disabled); the admin scans use it, with a per-op override. */
|
|
260
|
+
private readonly budget;
|
|
261
|
+
constructor(options: CloudRoaringOptions);
|
|
262
|
+
/**
|
|
263
|
+
* Build {@link CompactionDeps} from the store's own drivers, for the in-process lifecycle helpers
|
|
264
|
+
* ({@link compact} / {@link eraseSubject}). Requires the store to have been constructed with a **raw cold
|
|
265
|
+
* driver** (a pre-built `ColdChunkSource` has no underlying `IColdDriver` to compact through) and a `registry`
|
|
266
|
+
* (the authoritative `currentGen` pointer compaction swaps). Out-of-process callers use the `compactSegment`
|
|
267
|
+
* free function with explicit deps.
|
|
268
|
+
*/
|
|
269
|
+
private compactionDeps;
|
|
270
|
+
/** Get a handle to a segment. Validates the name/namespace grammar (finding S2). */
|
|
271
|
+
segment(name: string, options?: SegmentOptions): Segment;
|
|
272
|
+
/**
|
|
273
|
+
* **Subject access (GDPR Art. 15 / CCPA right-to-know): which segments is this id a member of?** (Phase 6b.)
|
|
274
|
+
*
|
|
275
|
+
* Enumerates the **registered** segments (via the store's own `registry`) and does a tier-merging `has(id)` on
|
|
276
|
+
* each — no drivers to re-pass. Complete only over registered segments (register your segments if you claim
|
|
277
|
+
* SAR support). There is deliberately **no `id → segments` reverse index** — that would tax every write for a
|
|
278
|
+
* rare request; this admin scan is `O(registered segments)` and touches no hot path
|
|
279
|
+
* (phases/06). Requires a `registry` in the store config
|
|
280
|
+
* (throws {@link UnsupportedError} otherwise).
|
|
281
|
+
*/
|
|
282
|
+
subjectReport(id: number, options?: {
|
|
283
|
+
namespace?: string;
|
|
284
|
+
allNamespaces?: boolean;
|
|
285
|
+
concurrency?: number;
|
|
286
|
+
budget?: BudgetOption;
|
|
287
|
+
}): Promise<SubjectReport>;
|
|
288
|
+
/**
|
|
289
|
+
* **Subject erasure (GDPR Art. 17): remove an id from every segment it's in, with a physical-deletion
|
|
290
|
+
* guarantee.** (Phase 6b.)
|
|
291
|
+
*
|
|
292
|
+
* For each **registered** segment the id is a member of: writes a logical `remove` tombstone (immediate) and
|
|
293
|
+
* then **force-compacts that segment now** — folding the tombstone into a fresh immutable generation so the
|
|
294
|
+
* bit is *physically* gone from Cold on return, even for an otherwise-idle/archival segment that organic
|
|
295
|
+
* compaction would never touch (the P13 fix). The returned per-segment record is your **erasure ledger** —
|
|
296
|
+
* persist it / route it to your audit sink as the proof of deletion; the physical-purge proof is
|
|
297
|
+
* compaction's own VERIFY step (a re-`has()` here would be unsound — a pinned cold source can still read the
|
|
298
|
+
* old generation; take a fresh generation view after erasing, exactly as with the compaction daemon).
|
|
299
|
+
*
|
|
300
|
+
* Uses the store's **own** drivers (raw cold + warm + registry), so the old integrator obligation to wire a
|
|
301
|
+
* matching `CompactionDeps` is gone — the `remove()` and the force-compaction provably run over the same tiers.
|
|
302
|
+
* Requires the store built with a **raw cold driver + registry** (throws {@link UnsupportedError} otherwise;
|
|
303
|
+
* a pre-built `ColdChunkSource` store has no `IColdDriver` to compact through — use the `compactSegment` free
|
|
304
|
+
* function there). **One contract remains** (an integrator obligation the library cannot check): **do not
|
|
305
|
+
* concurrently re-add the same id while erasing it.** A normal `add(id)` landing between the `remove` and the
|
|
306
|
+
* compaction clears the tombstone and folds the id back into the new generation
|
|
307
|
+
* (`effective = (cold ∪ adds) \ removes`); `physicallyPurged` attests only that compaction committed a
|
|
308
|
+
* generation with the tombstones applied at pin time — quiesce writes for the subject during erasure.
|
|
309
|
+
*
|
|
310
|
+
* **A `physicallyPurged:false` entry means the logical removal holds but the physical purge didn't run this
|
|
311
|
+
* call** — either a daemon held a live lease (`note:'leased-by-other'`; the daemon finishes it), or the
|
|
312
|
+
* force-compaction hit an isolated fault (`note:'error: …'`; per-segment faults are caught so one segment
|
|
313
|
+
* can't discard the whole ledger). `physicallyPurged:false` is **conservative** (a concurrent daemon may
|
|
314
|
+
* already have purged the bit — `'clean'`). **Recovery:** follow up any `physicallyPurged:false` entry with
|
|
315
|
+
* `store.compact(ref)` (or let the daemon do it) — **re-running `eraseSubject` will NOT re-purge it**, because
|
|
316
|
+
* `has()` now reads false (the tombstone) so the segment is skipped as a non-member. The physical-purge proof
|
|
317
|
+
* is compaction's own VERIFY step (a re-`has()` here would be unsound: a pinned cold source can still read the
|
|
318
|
+
* old generation — take a fresh generation view after erasing, as with the daemon). Admin-only path;
|
|
319
|
+
* `O(registered segments)`, no hot-path cost. Per-subject crypto-shred is infeasible (a subject's bit is
|
|
320
|
+
* co-mingled in a shared container), so this is the single-subject erasure route; whole-segment/tenant erasure
|
|
321
|
+
* is the `destroySegment`/`eraseNamespace` free functions.
|
|
322
|
+
*/
|
|
323
|
+
eraseSubject(id: number, options: {
|
|
324
|
+
owner: string;
|
|
325
|
+
namespace?: string;
|
|
326
|
+
allNamespaces?: boolean;
|
|
327
|
+
audit?: IAuditSink;
|
|
328
|
+
concurrency?: number;
|
|
329
|
+
budget?: BudgetOption;
|
|
330
|
+
}): Promise<EraseSubjectResult>;
|
|
331
|
+
/**
|
|
332
|
+
* **Compact one segment now**, in-process, using the store's own drivers — a convenience over the
|
|
333
|
+
* {@link compactSegment} free function. Merges `(cold ∪ adds) \ removes` into a fresh immutable generation,
|
|
334
|
+
* swaps `currentGen`, then version-fenced-purges the archived Warm rows. A no-op (`compacted:false`) when the
|
|
335
|
+
* segment has no dirty rows or a daemon holds a live lease — never throws on the normal contention/lease paths.
|
|
336
|
+
* Requires the store built with a **raw cold driver + registry** (throws {@link UnsupportedError} otherwise);
|
|
337
|
+
* like the daemon, it uses the raw drivers directly (a transient fault surfaces to you rather than retrying
|
|
338
|
+
* under the hood). **Not for the request/hot path** — it reads and rewrites a whole Cold generation (streaming,
|
|
339
|
+
* constant-memory, but full-segment I/O). Use the `compact-segments` daemon (`runCompactionCycle`) for routine
|
|
340
|
+
* background compaction; reach for `store.compact()` for occasional/manual one-shots — a maintenance endpoint,
|
|
341
|
+
* a small daemon-less deployment, or right after a targeted `remove`.
|
|
342
|
+
*/
|
|
343
|
+
compact(ref: SegmentRef, options: CompactionOptions): Promise<CompactionResult>;
|
|
344
|
+
/**
|
|
345
|
+
* **Cross-tier DR consistency check (audit gap #11).** After a restore/failover, verify every registered
|
|
346
|
+
* segment's `currentGen` actually has its `.crbm` present in Cold — catching a **torn restore** where the
|
|
347
|
+
* registry (`currentGen`) came back ahead of the object store, so a pointer references a generation that
|
|
348
|
+
* isn't there (reads would then throw). Read-only, bounded fan-out; run it at startup after a restore.
|
|
349
|
+
* Returns `{ checked, inconsistent }` — `inconsistent` empty ⇒ coherent; otherwise it names the segments to
|
|
350
|
+
* recover (restore the object store, or roll the registry back to a coherent point). Needs the store built
|
|
351
|
+
* with a **raw cold driver + a registry** (throws {@link UnsupportedError} otherwise). `destroyed`
|
|
352
|
+
* (crypto-shredded) segments are skipped. Pair it with the DR runbook (docs/guide/disaster-recovery.md).
|
|
353
|
+
*/
|
|
354
|
+
checkConsistency(options?: {
|
|
355
|
+
namespace?: string;
|
|
356
|
+
concurrency?: number;
|
|
357
|
+
}): Promise<ConsistencyReport>;
|
|
358
|
+
/**
|
|
359
|
+
* **Export ("eject") every registered segment's current effective set** through the injected `sink`, using
|
|
360
|
+
* only public read APIs — so your data is readable **without CloudRoaring** (the exit path; see the README's
|
|
361
|
+
* "Your data stays yours"). `format: 'roaring'` (default) writes one **portable RoaringBitmap32** per segment
|
|
362
|
+
* (loadable by any roaring library); `'ndjson'` writes newline-delimited ids (zero-dependency, streaming).
|
|
363
|
+
* Enumerates via the store's **own** registry (needs one — throws {@link UnsupportedError} otherwise) so the
|
|
364
|
+
* enumeration and the read path provably share one registry; an all-warm segment not yet in the registry can be
|
|
365
|
+
* named via `options.candidates`. Encrypted segments are decrypted transparently **iff** this store was wired
|
|
366
|
+
* with their keystore — the export is therefore **cleartext**; protect it. Crypto-shredded segments are skipped.
|
|
367
|
+
* A segment that can't be read is isolated into the manifest's `failed[]` (the run continues), so "a manifest
|
|
368
|
+
* exists" means the run finished — check `failed`. The `export-segments` CLI wraps this with a filesystem sink.
|
|
369
|
+
*/
|
|
370
|
+
exportSegments(sink: ExportSink, options?: ExportOptions): Promise<ExportManifest>;
|
|
371
|
+
/**
|
|
372
|
+
* Planning cost estimate (Phase 5b) — pure, no instance/data needed: sizing, sales, what-if. For a real,
|
|
373
|
+
* grounded report from live segment sizes, use `store.segment(name).costReport()`. See {@link CostReport}.
|
|
374
|
+
*/
|
|
375
|
+
static estimateCost(input: EstimateInput): CostReport;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* A handle bound to one segment — the seven ops.
|
|
379
|
+
*
|
|
380
|
+
* **IDs must be integers in `[0, 2^32)`** (dense 32-bit). A non-integer / negative / out-of-range id
|
|
381
|
+
* throws {@link ValidationError}.
|
|
382
|
+
*
|
|
383
|
+
* **`addMany`/`removeMany`/`intersectInto` are not atomic across chunks**: ids are grouped by chunk and
|
|
384
|
+
* applied one chunk at a time, so if a later chunk fails (e.g. {@link WriteConflictError} after retries)
|
|
385
|
+
* earlier chunks are already applied. Within a single chunk the update is atomic.
|
|
386
|
+
*/
|
|
387
|
+
declare class Segment {
|
|
388
|
+
private readonly engine;
|
|
389
|
+
private readonly ref;
|
|
390
|
+
private readonly clock;
|
|
391
|
+
private readonly metrics;
|
|
392
|
+
private readonly metricsOn;
|
|
393
|
+
constructor(engine: SegmentEngine, ref: SegmentRef, clock: Clock, metrics: IMetricsSink);
|
|
394
|
+
/**
|
|
395
|
+
* Time an op with the injected clock and emit an `op` metric on completion (success or throw). Skipped
|
|
396
|
+
* entirely when no sink is wired, so the default path pays nothing.
|
|
397
|
+
*/
|
|
398
|
+
private timed;
|
|
399
|
+
/** Add an id (integer in `[0, 2^32)`). Throws {@link ValidationError} on a bad id. */
|
|
400
|
+
add(id: number): Promise<void>;
|
|
401
|
+
/** Add many ids. Not atomic across chunks — see the class note. */
|
|
402
|
+
addMany(ids: Iterable<number>): Promise<void>;
|
|
403
|
+
/** Remove an id (integer in `[0, 2^32)`). Throws {@link ValidationError} on a bad id. */
|
|
404
|
+
remove(id: number): Promise<void>;
|
|
405
|
+
/** Remove many ids. Not atomic across chunks — see the class note. */
|
|
406
|
+
removeMany(ids: Iterable<number>): Promise<void>;
|
|
407
|
+
has(id: number): Promise<boolean>;
|
|
408
|
+
count(): Promise<number>;
|
|
409
|
+
iterate(): AsyncIterable<number>;
|
|
410
|
+
/**
|
|
411
|
+
* Chunk-skipping intersection: stream the ids in **this** segment AND every segment in `others`, ascending.
|
|
412
|
+
* Fetches only the Cold chunks present in *all* operands (a key absent from any operand contributes nothing
|
|
413
|
+
* and is never downloaded), streaming under a bounded in-flight window — so the Cold footprint stays small
|
|
414
|
+
* (Lambda-friendly) regardless of segment size. Pass `concurrency` to tune that window (a positive integer).
|
|
415
|
+
* AND is commutative, so `a.intersect([b])` and `b.intersect([a])` yield the same ids. (Warm state is read
|
|
416
|
+
* up front, so total memory also carries each operand's Warm size — negligible under Topology-A.) Pass
|
|
417
|
+
* `budget` to override the store's per-op denial-of-wallet budget for this call (or `false` to lift it).
|
|
418
|
+
*/
|
|
419
|
+
intersect(others: Segment[], options?: {
|
|
420
|
+
concurrency?: number;
|
|
421
|
+
budget?: BudgetOption;
|
|
422
|
+
}): AsyncIterable<number>;
|
|
423
|
+
/**
|
|
424
|
+
* Materialize `this ∩ others…` **into** `dest` (added, not replaced). Streaming + bounded-memory, but
|
|
425
|
+
* **not atomic** across chunks — see {@link addMany}.
|
|
426
|
+
*/
|
|
427
|
+
intersectInto(dest: Segment, others: Segment[], options?: {
|
|
428
|
+
concurrency?: number;
|
|
429
|
+
batchSize?: number;
|
|
430
|
+
}): Promise<void>;
|
|
431
|
+
/**
|
|
432
|
+
* Grounded cost report for this segment (Phase 5b): storage cost from its **real** `.crbm` size (exact,
|
|
433
|
+
* no payload reads); request cost from the supplied `workload` rates. A segment with no Cold generation
|
|
434
|
+
* reports zero storage. See {@link CostReport} — it always includes a verdict (incl. the lose-zone).
|
|
435
|
+
*/
|
|
436
|
+
costReport(options?: {
|
|
437
|
+
pricing?: PricingProfile;
|
|
438
|
+
workload?: Workload;
|
|
439
|
+
topology?: Topology;
|
|
440
|
+
}): Promise<CostReport>;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** Package version marker. Kept in sync with package.json at release. */
|
|
444
|
+
declare const VERSION = "0.1.0-rc.0";
|
|
445
|
+
|
|
446
|
+
export { CloudRoaring, type CloudRoaringOptions, type EraseSubjectResult, SafeBitmap, Segment, type SegmentOptions, type SubjectErasureEntry, type SubjectReport, type SubjectSegmentRef, VERSION, bulkLoadCrbmGeneration, compactSegment, roaringCodec, runCompactionCycle, runExport };
|