[codex] Recover shard materializers on restart#77
Conversation
|
Hey Jason, hope all is going well. I think this was an actual bug but please comment to let me know before I change the draft status. |
|
Restart-recovery findings from exercising this on a single-node metagraph store We've been trying to use this PR to get single-node restart recovery working (metagraph's vendored bedrock 1. Upstream timing race (before this PR's code runs). On restart the Coordinator becomes leader and starts the Director with an empty 2. The deeper gap — the shard↔worker mapping isn't persisted. Even with workers re-advertised,
So Repro: seed a single-node tenant, then re-open the same store in a second process. Glad to help or contribute the timing-race gate if useful. |
|
Update — prototyped the gate + a stable system-materializer id; surfaces the next layer Following up on the above: on a branch we prototyped both halves of layer 1+2 and verified against a live single-node metagraph store.
Result: the "System shard materializer not found, creating new one" path is gone — recovery now reuses the persisted system materializer instead of creating an empty one. But it surfaces the next layer: the found materializer then reports Happy to share the branch (the gate + the id change, full suite green) if it's a useful starting point — and glad to defer on the data-recovery layer. |
Summary
This fixes existing-cluster recovery so Bedrock restores a complete
shard_materializersmap after a durable restart, instead of recovering only the metadata/system materializer.The change:
RecoveryAttemptcarry:shard_materializersas a first-class recovery field;MaterializerBootstrapPhaseexisting-cluster recovery to recover a materializer for every shard tag in the recovered shard layout;"metadata_materializer"lookup for system shard tag0only;{:materializer, ref, shard_id};Bug Description
Bedrock's default keyspace layout has separate shard tags for system metadata and user/data keys:
0serves system keys, including\xff/system/shard_keys/*;1serves normal user/data keys.On fresh cluster bootstrap, Bedrock already creates materializers for all shard tags in the default layout and stores them in
recovery_attempt.shard_materializers. That gives topology enough information forLayoutIndexto route reads for both system and user shards.The existing-cluster restart path was asymmetric. It recovered only the system/materializer used as
metadata_materializer, queried the shard layout from it, and then advanced without rebuildingrecovery_attempt.shard_materializers.TopologyPhasethen copiedMap.get(recovery_attempt, :shard_materializers, %{})into the transaction system layout, producing an empty shard-materializer map after restart.That empty map breaks non-system reads.
LayoutIndexcan route tag0throughmetadata_materializer, but every non-system shard tag depends on:shard_materializers. After restart, user/data shard reads can therefore have no read server even though the cluster recovered enough metadata to know the shard layout.In practice this shows up as a durable cluster restart where metadata recovery succeeds, but normal user/data reads fail because the read-serving topology is incomplete.
Fix Details
The existing-cluster materializer bootstrap now does the recovery in two steps:
For each shard tag, recovery now:
shard_materializersmap.The resulting recovery attempt now enters topology with both
metadata_materializerand a complete%{shard_tag => materializer_pid}map.Compatibility Notes
The legacy
"metadata_materializer"service lookup remains supported for the system shard. Non-system shards require either shard-tagged materializer service entries or materializer-capable nodes so recovery can create the missing materializers. This avoids treating the metadata materializer as a read server for unrelated user/data shards.LogRecruitmentPhasealso now filters log services by explicit log tuple shape instead of destructuring every service tuple as two elements. That keeps recovery compatible with shard-tagged materializer service tuples inavailable_services.Validation
Ran locally:
mix test test/bedrock/control_plane/director/recovery/materializer_bootstrap_phase_test.exsmix test test/bedrock/control_plane/director/recoverymix testmix format --check-formattedmix credo --strictgit diff --checkFull suite result:
13 doctests, 158 properties, 2300 tests, 0 failures (17 excluded).