Errors this answers
could not reach sufficient tablets to guarantee safetythinks it's primary but we failed to demote it
Symptom
The primary is down or hung, you run EmergencyReparentShard (ERS) to promote a replica, and it fails with something like:
could not reach sufficient tablets to guarantee safety:
error when getting replication status for alias zone1-0000000102:
rpc error: code = DeadlineExceeded desc = context deadline exceeded
replica zone1-0000000100 thinks it's primary but we failed to demote it
The shard has no writable primary, so every write to it fails until this is fixed. Running ERS again gives the same error.
Why it happens
With the semi_sync durability policy, the primary counts a write as committed once one replica has acknowledged it. So when the primary stops answering, the last committed writes may exist only on the primary and on one replica that ERS can't see.
ERS won't take that chance. It asks every tablet in the shard for its replication position and waits up to --wait-replicas-timeout. If the old primary and any tablet that could have acknowledged its writes both fail to answer, those two together might hold a write nobody else has, and ERS refuses to promote anyone. Every alias in the error is a tablet that didn't answer.
We reproduced this on Vitess v14 with a hung primary and five tablets:
| Not answering besides the primary | ERS |
|---|---|
| Nothing | Promotes the replica |
| A dead replica, still registered in the topology | Fails with this error |
| Two replicas | Fails with this error |
A replica restoring a backup (type RESTORE) | Waits out the timeout, then promotes |
| Two replicas, with semi-sync off on the candidate | Fails the same way, before and after semi-sync is turned back on |
The usual culprits are tablets whose hosts died but whose records are still in the topology, and replicas too overloaded to answer in time. A replica in RESTORE can't acknowledge writes, so it only costs you the timeout.
Check
List the shard's tablets and match every alias in the error:
vtctldclient GetTablets --keyspace commerce --shard 80-c0
For each alias, find out whether the tablet is gone for good (host terminated, disk lost) or alive but not answering (overloaded, network trouble).
Then check semi-sync on every replica. The replicas that will serve the new primary must be able to acknowledge its writes, so they need ON. On MySQL 8.0.26 and later with the new plugins the variable is rpl_semi_sync_replica_enabled; older versions and the old plugins use rpl_semi_sync_slave_enabled, so the pattern below matches both:
for t in $(vtctldclient GetTablets --keyspace commerce --shard 80-c0 | awk '{print $1}'); do
echo "== $t"
vtctldclient ExecuteFetchAsDBA "$t" "show global variables like 'rpl_semi_sync_%_enabled'"
done
Fix
1. Pick the replica to promote
A REPLICA tablet (not RDONLY, not restoring) that's healthy and answering. You'll name it explicitly instead of letting ERS choose.
2. Remove dead tablets from the topology
For each tablet in the error whose host is gone for good, delete its record:
vtctldclient DeleteTablets zone1-0000000102
In the lab, deleting the one dead replica was enough: the next ERS went through.
3. Or skip tablets that are alive but won't answer
If a tablet still exists but can't answer in time, tell ERS to go ahead without it:
vtctldclient EmergencyReparentShard commerce/80-c0 \
--new-primary zone1-0000000104 \
--ignore-replicas zone1-0000000102,zone1-0000000103
Steps 2 and 3 carry the same risk: if a tablet you removed or skipped was the only one that received the last committed writes, those writes are lost. That's the risk ERS was refusing to take for you. Take it on purpose, and write down which tablets you removed or skipped.
4. Make sure the remaining replicas can acknowledge writes
If the check above shows semi-sync OFF on replicas that will stay, turn it back on. In Vitess v14, vttablet sets semi-sync from its --enable_semi_sync flag whenever a tablet changes type, so a round trip through rdonly resets it:
vtctldclient ChangeTabletType zone1-0000000101 rdonly
vtctldclient ChangeTabletType zone1-0000000101 replica
5. Run ERS against the replica you picked
vtctldclient EmergencyReparentShard commerce/80-c0 --new-primary zone1-0000000104
Verify
vtctldclient GetTablets --keyspace commerce --shard 80-c0shows exactly oneprimary: the one you named.- Writes through vtgate succeed.
- Every remaining replica replicates from the new primary with semi-sync
ON.
Clean up
- The old primary: in the lab it rejoined as a replica of the new primary on its own once it came back. Check that it did, or delete it before anything can write to it.
- Deleted tablets: a deleted tablet stays out of the topology until its vttablet restarts. Rebuild or restart it once its host is healthy.
- Restoring replicas: let them finish. In the lab, the restoring replica came back as a replica of the new primary.
In the incident behind this page
The primary was hung, one replica was dead but still registered, another was restoring a backup, and semi-sync was off on two replicas, including at first the one we wanted to promote. We turned semi-sync back on for it, and ERS to it then succeeded. When we rebuilt the failure in a lab later, semi-sync made no difference to this error; the only way past it was removing or skipping the dead replica, so that's most likely what changed during the incident too. In a real outage several things change at once, and the one you did last isn't always the one that worked.
Gotchas
- Waiting longer won't help a dead tablet.
--wait-replicas-timeoutdefaults to 30 s in v14 and 15 s in latervtctldclientreleases. - The older
vtctlclient spells the flags differently:--keyspace_shard,--new_primary,--ignore_replicas. - A restoring replica is never a candidate, and it adds the full timeout to every ERS while it can't answer.
- Semi-sync can be off on a replica without anyone noticing until a reparent needs it. Checking every replica is worth a place in your regular on-call checks.
Further reading
- Vitess ERS hardening (vitess.io blog, September 2026): how ERS decides it's safe to promote, and what changes in Vitess 25.
Running this fleet-wide, by hand?
HASHJOIN builds the control plane that runs upgrades, failovers and repairs like this one across every host, with a lock per unit, a drain on Ctrl-C and a log you can read at 3 a.m.
New fixes and field notes by email, about once a month.