Repository navigation
Commit ad622d3
fix(cluster): an object authored during a store outage is served by every replica after its resync (#31816)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi926TiHxhsZMVATUkqxg2xD2)_
Fixes #31722
Clause-②: yes (widening)
Metadata-protocol: none
Measured on the diff: one new public method,
`ObjectStackProtocolImplementation.resyncMetadataMutationPubSub()`, and
its
result type `MetadataMutationResyncReport`, exported from
`@objectstack/metadata-protocol`. Nothing is removed or made required.
The
claim read `no`; the measurement says `yes (widening)`, as it did for
#31721.
No metadata an author writes changes.
## 维护者速读
- 改了什么:多副本集群中,Redis 等共享存储断线期间在 A 副本上新建、修改或删除的对象,B
副本在自己的集群驱动重连(`cluster.resync`)后会自动收敛,不再需要重启。
- 为什么改:`metadata.mutated`
通道(让其他副本注册新对象的那条)是唯一没有重同步入口的通道;断线期间丢失的提示会让其他副本一直回答
`OBJECT_NOT_FOUND`(或旧定义、或已删除的对象),直到重启。
- 风险与回滚:单节点(默认内存驱动)完全不变,从不触发;重同步只读本副本自己的
`sys_metadata`,读失败时不删除任何注册项。回滚即撤销本 PR。
- 先看:`metadata-protocol` 的新文件 `protocol-mutation-resync.ts`(选哪些项重新收敛),以及
`service-cluster` 的 `metadata-cluster-bridge-plugin.ts`(注册一行)。
- 两分钟验证:`cd packages/runtime && pnpm exec vitest run
src/cluster-metadata-mutation-resync.integration.test.ts`,两个内核共享一个
SQLite 文件和一条会丢消息的总线。
- 需要你做的:无。
## What changes
- **Lane 2 has a resync seam (`@objectstack/metadata-protocol`).**
`resyncMetadataMutationPubSub()` reads `sys_metadata`'s active rows
once,
with only their address and `checksum` and never a body. It then
re-converges each item a lost hint could have touched:
- a row whose checksum moved since this replica last converged on it (a
lost
save or publish);
- an item this replica converged on that has no active row now (a lost
delete);
- an item a hint or a local write named since the last convergence (a
revert
brings an earlier checksum back, so the checksum alone cannot tell).
Each item goes through `applyRemoteMetadataMutation`, the applier a
delivered hint runs, from this replica's own re-read. Nothing travels on
the
wire. A row that is gone takes the delivered delete's heal walk.
- **The baseline.** `attachMetadataMutationPubSub` seeds a per-replica
ledger
with one active-row read. Every convergence keeps the ledger current.
Hints
and local writes mark items. Resyncs run one at a time, and an item
touched
during a resync stays marked. With no baseline (the seed read failed),
the
first resync re-converges every active row.
- **A read that fails is never a delete.**
- If the active-row read fails, the resync rejects and changes nothing.
- If one item's re-read fails, that item is kept as this replica holds
it and
stays marked for the next resync. The failures are logged once per
resync
(`console.error`, with the items and the first cause).
- **The bridge calls it (`@objectstack/service-cluster`).**
`MetadataClusterBridgePlugin` registers lane 2 through
`registerLaneResync`
on the same `cluster.resync` event as lanes 1, 3, 4 (#31721) and 5
(#31597). A protocol
that predates the seam is skipped, and a rejected resync is a warning,
as
for the other lanes.
- **Docs.** `content/docs/kernel/cluster.mdx` §6.2 and the bridge
docblock now
describe lane 2's resync instead of "Lane 2 has no resync yet".
## Why
#31721 left the `metadata.mutated` lane as the one lane without a
resync. Its
hint is what makes a peer re-run the ObjectQL registry write-through. So
a hint
lost during a store outage left every other replica answering
`OBJECT_NOT_FOUND` for an object authored meanwhile (or serving its old
body,
or serving it after a delete) until restart.
### Step 0: full re-convergence vs a diff
Measured on a booted showcase (`bootShowcase`,
`OS_METADATA_WRITABLE=object`),
with N objects authored and the lane attached:
| N | Diff, nothing lost | Diff, 5 changed | Full re-apply of every row
| Listener replays (full) |
| --- | --- | --- | --- | --- |
| 50 | ~1 ms, 50 unchanged | 12 ms, 5 converged | 97 ms | 50 |
| 300 | 2 ms, 300 unchanged | 9 ms, 5 converged | 406 ms | 300 |
The address-and-checksum read takes ~1 ms at both sizes. These are
shared-box timings, so read them as ratios.
**Choice: the diff.** A full re-apply costs one delivered-hint
convergence per
stored row on every reconnect. Each convergence also replays the item
into
the local mutation listeners, and some of those re-sync a whole family
per
event (authored hooks and actions). So the cost grows with the catalog
even
when nothing was lost. A since-timestamp re-read was ruled out:
- a hard delete leaves no active row to carry a timestamp;
- the writers' clocks are not this replica's.
### A finding from the measurement
On the booted showcase, the first build's resync and seed reads were
refused
with `PermissionDeniedError` (a read under a context that carries no
principal). Every resync would have failed on a secured stack. Both
reads now
carry `context: { isSystem: true }`, as the repository's own reads do.
The
fan-out harness now refuses a principal-less column-subset read, as the
secured engine does, so this is pinned (A8a/A8b below). The two-kernel
test
has no security plugin, so it could not catch it.
## Tests
-
`packages/metadata-protocol/src/protocol.cluster-mutation-fanout.test.ts`:
a new `[#31722] cluster.resync` describe with 10 cases. The shared
harness
gains a read fault (every read, or item re-reads only), the registered
labels, and the principal-less refusal:
- ⭐ an object authored while the hint was lost is served after the
resync;
- a lost update re-converges that item only, and an unchanged item is
not
re-applied;
- a lost delete takes the heal walk;
- a delete of a row present at attach is found from the baseline;
- a revert to an earlier checksum after a delivered hint;
- a local write on the peer is re-read;
- a failed active-row read rejects and keeps every entry;
- an item whose re-read fails is kept, logged once, and retried;
- CONTROL: nothing lost means nothing is re-applied;
- CONTROL: with no transport, the seam does nothing.
-
`packages/services/service-cluster/src/metadata-cluster-bridge-plugin.test.ts`:
- the existing resync cases now assert lane 2 and the info line;
- 2 new cases: a protocol that predates the seam, and a rejected
protocol
resync is a warning.
-
`packages/runtime/src/cluster-metadata-mutation-resync.integration.test.ts`
(new): two `LiteKernel`s over one SQLite file, a lossy bus, a `test-bus`
driver with liveness, and the real bridge.
- ⭐ author on A with the hint lost. B does not know the object. B's
`cluster.resync` runs. B serves the object and its row.
- CONTROL: a delivered hint converges B with no resync.
- CONTROL: on the `memory` driver, the seam is never called (R3: the
in-process driver never emits `cluster.resync`).
### Ablations
Each was run against the tests above, first on the pre-merge head and
again
on the merged head. All went red both times, and each restore left the
file
equal to HEAD.
| # | Mutation | Red |
| --- | --- | --- |
| A1 | bridge lane-2 registration removed | 3 bridge cases; the runtime
⭐ through the built `dist` |
| A2 | active-row read failure swallowed (rows = []) | the failed-read
case |
| A3 | a failed item re-read drops its key | the item-failure case |
| A4 | no unchanged skip | 2 |
| A5 | the hint's touch removed | 4 |
| A6 | lane-2 resync registered before the in-process guard | 4 (the
memory CONTROL included) |
| A7 | the local write's touch removed | the local-write case |
| A8a | the seed read without the system context | the baseline-delete
case |
| A8b | the resync read without the system context | 9 |
The A1 runtime leg uses a preflight marker that is present in the
pristine
`dist`, absent under the mutation, and present after the restore.
## Acceptance notes
- Delete semantics follow the delivered-hint path, because it is the
same
applier. A per-item re-read failure is logged and kept, not deleted.
- The seed read runs once per attach, only where the bridge attaches (a
driver
that crosses a process boundary).
- R3 holds: the `memory` driver never emits `cluster.resync`, and the
bridge
never attaches lane 2 on it.
- Landing order: #31597 (PR #31785, the settings lane) edited the same
bridge
file and §6.2 and landed first. `main` is merged in after it (a merge
commit). Lane 5 stays at `kernel:bootstrapped` with `subscribeResync()`
in
both phases; lane 2 registers at `kernel:ready` like lanes 1 to 4.
## Verification
- Per touched package, `pnpm typecheck` and package-scoped lint (root
eslint
on the directory, `--no-inline-config`) exit 0. A full `vitest run`:
| Package | Test files | Tests |
| --- | --- | --- |
| metadata-protocol | 329 passed, 4 skipped | 22607 passed, 26 skipped |
| service-cluster | 11 | 158 |
| runtime | 568 | 10424 passed, 19 skipped |
- All of the above ran on the merged head `70a46315`.
- `dispatch-gates.mjs --commands` was derived on `70a46315` and gave 104
commands. Each was run (all exit 0) and reconciled with `--ran`: 104
derived, 104 run, 0 NOT-MEASURED. `check-nul-bytes` exits 0.
- Forced test edits: none. The existing bridge resync cases gained lane
2 in
their assertions, and the fan-out suite's shared harness was extended.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(`packages/spec` untouched.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: n/a.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmQr9knGGTwQc6UKmnE
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4ed2092 commit ad622d3
11 files changed
Lines changed: 831 additions & 14 deletions
File tree
- .changeset
- content/docs/kernel
- packages
- metadata-protocol/src
- runtime/src
- services/service-cluster/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
379 | | - | |
380 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
381 | 382 | | |
382 | 383 | | |
383 | 384 | | |
384 | 385 | | |
385 | 386 | | |
386 | | - | |
387 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
388 | 396 | | |
389 | 397 | | |
390 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
167 | 170 | | |
168 | 171 | | |
169 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
| 61 | + | |
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
| |||
323 | 326 | | |
324 | 327 | | |
325 | 328 | | |
326 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
327 | 334 | | |
328 | 335 | | |
329 | 336 | | |
330 | 337 | | |
331 | 338 | | |
332 | | - | |
| 339 | + | |
333 | 340 | | |
334 | 341 | | |
335 | 342 | | |
336 | 343 | | |
337 | 344 | | |
338 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
339 | 357 | | |
340 | 358 | | |
341 | 359 | | |
| |||
350 | 368 | | |
351 | 369 | | |
352 | 370 | | |
| 371 | + | |
353 | 372 | | |
354 | 373 | | |
355 | 374 | | |
| |||
365 | 384 | | |
366 | 385 | | |
367 | 386 | | |
368 | | - | |
| 387 | + | |
369 | 388 | | |
370 | 389 | | |
371 | 390 | | |
372 | 391 | | |
373 | 392 | | |
374 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
375 | 410 | | |
376 | 411 | | |
377 | 412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
0 commit comments