◐ Off-By-One · answer catalog

bash-ceph-crush-straw2-failure-domain-placement-exactness

2 answer(s)shellbashshellbash

bash-ceph-crush-straw2-failure-domain-placement-exactness

📦 Source in repository (JSON)

Answer 1

The solution is complete and verified. Here's a summary of what I found and built.

Diagnoses (why naive bash/awk CRUSH fails)

  1. "straw" ≠ "straw2". The ubiquitous formula draw = (hash & 0xffff) * weight (max wins) is the pre-straw2 scheme. Measured on weights [2,3,2,2,1.5,2] it gave win rates 0.128 / 0.461 / 0.026 instead of 0.16 / 0.24 / 0.12 — the heavy host got 46% and the 1.5 host got 2.6%. Real straw2 races fixed-point exponentials: draw = (crush_ln(u) - 2^48) / weight, max wins.

  2. Map weight vs live reweight. Straw2/bucket weights are the fixed CRUSH map weights; live reweight (default 1.0) only feeds is_out. Recomputing bucket weights from live weights made one-OSD failure remap 0.284 of PGs vs the 0.083 bound. Holding map weights fixed dropped it to 0.084.

  3. Off-by-four-power in crush_ln. Subtracting 2^44 instead of 2^48 made the lightest item win 93%.

  4. Portability. gawk bitwise builtins are absent in mawk; I use a 256×256 byte-XOR table for exact 32-bit rjenkins1.

  5. Failure domain. Collision must be checked on the target bucket (host), not just the leaf.

Deliverable

~/SOLUTION.md (also ~/crush/SOLUTION.md) — self-contained with root-cause analysis, the full exact fix (all files inline), and verification. Supporting files in ~/crush/: crush.awk (825 lines), mkmap.sh, run.sh, verify.sh, check_hash.sh.

Verification results

Final suite: RESULT: 6 passed, 0 failed.

The code block was extracted back out of the markdown and re-run to confirm the document is directly usable.

Evidence & signatures

# Evidence
- Problem class: bash-ceph-crush-straw2-failure-domain-placement-exactness
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-25T10:56:48.044Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement CRUSH map evaluation in bash and awk: parse a CRUSH hierarchy (root/rack/host/OSD buckets with weights, straw2 leaf selection, a rule with chooseleaf and firstn replica counts), place every placement group while honoring failure-domain separation, and emit a canonical JSON mapping snapshot plus per-PG bucket retrace evidence. Use exact fixed-point weighted-hash arithmetic so placement is reproducible across bash versions, then prove the stability and balance properties: after adding or removing a single OSD the fraction of remapped PGs must stay within the analytic CRUSH bound, and long-run per-OSD PG share must track normalized weight within tolerance even with heterogeneous failures and reweighted (out) OSDs.", "environment": "bash", "language": "shell", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "bash-ceph-crush-straw2-failure-domain-placement-exactness", "provider": "openrouter", "solved_at": "2026-09-25T10:56:48.045Z", "version": "5.2"}

Answer 2

The solution is complete and verified. Here's a summary of what I found and built.

Diagnoses (why naive bash/awk CRUSH fails)

  1. "straw" ≠ "straw2". The ubiquitous formula draw = (hash & 0xffff) * weight (max wins) is the pre-straw2 scheme. Measured on weights [2,3,2,2,1.5,2] it gave win rates 0.128 / 0.461 / 0.026 instead of 0.16 / 0.24 / 0.12 — the heavy host got 46% and the 1.5 host got 2.6%. Real straw2 races fixed-point exponentials: draw = (crush_ln(u) - 2^48) / weight, max wins.

  2. Map weight vs live reweight. Straw2/bucket weights are the fixed CRUSH map weights; live reweight (default 1.0) only feeds is_out. Recomputing bucket weights from live weights made one-OSD failure remap 0.284 of PGs vs the 0.083 bound. Holding map weights fixed dropped it to 0.084.

  3. Off-by-four-power in crush_ln. Subtracting 2^44 instead of 2^48 made the lightest item win 93%.

  4. Portability. gawk bitwise builtins are absent in mawk; I use a 256×256 byte-XOR table for exact 32-bit rjenkins1.

  5. Failure domain. Collision must be checked on the target bucket (host), not just the leaf.

Deliverable

~/SOLUTION.md (also ~/crush/SOLUTION.md) — self-contained with root-cause analysis, the full exact fix (all files inline), and verification. Supporting files in ~/crush/: crush.awk (825 lines), mkmap.sh, run.sh, verify.sh, check_hash.sh.

Verification results

Final suite: RESULT: 6 passed, 0 failed.

The code block was extracted back out of the markdown and re-run to confirm the document is directly usable.

Evidence & signatures

# Evidence
- Problem class: bash-ceph-crush-straw2-failure-domain-placement-exactness
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-25T10:56:48.044Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement CRUSH map evaluation in bash and awk: parse a CRUSH hierarchy (root/rack/host/OSD buckets with weights, straw2 leaf selection, a rule with chooseleaf and firstn replica counts), place every placement group while honoring failure-domain separation, and emit a canonical JSON mapping snapshot plus per-PG bucket retrace evidence. Use exact fixed-point weighted-hash arithmetic so placement is reproducible across bash versions, then prove the stability and balance properties: after adding or removing a single OSD the fraction of remapped PGs must stay within the analytic CRUSH bound, and long-run per-OSD PG share must track normalized weight within tolerance even with heterogeneous failures and reweighted (out) OSDs.", "environment": "bash", "language": "shell", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "bash-ceph-crush-straw2-failure-domain-placement-exactness", "provider": "openrouter", "solved_at": "2026-09-25T10:56:48.045Z", "version": "5.2"}
Generated from the verified corpus · MIT licensedBack to the catalog