Bug Report: `BackupShard` mispairs tablets and replication statuses when a status read fails
Overview of the Issue
ShardReplicationStatuses returns two parallel slices, where stats[i] is the status of tablets[i]. When it returns an error, BackupShard replaces tablets with the filtered candidate list but leaves stats untouched, then keeps indexing stats[i] by the new list (Code)
tablets = reparentutil.GetBackupCandidates(tablets, stats)
...
for i, tablet := range tablets {
...
if stats[i].ReplicationLagUnknown {As soon as a filtered-out tablet precedes a kept one the pairing shifts, so the selection reads another tablet's replication lag. And because GetBackupCandidates keeps a PRIMARY whose status is nil, stats[i] can be nil, which panics into panicHandler and fails the backup with a misleading error rather than crashing
I have a fix with a regression test ready and am happy to open the PR with Backport to: release-24.0 and release-23.0. It was found while working on https://github.com/vitessio/vitess/pull/21302, where @mhamza15 suggested splitting it out so it can be backported.
Reproduction Steps
On a shard where one replica's ReplicationStatus call fails — an unreachable or starting tablet — run BackupShard. The backup either picks a tablet by the wrong tablet's lag, or fails with an error unrelated to the real cause. It is order-dependent: ShardReplicationStatuses builds its slice from maps.Values(), so whether the mispairing bites varies per run.
Binary Version
$ vtctld --version
vtctld version Version: 24.0.2 (Git revision 181d22c8f1dca63f5c8846be9b39f712a2412fff branch 'v24.0.2') built on Thu Sep 17 11:57:49 UTC 2026 by root@buildkitsandbox using go1.26.5 linux/amd64
# Present since https://github.com/vitessio/vitess/pull/14604, confirmed in release-23.0 and release-24.0 and on main.Operating System and Environment details
# vtctld runs in a container on Kubernetes.
# Not environment-specific: the mispairing is in the selection logic and does not depend on OS, arch or topo backend
# Container (where the vtctld binary runs) — cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
# Host node
osImage: Rocky Linux 9.8 (Blue Onyx)
kernelVersion: 6.6.66-2.el9.x86_64
architecture: amd64
$ uname -sr
Linux 6.6.66-2.el9.x86_64
$ uname -m
x86_64Log Fragments
# The mispairing is order-dependent. Running the added regression test against
# unfixed main, 12 consecutive runs of the single subtest:
#
# pass=2 fail=10
#
# ShardReplicationStatuses builds its slice with maps.Values(), so whether a
# filtered-out tablet precedes a kept one varies per run.Source: vitessio/vitess