From 06401ce90718c86e7337ff44190dc952af36d8a6 Mon Sep 17 00:00:00 2001 From: Aayush Shah Date: Wed, 24 Feb 2021 14:55:51 -0500 Subject: [PATCH] kvserver: re-add spuriously removed nil check in `relocateOne` e924d91081fdc8c66650cf8654b2008d01a8eb41 introduced a bug by spuriously removing a nil check over the result of a call to `allocateTargetFromList`. This commit re-adds the check. The bug could cause a panic when `AdminRelocateRange` was called by the `StoreRebalancer` or the `mergeQueue` if one (or more) of the stores that are supposed to receive a replica for a range become unfit for receiving the replica (due to balancing reasons / or shifting constraints) _between when rebalancing decision is made and when it's executed_. Resolves #60812 Release justification: fixes bug that causes a panic Release note: None --- pkg/kv/kvserver/replica_command.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/kv/kvserver/replica_command.go b/pkg/kv/kvserver/replica_command.go index 5de61f2a5aaa..6aeb575f9c5e 100644 --- a/pkg/kv/kvserver/replica_command.go +++ b/pkg/kv/kvserver/replica_command.go @@ -2925,6 +2925,10 @@ func (s *Store) relocateOne( existingNonVoters, s.allocator.scorerOptions(), args.targetType) + if targetStore == nil { + return nil, nil, fmt.Errorf("none of the remaining %ss %v are legal additions to %v", + args.targetType, args.targetsToAdd, desc.Replicas()) + } target := roachpb.ReplicationTarget{ NodeID: targetStore.Node.NodeID,