"""Exact fractional placement ceiling, not a Ceph simulator.""" from fractions import Fraction import json def capacity(value): if isinstance(value, bool) or not isinstance(value, (int, str, Fraction)): raise ValueError("Use integers, decimal strings or Fraction, not floats") try: result = Fraction(value) except (ValueError, ZeroDivisionError) as error: raise ValueError("Capacity must be a finite rational") from error if result < 0: raise ValueError("Capacity must be nonnegative") return result def placement_ceiling(capacities, shards): """Maximum data per shard position; one shard per domain, divisible data.""" if isinstance(shards, bool) or not isinstance(shards, int) or shards < 1: raise ValueError("shards must be a positive integer") values = sorted(capacity(value) for value in capacities) if len(values) < shards: return Fraction(0) remaining = sum(values, Fraction(0)) best = remaining / shards # Excluding j largest domains leaves at least shards-j copies elsewhere. for j in range(1, shards): remaining -= values[-j] best = min(best, remaining / (shards - j)) return best def example(label, capacities, shards=3, data_shards=1, ratio="1"): values = [capacity(value) for value in capacities] threshold = capacity(ratio) if not 0 < threshold <= 1: raise ValueError("ratio must be in (0, 1]") if (isinstance(data_shards, bool) or not isinstance(data_shards, int) or not 1 <= data_shards <= shards): raise ValueError("data_shards must be an integer from 1 through shards") budgets = [value * threshold for value in values] x = placement_ceiling(budgets, shards) return { "label": label, "domain_capacity_TiB": [str(value) for value in values], "threshold": str(threshold), "shards": shards, "data_shards": data_shards, "per_position_TiB": str(x), "logical_TiB": str(data_shards * x), "raw_used_TiB": str(shards * x), "stranded_within_budget_TiB": str(sum(budgets) - shards * x), "reserved_by_threshold_TiB": str(sum(values) - sum(budgets)), } def results(): return { "schema_version": 1, "evidence": "Constructed exact arithmetic, not measurements or Ceph execution", "assumptions": [ "One equal-sized shard per distinct domain", "Freely divisible data and unrestricted combinations of eligible domains", "Capacity budgets are dedicated to this pool; no existing allocations", "No placement-group skew, metadata overhead or transient migration space", ], "examples": [ example("Three unequal domains", [60, 20, 20]), example("Expand only the largest", [120, 20, 20]), example("Add a fourth domain", [60, 20, 20, 20]), example("Expand both small domains", [60, 40, 40]), example("2+1 equal-sized erasure shards", [60, 20, 20], data_shards=2), example("Four domains at 95 percent", [60, 20, 20, 20], ratio="0.95"), example("Largest domain lost; 90 percent budget", [0, 20, 20, 20], ratio="0.90"), ], } if __name__ == "__main__": print(json.dumps(results(), indent=2) + "\n", end="")