From 402da16d28feebaf41c554ccc409ff625c7d3cd1 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Wed, 25 Dec 2024 17:52:07 +0800 Subject: [PATCH] fix(replica): reconstruct ActiveChain and SnapshotLvolMap while creating replica If the replica's ActiveChain and SnapshotLvolMap is not constructed while creating replica, the mismatches found by the validateAndUpdate() will result in the error state of the replica. ``` .... newSnapshotLvolMap, err := constructSnapshotLvolMap(r.Name, bdevLvolMap) if err != nil { return err } if len(r.SnapshotLvolMap) != len(newSnapshotLvolMap) { return fmt.Errorf("replica current active snapshot ....") } ... ```` Longhorn 10033 Signed-off-by: Derek Su --- pkg/spdk/replica.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/spdk/replica.go b/pkg/spdk/replica.go index e8ceb63e..706c9158 100644 --- a/pkg/spdk/replica.go +++ b/pkg/spdk/replica.go @@ -249,7 +249,7 @@ func (r *Replica) construct(bdevLvolMap map[string]*spdktypes.BdevInfo) (err err }() switch r.State { - case types.InstanceStatePending: + case types.InstanceStateStopped, types.InstanceStatePending: break case types.InstanceStateRunning: if r.isRebuilding { @@ -735,6 +735,16 @@ func (r *Replica) Create(spdkClient *spdkclient.Client, portCount int32, superio if err := r.prepareHead(spdkClient, backingImage); err != nil { return nil, err } + + // Construct the snapshot lvol map and the active chain + bdevLvolMap, err := GetBdevLvolMapWithFilter(spdkClient, r.replicaLvolFilter) + if err != nil { + return nil, err + } + if err := r.construct(bdevLvolMap); err != nil { + return nil, err + } + r.State = types.InstanceStateStopped podIP, err := commonnet.GetIPForPod()