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()