-
Notifications
You must be signed in to change notification settings - Fork 1
fix(satellite): fire late-add metadata/self-heal only for unattached desired volumes (BUG-048 deadlock) #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /* | ||
| Copyright 2026 Cozystack contributors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package drbd_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/cozystack/blockstor/pkg/drbd" | ||
| "github.com/cozystack/blockstor/pkg/storage" | ||
| ) | ||
|
|
||
| // AttachedVolumes is the kernel-truth backing for the BUG-048 resize-deadlock | ||
| // gate: it returns the LOCAL volumes that are present-and-attached (have a | ||
| // valid DRBD-9 metadata block — disk-state UpToDate / Inconsistent / | ||
| // Consistent / Outdated). A volume absent from the device list, or Diskless / | ||
| // mid-transition, is excluded so the reconciler still runs the metadata pass | ||
| // for a genuine late-add but never for a converged/resizing RD. | ||
|
|
||
| func attachedVolumesAdm(t *testing.T, json string) *drbd.Adm { | ||
| t.Helper() | ||
|
|
||
| fx := storage.NewFakeExec() | ||
| fx.Responses["drbdsetup status pvc-av --json"] = storage.FakeResponse{Stdout: []byte(json)} | ||
|
|
||
| return drbd.NewAdm(fx) | ||
| } | ||
|
|
||
| func assertAttachedSet(t *testing.T, got map[int32]struct{}, want ...int32) { | ||
| t.Helper() | ||
|
|
||
| if len(got) != len(want) { | ||
| t.Fatalf("attached set size = %d, want %d (got %v, want %v)", len(got), len(want), got, want) | ||
| } | ||
|
|
||
| for _, v := range want { | ||
| if _, ok := got[v]; !ok { | ||
| t.Errorf("expected volume %d in attached set %v", v, got) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Every metadata-bearing disk-state counts as attached. Diskless and | ||
| // transient states do NOT — those are volumes that still need the metadata | ||
| // pass (a genuine late-add or a re-attach). | ||
| func TestAttachedVolumes_OnlyMetadataBearingStatesCount(t *testing.T) { | ||
| adm := attachedVolumesAdm(t, `[{ | ||
| "name":"pvc-av","node-id":0,"role":"Secondary", | ||
| "devices":[ | ||
| {"volume":0,"disk-state":"UpToDate"}, | ||
| {"volume":1,"disk-state":"Inconsistent"}, | ||
| {"volume":2,"disk-state":"Consistent"}, | ||
| {"volume":3,"disk-state":"Outdated"}, | ||
| {"volume":4,"disk-state":"Diskless"}, | ||
| {"volume":5,"disk-state":"Negotiating"}, | ||
| {"volume":6,"disk-state":"DUnknown"} | ||
| ] | ||
| }]`) | ||
|
|
||
| // 0..3 are attached (metadata-bearing); 4 (Diskless), 5 (Negotiating), | ||
| // 6 (DUnknown) are not. | ||
| assertAttachedSet(t, adm.AttachedVolumes(t.Context(), "pvc-av"), 0, 1, 2, 3) | ||
| } | ||
|
|
||
| // A volume entirely absent from the kernel device list (the genuine late-add | ||
| // window — `vd c` added it to the desired set but the kernel has not brought | ||
| // it up yet) is simply not in the set, so the reconciler sees it as | ||
| // unattached and runs the metadata pass for it. | ||
| func TestAttachedVolumes_AbsentVolumeNotInSet(t *testing.T) { | ||
| adm := attachedVolumesAdm(t, `[{ | ||
| "name":"pvc-av","node-id":0,"role":"Secondary", | ||
| "devices":[ | ||
| {"volume":0,"disk-state":"UpToDate"} | ||
| ] | ||
| }]`) | ||
|
|
||
| got := adm.AttachedVolumes(t.Context(), "pvc-av") | ||
| assertAttachedSet(t, got, 0) | ||
|
|
||
| if _, ok := got[1]; ok { | ||
| t.Errorf("volume 1 is absent from the device list and must NOT be reported attached; got %v", got) | ||
| } | ||
| } | ||
|
|
||
| // Conservative toward FIRING (fail-toward-correctness): on a probe failure, | ||
| // empty output, or an unloaded slot the set is empty, so the reconciler treats | ||
| // every desired volume as possibly-unattached and runs the idempotent metadata | ||
| // pass — the pre-#164 behaviour. The deadlock-relevant skip only happens once | ||
| // the kernel positively reports volumes attached. | ||
| func TestAttachedVolumes_ConservativeEmptyOnNoKernelSlot(t *testing.T) { | ||
| fx := storage.NewFakeExec() | ||
| // No registered response → FakeExec returns empty stdout, nil error | ||
| // (the "kernel slot present but status empty" / blank-output shape). | ||
| adm := drbd.NewAdm(fx) | ||
|
|
||
| if got := adm.AttachedVolumes(t.Context(), "pvc-missing"); len(got) != 0 { | ||
| t.Errorf("expected empty attached set on no kernel data; got %v", got) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the
Showmethod in the same file (line 221), consider using"-j"instead of"--json"and placing the option before the positionalresourceargument. Some older or stricter CLI parsers can be sensitive to option ordering (placing options after positional arguments).