From e3dd9a335a2a384a1ebaa8cc09598f3abe5f0e51 Mon Sep 17 00:00:00 2001 From: Shuo Wu Date: Mon, 21 Oct 2024 18:16:52 +0800 Subject: [PATCH] fix: server try the best to avoid eliminating broken replicas Signed-off-by: Shuo Wu --- pkg/spdk/server.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pkg/spdk/server.go b/pkg/spdk/server.go index c95c66f7..8b8b8958 100644 --- a/pkg/spdk/server.go +++ b/pkg/spdk/server.go @@ -3,6 +3,7 @@ package spdk import ( "fmt" "net" + "reflect" "strconv" "sync" "time" @@ -254,17 +255,24 @@ func (s *Server) verify() (err error) { replicaMapForSync[lvolName] = replicaMap[lvolName] } for replicaName, r := range replicaMap { - headSvcLvol := r.Head - if headSvcLvol == nil { - delete(replicaMap, replicaName) - continue - } - // TODO: How to handle a broken replica without a head lvol - if bdevLvolMap[headSvcLvol.Name] == nil { - delete(replicaMap, replicaName) - continue + // Try the best to avoid eliminating broken replicas without a head lvol + if r.Head == nil || bdevLvolMap[r.Head.Name] == nil { + noReplicaLvol := true + for lvolName := range bdevLvolMap { + if IsReplicaLvol(r.Name, lvolName) { + noReplicaLvol = false + break + } + } + if noReplicaLvol { + delete(replicaMap, replicaName) + continue + } } } + if !reflect.DeepEqual(s.replicaMap, replicaMap) { + logrus.Infof("spdk gRPC server: Replica map updated, map count is changed from %d to %d", len(s.replicaMap), len(replicaMap)) + } s.replicaMap = replicaMap s.Unlock()