Skip to content

Commit c4affa2

Browse files
authored
fix(storage): verify the V2 spare after retaining an Umami claim (#6720)
1 parent d310e03 commit c4affa2

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎scripts/migrate-longhorn-v2/cnpg_standby_retire.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ func verifyUmamiSpareBeforeRetirement(ctx context.Context, journal *umamiStandby
136136
}
137137
spare := journal.record.Original.Spare
138138
current, err := readUmamiV2Standby(ctx, journal.c, observation, spare.Pod.Name, qualified.Disks)
139-
if err != nil || !reflect.DeepEqual(current, spare) {
139+
if err != nil {
140+
return err
141+
}
142+
if !reflect.DeepEqual(current, spare) {
140143
return errors.New("the witnessed Umami V2 spare changed before eviction")
141144
}
142145
return nil

‎scripts/migrate-longhorn-v2/cnpg_standby_v2.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func bindUmamiV2Standby(observation cnpgObservation, claim, pv, volume, engine o
5454
verifyPostgresStandby(observation.States[primary], observation.States[name]) != nil {
5555
return cnpgRecoveredStorage{}, refused
5656
}
57-
owned, err := healthyCNPGPods(cluster, observation.Pods)
57+
owned, err := healthyCNPGPodsWithRetention(cluster, observation.Pods, observation.retainedStandby)
5858
if err != nil {
59-
return cnpgRecoveredStorage{}, refused
59+
return cnpgRecoveredStorage{}, err
6060
}
6161
pods, err := indexed(owned)
6262
if err != nil {

‎scripts/migrate-longhorn-v2/cnpg_standby_v2_test.go‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "testing"
55
func TestUmamiV2StandbyBindsLivePhysicalReplayAndCopies(t *testing.T) {
66
const standby = "umami-db-4"
77
storage := newRecoveredStorageFixture(t)
8-
for _, fault := range []string{"", "old engine", "incomplete copies", "behind", "primary", "wrong mount"} {
8+
for _, fault := range []string{"", "retained peer", "missing healthy peer", "missing retention witness", "retained peer behind", "old engine", "incomplete copies", "behind", "primary", "wrong mount"} {
99
t.Run(fault, func(t *testing.T) {
1010
f := storage.copyBindingObjects(t)
1111
obs := umamiV2TransitionObservation(t)
@@ -24,11 +24,22 @@ func TestUmamiV2StandbyBindsLivePhysicalReplayAndCopies(t *testing.T) {
2424
volumeRef["pvcName"], volumeRef["namespace"] = standby, "umami"
2525

2626
switch fault {
27+
case "retained peer", "missing healthy peer", "missing retention witness", "retained peer behind":
28+
obs.retainedStandby = "umami-db-2"
29+
status := valueObject(obs.Cluster, "status")
30+
status["instances"] = float64(3)
31+
status["healthyPVC"] = []any{"umami-db-1", "umami-db-3", standby}
32+
}
33+
switch fault {
34+
case "missing healthy peer":
35+
valueObject(obs.Cluster, "status")["healthyPVC"] = []any{"umami-db-1", obs.retainedStandby, standby}
36+
case "missing retention witness":
37+
obs.retainedStandby = ""
2738
case "old engine":
2839
valueObject(f.engine, "spec")["dataEngine"] = "v1"
2940
case "incomplete copies":
3041
f.replicas = f.replicas[:2]
31-
case "behind":
42+
case "behind", "retained peer behind":
3243
state := obs.States[standby]
3344
state.ReplayLSN = "2/FF"
3445
obs.States[standby] = state
@@ -38,7 +49,7 @@ func TestUmamiV2StandbyBindsLivePhysicalReplayAndCopies(t *testing.T) {
3849
value(pod, "spec", "volumes").([]any)[0].(object)["persistentVolumeClaim"] = object{"claimName": "another-claim"}
3950
}
4051
got, err := bindUmamiV2Standby(obs, f.claim, f.pv, f.volume, f.engine, f.replicas, f.p.record.Storage.Disks)
41-
if fault == "" {
52+
if fault == "" || fault == "retained peer" {
4253
if err != nil || got.Pod != benchmarkIdentity(pod) || got.Claim != benchmarkIdentity(f.claim) || len(got.Replicas) != 3 {
4354
t.Fatalf("V2 standby did not qualify: %+v, %v", got, err)
4455
}

0 commit comments

Comments
 (0)