CockroachDB / NewSQL — distributed SQL database. Postgres wire-compatible, Raft per range, HLC instead of TrueTime, multi-region survival/locality, range splits/rebalancing. Inspired by Spanner (PC/EC) but no atomic clocks needed. 4 scenarios: cross-range distributed transaction (HLC + Raft + 2PC), range rebalance after node add (auto-split, auto-rebalance), multi-region locality via REGIONAL BY ROW (GDPR data residency), region failure (REGION survival mode). 2 ADRs: CockroachDB vs Postgres+Citus vs Spanner choice; HLC vs TrueTime trade-off.
Distributed SQL сохраняет SQL transactions поверх partitioned replicated keyspace, но сеть остаётся частью latency/failure model. «NewSQL» не отменяет quorum, retries, hotspots или compliance design.
| Компонент | Ответственность |
|---|---|
| SQL Client with Retry Loop | Повторяет всю transaction closure по retryable error и не дублирует side effects. |
| SQL Gateway | Планирует запрос и координирует transaction across ranges. |
| Range A Leaseholder | Обслуживает consistent operations и предлагает writes в Raft group A. |
| Range A Replica | Участвует в Raft quorum and recovery. |
| Range B Leaseholder | Вторая key range, добавляющая coordination к transaction. |
| Range B Replica | Независимая failure-domain copy range B. |
| Transaction Record and Intents | Отслеживает atomic outcome и provisional writes. |
| Clock and Locality Monitor | Контролирует clock health, lease/locality и hot ranges. |
A transaction whose keys are colocated can execute through one leaseholder and its Raft group, though acknowledgement still depends on replication and durability.
Проверяемый исход: Atomic commit is scoped to the transaction; latency is measured, not promised from topology alone.
The gateway touches two independently replicated ranges and coordinates intents/outcome. More participants mean more network and contention surface, not weaker atomicity.
Проверяемый исход: Both ranges expose one committed outcome or the transaction aborts.
Concurrent transactions form a conflict that cannot be hidden safely. The database returns a retryable serialization error; the client re-executes the whole closure.
Проверяемый исход: A stale partial retry cannot leak business side effects or break the invariant.
Loss of one replica does not automatically mean data loss; availability depends on the range quorum and locality placement. Residency/compliance requires controls beyond REGIONAL BY ROW.
Проверяемый исход: The system fails closed when quorum is unavailable and separately audits where data/backups/keys can reside.
Числа выше — учебные inputs или размерностные формулы. Их нельзя выдавать за benchmark или SLA конкретного продукта.
[CONCEPT]partitioning-strategies
Диаграмма показывает причинные границы и recovery contracts, а не скрытую реализацию конкретного managed-сервиса. Любая stronger guarantee действует только в явно названной transaction/checkpoint/acknowledgement boundary.
Введите числа или выберите пресет