@cloudbitmaps/roaring 0.19.0 → 0.20.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/PRIVACY.md CHANGED
@@ -60,7 +60,7 @@ CloudBitmaps gives you three levers with different guarantees. Use them delibera
60
60
 
61
61
  | Lever | API | Guarantee | Use for |
62
62
  |---|---|---|---|
63
- | **Subject erasure** | `store.eraseSubject(id, { namespace })` | *Physical on return* — the segment's current generation is rewritten without the id (every chunk streamed through, one bit cleared), published **fenced on the generation it streamed**, and **the generation that held the bit is deleted before the call returns**. So is every other generation still holding the id: a retained *superseded* one (an ex-member dropped by a re-seed), and each one above the pointer after a `rollback` — generations a rollback can move the pointer onto again — while, when the current generation does not hold the id, the ones there that never held it stay as rollback targets (a rewrite is numbered above everything, so its `keep: 0` collection takes every older generation, above the pointer or below). Before it says `erased: true` the call lists the bucket and reads what is left, so **`erased: true` means no generation of the segment holds the id**, above the pointer or below it. `eraseSubject` reports a per-segment fault as an `error: …` ledger entry rather than throwing it, and a call that a racing writer overtook (a load, another erasure, or a rollback) as `erased: false, note: 'superseded'`, so "on return" is a claim about every segment whose entry says **`erased: true`** (a fault is an `error: …` entry, never `erased: true`). The store that performs the call stops serving the id immediately; **other processes converge on their own read TTL** — see [One process, and the rest of your fleet](#one-process-and-the-rest-of-your-fleet). Does **not** reach backups, replicas or noncurrent object versions — those hold the old generation until their own lifecycle removes it. It carries a generation's metadata over unchanged and does **not** scan it, so **never put a subject's id in metadata**. | "forget this person" — GDPR Art. 17 |
63
+ | **Subject erasure** | `store.eraseSubject(id, { namespace })` | *Physical on return* — the segment's current generation is rewritten without the id (every chunk streamed through, one bit cleared), published **fenced on the generation it streamed**, and **the generation that held the bit is deleted before the call returns**. So is every other generation still holding the id: a retained *superseded* one (an ex-member dropped by a re-seed), and each one above the pointer after a `rollback` — generations a rollback can move the pointer onto again — while, when the current generation does not hold the id, the ones there that never held it stay as rollback targets, but for any object no read of the segment can open, which goes whatever the id. (When the current generation holds the id, the rewrite is numbered above everything, so its `keep: 0` collection takes every older generation, above the pointer or below.) Before it says `erased: true` the call lists the bucket and reads what is left, so **`erased: true` means no generation of the segment holds the id**, above the pointer or below it. `eraseSubject` reports a per-segment fault as an `error: …` ledger entry rather than throwing it, and a call that a racing writer overtook (a load, another erasure, or a rollback) as `erased: false, note: 'superseded'`, so "on return" is a claim about every segment whose entry says **`erased: true`** (a fault is an `error: …` entry, never `erased: true`). The store that performs the call stops serving the id immediately; **other processes converge on their own read TTL** — see [One process, and the rest of your fleet](#one-process-and-the-rest-of-your-fleet). Does **not** reach backups, replicas or noncurrent object versions — those hold the old generation until their own lifecycle removes it. It carries a generation's metadata over unchanged and does **not** scan it, so **never put a subject's id in metadata**. | "forget this person" — GDPR Art. 17 |
64
64
  | **Dispose** | `store.dropSegment(ref, { confirmSegment })` | *Immediate* — the segment is tombstoned and its Storage generations deleted, reclaiming the space. **Check `generationsRemaining`:** if it is non-empty the space was *not* fully reclaimed and the drop should be re-run (a load that had read the segment before the tombstone landed, even one still consuming its ids, or an `eraseSubject` rewrite already under way, can write its object after the drop's sweep; it deletes that object itself once its publish is refused, and only one whose process stops in between, or whose publish fails without a definite answer (a lost response, a timeout), leaves it, for a re-run of the drop). Works on cleartext; on an encrypted segment it *also* crypto-shreds, on the terms in the next row. Does **not** reach noncurrent versions / replicas / PITR snapshots — deleting an object is weaker than removing a key. | retiring a dated bucket; rolling-window retention |
65
65
  | **Crypto-shred** | `destroySegment` / `eraseNamespace` | *At rest, complete once no copy of the wrapped key survives* — removes the segment's wrapped DEK(s) from its registry row in one compare-and-swap, without touching the bytes or any KEK. **Every** copy of the objects (current, prior generations, backups, WORM-locked objects) is then unreadable once no retained copy of that row still holds the wrapped key — noncurrent object versions, backups and PITR copies of the row included — or once every KEK that wrapped it is destroyed. Until then, a retained copy of the row and a KEK that wrapped it decrypt the segment, and a registry restore to a point before the shred makes it readable again; see *Erasure vs. backups / WORM* below, and [an optional registry expiry rule](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/disaster-recovery.md#optional-make-a-shred-durable-with-a-registry-expiry-rule) that makes a shred durable after a set number of days. Requires the segment to be encrypted. A process that had already opened the segment holds the **unwrapped** key in memory and keeps reading until it is told — call `store.invalidate(ref)` there; see [One process, and the rest of your fleet](#one-process-and-the-rest-of-your-fleet). | whole-segment / tenant offboarding; erasure under immutable backups (see below) |
66
66
 
@@ -76,9 +76,16 @@ It reuses the store's own drivers (so build the store with a backend). It return
76
76
  **erasure ledger** — one entry per segment the id was found in, `{ segment, namespace?, erased, fromGeneration,
77
77
  generation, note? }` — as your proof of deletion; persist it or route it to your audit sink, which also receives
78
78
  one `segment.rewrite { fromGeneration, generation }` event per rewrite when you pass `audit` — an id found only
79
- outside the current generation (a retained *superseded* one, or one above the pointer after a rollback) is
80
- collected rather than rewritten, so it emits no event and its ledger entry carries no `generation`. Segments the id is
81
- not in are not listed. `store.subjectReport(id, { namespace })` answers the read side (Art. 15 — which segments
79
+ outside the current generation (a retained *superseded* one, one above the pointer after a rollback, an object left
80
+ under a tombstone, or a first load's object on a segment with no generation yet) is collected rather than rewritten,
81
+ so it emits `segment.collect { fromGeneration, collected }`
82
+ instead and its ledger entry carries no `generation`. Each `segment.*` event also names the segment's `incarnation`
83
+ when its registry token carries one, so a segment created again under the same name is told apart from the one
84
+ erased. Segments the id is
85
+ not in are not listed. A segment where the erasure found the id in nothing it could search, and deleted only objects
86
+ no read of it can open, is not listed either: the audit sink gets `segment.collect { collected }` for it, with no
87
+ `fromGeneration`, and that event is the only record of the deletion. `store.subjectReport(id, { namespace })` answers
88
+ the read side (Art. 15 — which segments
82
89
  an id is in).
83
90
 
84
91
  Two rules. **Do not load a segment while erasing from it**: a load that lands after the rewrite carries whatever
@@ -117,11 +124,22 @@ sweep run (it collects nothing without a row) reaches. List those objects with `
117
124
  `store.dropSegment(ref, { confirmSegment: ref.segment })`, which leaves a tombstone row fencing the name. An empty
118
125
  ledger is not by itself proof the id is gone. A tombstoned segment is searched too: a
119
126
  cleartext object left under it that holds the id is deleted with everything under the tombstone, and the entry reads
120
- `erased: true`. A segment whose row names no generation yet (a retention policy set before its first load) is
121
- searched too: an object a first load wrote and never published that holds the id, or on an encrypted store cannot
122
- be searched until its load publishes the key, is reported as an `error: …` note and not deleted, because that load may
123
- still publish it. Load the segment, which makes the object collectable, or drop
124
- it, and re-run.
127
+ `erased: true`. A segment whose row names no generation yet (a retention policy set before its first load) is searched
128
+ too: an object a first load wrote and never published that holds the id is deleted, and the entry reads `erased:
129
+ true`. Before it deletes anything the erasure renews the row's `pointerId`, so a load still running that wrote such an
130
+ object is refused at its publish and never names an object that is gone. Each delete names the object the erasure
131
+ read: on a storage driver that reports `conditionalDelete`, another erasure of the id that deletes it first, followed
132
+ by a load that takes the number freed and publishes, does not lose that load's generation to this erasure's delete; on
133
+ one that does not, it can, and the row then names a missing object, which `store.checkConsistency()` reports
134
+ ([a number taken again](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/erasure.md#how-it-stays-correct)). On an encrypted store such an object cannot
135
+ be searched until its load publishes the key, so it is deleted whatever id is erased: an erasure of any id refuses an
136
+ encrypted first load in flight that has written its object onto a segment whose row was made ahead of its data, and
137
+ that load is re-run ([the erasure guide](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/erasure.md#two-rules-while-you-erase)). On an encrypted segment,
138
+ an object sealed under a key its row does not hold, and on a cleartext segment with a generation, an encrypted object,
139
+ open for no read of the segment (the object of a first load that lost the race to the one that published, or
140
+ crashed): each is deleted the same way, whatever id is erased, wherever an erasure meets it, except as the current
141
+ generation, which is never deleted for this, and under a tombstone, where it is no holder and goes only with
142
+ everything there, when another object under the tombstone holds the id.
125
143
 
126
144
  **Do not roll a segment back while erasing from it.** A rollback that lands mid-erasure can move the pointer onto a
127
145
  generation the erasure did not rewrite, so the id can be current again. Roll back before the erasure starts or
@@ -137,8 +155,8 @@ A call with a feed reads operands the library never stores, which no erasure can
137
155
 
138
156
  Erasure and crypto-shred are **immediate in storage and immediate in the store whose verb performed them**, for
139
157
  every read that starts after the verb returns. A read already in progress in that store can still yield an erased id
140
- from a chunk it had requested before the verb ran: up to 32 chunks for `iterate` and `count`, and up to `concurrency`
141
- keys (32 by default) for a combine. A combine or `iterate` reads ranges of the object, and resolves the segment again before it serves each chunk, one held in its cache included, as a read of that chunk alone does, so the ranges it had already requested are dropped, not served. They are not immediate in any *other* store, in the same process or another, and this library ships nothing that could
158
+ from a chunk it had requested before the verb ran: up to 32 chunks for `iterate` and `count`, and up to `concurrency` + 1
159
+ keys (33 by default) for a combine, the key it is handing out and the `concurrency` keys it had already requested. A combine or `iterate` reads ranges of the object, and resolves the segment again before it serves each chunk, one held in its cache included, as a read of that chunk alone does, so the ranges it had already requested are dropped, not served. They are not immediate in any *other* store, in the same process or another, and this library ships nothing that could
142
160
  make them so — there is no daemon, no bus, and no connection between two stores that happen to point at the same
143
161
  bucket.
144
162
 
@@ -154,11 +172,15 @@ bucket.
154
172
  | a leased pinned handle (`seg.pin({ leaseUntil })`) in another store | until its lease ends, at most 14 days after it was taken: its reads then throw `LeaseExpiredError`, whether or not its reader still holds the chunks. Until then, as for any pinned handle in the row above |
155
173
 
156
174
  **An outage of the registry extends that bound.** A refresh that cannot read the row because of a transient fault
157
- (throttling, a 5xx, a dropped connection) keeps serving the generation the reader already holds, and the key it
158
- unwrapped, and asks again 500 ms later, or after `cache.genTtlMs` if that is shorter. So while the registry cannot
159
- be read, a shred or a drop is not seen, and the store converges within one retry of the registry answering. Any
160
- other failure of the refresh (an access denial, a row that will not parse) is not ridden out: the read that finds it
161
- fails with that error, and the reader is dropped with the key it held.
175
+ (throttling, a 5xx, a dropped connection) keeps serving what the store resolved before the outage, for a segment
176
+ still in its reader cache: its open reader and the key that reader unwrapped, or, where no reader is open (a
177
+ `count()` answered from the row opens none), the row it resolved. A read during the outage that needs the key,
178
+ where none was unwrapped before it, unwraps it from that row's wrapped keys. The refresh asks again 500 ms later, or
179
+ after `cache.genTtlMs` if that is shorter. So while the registry cannot be read, a shred or a drop is not seen, and
180
+ the store converges within one retry of the registry answering. A segment the reader cache has let go is served only
181
+ until its resolution lapses: after that its next read fails with the fault, as a cold read does. Any other failure
182
+ of the refresh (an access denial, a row that will not parse) is not ridden out: the read that finds it fails with
183
+ that error, and the reader is dropped with the key it held.
162
184
 
163
185
  `destroySegment` and `eraseNamespace` are free functions over raw drivers, not verbs of a store, so for them every
164
186
  store is another store, one in the same process included.
@@ -261,10 +283,10 @@ to run, and the deletion is ours to perform correctly.** Practical patterns:
261
283
  The registry row's `retention` is untouched by a load, an `*Into` materialization or an erasure rewrite, so the
262
284
  `expiresAt` you set stays put across all of them.
263
285
  - Surface segment age and size so unbounded growth is visible, not silent. The **metrics sink** carries neither (its `storage.get` events count the bytes of each read, not a segment's size).
264
- `seg.count()` gives a segment's cardinality; `seg.costReport()` prices its current generation's measured size
265
- (`monthlyUSD.byOp.storage`, $0 when the storage source cannot measure it), and does not count superseded
266
- generations still in the bucket, which `store.generations(ref)` lists; and its registry row carries `createdAt`
267
- and `updatedAt`, which the backend's `registry.list()` returns for every row.
286
+ `seg.count()` gives a segment's cardinality; `seg.stat()` gives its current generation's size in bytes (`sizeBytes`,
287
+ `null` when the storage source cannot measure it), and does not count superseded generations still in the bucket,
288
+ which `store.generations(ref)` lists; and its registry row carries `createdAt` and `updatedAt`, which the
289
+ backend's `registry.list()` returns for every row.
268
290
 
269
291
  **Be precise about what "drop the oldest" involves**, because the three levers differ in what they guarantee:
270
292
 
@@ -276,10 +298,10 @@ to run, and the deletion is ours to perform correctly.** Practical patterns:
276
298
  - **A deleted row keeps its record only where the registry cannot remove it.** Where the registry reports
277
299
  `conditionalDelete` (the default for S3 when its client sends to an AWS S3 host, for
278
300
  Azure Blob, the local filesystem and memory), `registry.delete` and the retention sweep's purge of a tombstone remove
279
- a row created by 0.12 from the bucket, and its token's random incarnation id keeps a re-create apart from it. Where it
280
- does not (an S3 client that sends to an S3-compatible store or an emulator, or a GCS client, by default, or
281
- `conditionalDelete: false`), and for a row written by a release before 0.12 on any backend, a delete writes a deleted marker that holds
282
- the record, so the row's token counter survives a re-create. A tombstone left by `dropSegment` or `destroySegment`
301
+ the row from the bucket, and a re-create's random incarnation id keeps it apart from the removed row. Where it does not
302
+ (an S3 client that sends to an S3-compatible store or an emulator, or a GCS client, by default, or
303
+ `conditionalDelete: false`), a delete writes a deleted marker that holds the record, so the row's token counter
304
+ survives a re-create. A tombstone left by `dropSegment` or `destroySegment`
283
305
  holds no wrapped key and no summary, since both clear them, so a purge that leaves a tombstone keeps the name, the
284
306
  pointer, the retention policy and the timestamps. A **live** row deleted directly with `registry.delete` keeps its
285
307
  summary, the current generation's id count and your metadata, in a marker where one is written.
@@ -308,12 +330,11 @@ So the two are complements, not alternatives: **`dropSegment` for "stop paying f
308
330
  > ⚠️ **Never let a lifecycle rule expire a registry row's current version, a tombstone, or a due-index pointer** —
309
331
  > a separate trap, and a worse one. A rule cannot tell a live row from a tombstone, and an expired live row is a
310
332
  > segment whose pointer is gone: its generations look unreferenced, and nothing reads or collects them. The library
311
- > removes a row only by a delete the store applies to the exact version it judged, and only a row whose token
312
- > carries a random incarnation id, so a name re-created later is told apart from it with overwhelming probability.
313
- > A tombstone of a row written by a release before 0.12 carries the row's token counter on instead, and that counter
314
- > is what keeps the name's tokens unique against a process still on that release. That token is the segment's
315
- > **identity**: it is what a cached reader, a fenced publish and a generation-collection pass each compare to decide
316
- > whether two observations describe the same segment. Re-issue one and they can all answer "yes" about a segment that
333
+ > removes a row only by a delete the store applies to the exact version it judged, and every row's token carries a
334
+ > random incarnation id, so a name re-created later is told apart from it with overwhelming probability. That token is
335
+ > the segment's **identity**: a fenced publish and a generation-collection pass compare it, and a cached reader
336
+ > compares the row's `pointerId`, itself one of the row's tokens, to decide whether two observations describe the same
337
+ > segment. Re-issue one and they can all answer "yes" about a segment that
317
338
  > no longer exists — serving a deleted incarnation's data, or collecting a live one's objects. A rule on
318
339
  > *noncurrent* versions of the registry prefix touches neither the current row nor its tombstone; what it shortens is
319
340
  > the history a registry restore picks from, and the time a crypto-shred takes to complete (above).
@@ -332,8 +353,7 @@ response, a removal the registry refused (`purgeFaults` counts it), or a pointer
332
353
  it reads, and an unscoped fleet scan, one given no `namespace`, from every day. A deployment that scopes every sweep to a
333
354
  namespace, or runs only index scans, keeps such a pointer until an unscoped fleet scan runs. Where the registry does not
334
355
  report `conditionalDelete` (an S3 client that sends to an S3-compatible store or an emulator, or a GCS client, by default, or
335
- `conditionalDelete: false`), and for a row written by a release before 0.12 on any backend, the purge leaves a tombstone
336
- instead: every one of those fields, in the bucket, indefinitely, read by every full listing. A registry that does not
356
+ `conditionalDelete: false`), the purge leaves a tombstone instead: every one of those fields, in the bucket, indefinitely, read by every full listing. A registry that does not
337
357
  report it files no pointer to begin with. A removed
338
358
  row stays recoverable wherever the storage keeps a copy of it: with object versioning on, its earlier versions stay until
339
359
  a noncurrent-version rule expires them, as an overwritten row's do; with soft delete on, it stays for the retention
@@ -382,8 +402,13 @@ Wire the **audit sink** (`IAuditSink`) to get an append-only, vendor-neutral rec
382
402
  state changes — `segment.publish` (a loaded generation became current), `segment.load-refused` (a load that did
383
403
  not publish, because its guard refused it or another writer got there first), `segment.rollback` (an operator moved
384
404
  the pointer to a generation it named), `segment.rewrite` (a subject-erasure
385
- rewrite: `fromGeneration` → `generation`), `segment.erase` (a genuine crypto-shred), `segment.dispose` (a
386
- `dropSegment`, including every retirement the sweep performs) and `namespace.erase` — for your audit log / SIEM.
405
+ rewrite: `fromGeneration` → `generation`), `segment.collect` (a subject erasure that rewrote nothing and deleted what
406
+ no reader resolves: the generations holding the id, when it found the id only outside the current generation, or, with
407
+ no `fromGeneration`, only objects no read of the segment can open, which it deletes whatever the id), `segment.erase`
408
+ (a genuine
409
+ crypto-shred), `segment.dispose` (a `dropSegment`, including every retirement the sweep performs) and
410
+ `namespace.erase` — for your audit log / SIEM. Each `segment.*` event names the segment's `incarnation` when its
411
+ registry token carries one, so a segment created again under the same name is told apart from the one before.
387
412
  It is off by default and exception-safe. See the [dashboards guide](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/dashboards.md), which also says
388
413
  which event is the receipt for which claim. An erasure *ledger* — per-subject-request proof of physical deletion
389
414
  — is returned by **`eraseSubject`**. `subjectReport` is the read side and returns only which segments an id is
package/README.md CHANGED
@@ -14,6 +14,7 @@ file, then ask `has`, `count`, `iterate`, `intersect`, `union` and `andNot`, wit
14
14
  ```bash
15
15
  pnpm add @cloudbitmaps/roaring # the store, with in-memory and local-disk backends
16
16
  pnpm add @cloudbitmaps/s3 # the storage you have: or @cloudbitmaps/gcs, or @cloudbitmaps/azure-blob
17
+ pnpm add @cloudbitmaps/tools # optional: price a store, offline
17
18
  ```
18
19
 
19
20
  On npm 12 and pnpm 10 and later, allow `roaring`'s one install script first, or the install exits 0 and the package throws at `import`. Put this in your `package.json`: `{ "allowScripts": { "roaring": true }, "pnpm": { "onlyBuiltDependencies": ["roaring"] } }`. npm 11 runs the script but warns until you allow it the same way; pnpm 9 needs nothing extra. [Details](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/getting-started.md#cannot-find-module-buildreleaseroaringnode-after-a-successful-install).
@@ -83,7 +84,8 @@ pointer read: it reads no payload and no object.
83
84
  The trade is stated plainly. A membership check that misses the cache costs a ranged GET against object storage,
84
85
  where an in-process store costs a memory read. If you need sub-millisecond answers on a working set that fits a
85
86
  bounded cache, use Redis. [The benchmarks](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/benchmarks.md)
86
- give the method and what the numbers do not establish.
87
+ give the method and what the numbers do not establish. To price your own store, from the sizes `seg.stat()` reports, use
88
+ `@cloudbitmaps/tools` ([the cost guide](https://github.com/cloudbitmaps/cloudbitmaps/blob/main/docs/guide/cost.md)).
87
89
 
88
90
  ## Before production
89
91