Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f0b77c5
fix(rest,cli): guard a replica delete only on a volume that stays
kvaps Nov 22, 2026
ca0c857
fix(store,cli): delete the incomplete replicas of a volume first
kvaps Nov 22, 2026
5b3fd43
fix(rest,cli,controller): flag a definition DELETE before its replicas
kvaps Nov 22, 2026
399d027
fix(validate,rest,cli): keep the U130 guard when a Primary is up
kvaps Nov 22, 2026
1066bce
test(validate): a source that is being deleted is no source
kvaps Nov 22, 2026
2b935a8
test(rest,cli): refuse a replica delete when the RD cannot be read
kvaps Nov 22, 2026
6a142ed
refactor(store): stop ordering the rd d cascade
kvaps Nov 22, 2026
f8e292b
Merge branch 'main' into fix/delete-mid-initial-sync
kvaps Nov 23, 2026
5e52430
fix(store): refuse a definition over the replicas of a deleted one
kvaps Nov 24, 2026
984337b
fix(rest): answer a refused definition create with FAIL_EXISTS_RSC_DFN
kvaps Nov 24, 2026
7f77e88
fix(restore): say a target is still being deleted instead of missing
kvaps Nov 24, 2026
d2ee887
test(store): refuse a definition over a finalizer-held replica
kvaps Nov 24, 2026
a640e3a
fix(controller): elect and seed from the replicas that stay
kvaps Nov 24, 2026
0557810
fix(rest): answer rd d once the online replicas are torn down
kvaps Nov 24, 2026
ab8b378
refactor: keep the delete and restore handlers within funlen
kvaps Nov 24, 2026
aca2cac
Merge remote-tracking branch 'origin/main' into fix/delete-mid-initia…
kvaps Nov 24, 2026
36ad7cb
docs(parity): list the draining definition as an accepted delta
kvaps Nov 24, 2026
d575f87
docs(validate): own the unattached hand move the lifted guard misses
kvaps Nov 24, 2026
11d9633
Merge branch 'main' into fix/delete-mid-initial-sync
kvaps Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/cli-parity-known-deltas.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Row IDs match the command-catalogue indexes used by `cli-parity-refresh.sh` (see
| 86 | `node interface modify <node> <nic> --active` | BEHAVIOR | permanent | blockstor has no satellite-to-controller connection to re-target: the satellite talks only to the Kubernetes API through the in-cluster Service. `NodeNetInterface` carries no `Active` field, and the REST `is_active` flag is synthesised on read as "first interface", so `--active` changes nothing. To make another interface active, reorder `spec.netInterfaces` so it comes first; a changed address reaches the node's DRBD configuration after its satellite pod restarts. Pinned by `TestSatelliteFlagsLackControllerBindAddress` and `TestNodeCRDHasNoActiveField` in `pkg/satellite/stream/redial_spec_test.go`. |
| 105 | `n describe` / `r lv` (`/v1/view/resources` volume of a replica with no resolvable pool) | WIRE_SHAPE | permanent | A diskful replica whose satellite has not reported a volume yet is listed with one placeholder volume per volume definition, as LINSTOR lists the replica's own volumes (`Json.apiToResourceWithVolumes`). The placeholder names the pool LINSTOR would resolve (`CtrlStorPoolResolveHelper.resolveStorPool`: the StorPoolName chain, then the diskful neighbours' pools, then `DfltStorPool`, first one present on the node). When none resolves, it is listed with an empty `storage_pool_name`. LINSTOR cannot produce that row, because it creates every Volume with a resolved pool; python-linstor's `construct_rsc` then calls `add_child` on the `None` that `find_child("")` returns, so `n describe` fails for that replica until its satellite reports the volume. Deliberate: the alternative is an empty `volumes` list, on which linstor-scheduler-extender indexes `volumes[0]` without a length check and panics on every filter call, keeping the pod Pending. Pinned by `pkg/rest/view_client_contract_test.go::TestViewUnresolvablePoolStillListsTheVolume`. |
| 106 | `rd sp <rd> AutoSnapshot/RunEvery <n>` (schedule after a controller restart or failover) | BEHAVIOR | permanent | Upstream keeps the auto-snapshot schedule in memory: after a controller start `AutoSnapshotTask` books the first run at start + `RunEvery` + one poll (`TASK_TIMEOUT`, 10 s; `AutoSnapshotTask.java` in v1.33.1), so every restart shifts the schedule. blockstor keeps the last slot in the definition's annotation and books the next one at slot + `RunEvery`, so a restart or leader failover shorter than `RunEvery` does not shift it, and the first snapshot after a short restart can come sooner than upstream's. A slot missed by a whole interval or more (longer downtime) is booked at the time it is taken, with no catch-up, which matches the upstream outcome of one snapshot, not a burst. Between restarts the cadence matches upstream (10 s poll, next run booked at the slot as `AutoSnapshotConfig.next()`). Pinned by `internal/controller/autosnapshot_cadence_test.go::TestAutoSnapshot{RunEveryOneTakesOnePerMinute,AfterDowntimeTakesOneNotABurst}`. |
| 118 | `rd d <rd>` then `rd c <rd>` while a replica still drains | BEHAVIOR | permanent | LINSTOR keeps a deleted definition, flagged DELETE, until every satellite confirms its replica gone (`CtrlRscDfnDeleteApiCallHandler`): `rd l` keeps listing it, its `rd d` reply waits on the online satellites and warns about one that is not connected, and an `rd c` of the same name is refused with FAIL_EXISTS_RSC_DFN. blockstor removes the definition object at once and lets the replicas drain on their own. `rd d` waits up to 20s for the replicas on online nodes and then answers; a replica on an offline node, or one still draining past that budget, is not waited for. While such a replica drains, `rd l` no longer lists the definition, but `rd c` and a snapshot restore into the same name are refused with FAIL_EXISTS_RSC_DFN (HTTP 409) naming the nodes still draining, so linstor-csi retries the create as it does against LINSTOR. The outcome of a create matches; the divergence is the listing and the `rd d` reply. Pinned by `TestRDDeleteWaitsForReplicasOnOnlineNodes`, `TestRDDeleteDoesNotWaitForAnOfflineNode`, `TestRDCreateWaitsForTheDeletedDefinitionsReplicas`, `TestRestoreIntoANameStillBeingDeletedAnswers409` (pkg/rest) and `TestRDCreateRefusedOverAFinalizerHeldReplica` (pkg/store/k8s). |

## Open (block merge until addressed)

Expand Down
6 changes: 6 additions & 0 deletions internal/cli/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ func restoreIntoExistingTarget(
) error {
rdName := args.toResource

// No definition to restore into: its predecessor is still draining
// replicas, and the refusal names their nodes.
if store.IsReplicasDraining(createErr) {
return fmt.Errorf("restore %s onto %s: %w", snap.Name, rdName, createErr)
}

existing, err := run.Store.ResourceDefinitions().Get(ctx, rdName)
if err != nil {
return fmt.Errorf("get resource definition %s: %w", rdName, err)
Expand Down
29 changes: 29 additions & 0 deletions internal/cli/snapshot_restore_orphans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package cli_test
import (
"context"
"errors"
"strings"
"testing"

apiv1 "github.com/cozystack/blockstor/pkg/api/v1"
Expand Down Expand Up @@ -54,3 +55,31 @@ func TestSnapshotRestoreRefusesATargetWithOrphanReplicas(t *testing.T) {
t.Fatalf("the refusal left a definition behind: err=%v", err)
}
}

// A restore into a name whose earlier definition is still draining a replica
// on a node that is down is refused as the plain create is: the definition is
// still being deleted, and the refusal names the node. Read as an existing
// target instead, it answered that the definition was not found.
func TestSnapshotRestoreIntoANameStillBeingDeletedSaysSo(t *testing.T) {
t.Parallel()

app, _, errBuf := newApp(t, func(ctx context.Context, backend store.Store) {
seedSnapshotSource(ctx, backend)
_ = backend.Resources().Create(ctx, &apiv1.Resource{
Name: "pvc-drain", NodeName: "node-down", Flags: []string{apiv1.ResourceFlagDelete},
})
})

if got := app.Run(t.Context(), restoreResourceArgv("pvc-drain")); got == 0 {
t.Fatal("restore over a draining replica succeeded")
}

msg := errBuf.String()
if !strings.Contains(msg, "still being deleted") || !strings.Contains(msg, "node-down") {
t.Fatalf("refusal = %q, want it to say the definition is still being deleted on node-down", msg)
}

if strings.Contains(msg, "not found") {
t.Fatalf("refusal = %q, answered as a missing definition", msg)
}
}
5 changes: 5 additions & 0 deletions internal/cli/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ func resourceDefinitionDelete(ctx context.Context, run *runContext) error {
// Then the replicas. Dropping the definition alone leaves them with no
// parent to stamp a deletion on, so the satellite finalizer never runs
// and the DRBD minor, port and peer entries stay live on every node.
err = store.MarkDefinitionDeleting(ctx, run.Store, name)
if err != nil {
return fmt.Errorf("delete resource definition %s: %w", name, err)
}

err = store.CascadeDeleteResources(ctx, run.Store, name)
if err != nil {
return fmt.Errorf("delete replicas of %s: %w", name, err)
Expand Down
63 changes: 62 additions & 1 deletion internal/cli/write_more.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,12 @@ func resourceDelete(ctx context.Context, run *runContext) error {
return err
}

for _, node := range run.Flags.Positionals[:last] {
nodes, err := deletionOrder(ctx, run, rdName, run.Flags.Positionals[:last])
if err != nil {
return err
}

for _, node := range nodes {
err := checkDeletable(ctx, run, rdName, node)
if err != nil {
return err
Expand Down Expand Up @@ -687,6 +692,49 @@ func checkZFSDeleteStrategy(ctx context.Context, run *runContext, rdName string)
return nil
}

// deletionOrder puts the named replicas in the order they are safe to
// delete one at a time (validate.SortForDeletion): `r d a b c <rd>` naming a
// syncing replica after its source would otherwise drop the source first and
// be refused on the replica it was about to delete anyway.
func deletionOrder(ctx context.Context, run *runContext, rdName string, named []string) ([]string, error) {
if len(named) < 2 {
return named, nil
}

replicas, err := run.Store.Resources().ListByDefinition(ctx, rdName)
if err != nil {
if isNotFound(err) {
return named, nil
}

return nil, fmt.Errorf("list replicas of %s: %w", rdName, err)
}

validate.SortForDeletion(replicas)

ordered := make([]string, 0, len(named))
taken := make([]bool, len(named))

for i := range replicas {
for j, node := range named {
if !taken[j] && naming.Same(node, replicas[i].NodeName) {
ordered = append(ordered, node)
taken[j] = true
}
}
}

// Names with no replica behind them keep their place at the end; the
// delete is idempotent for them.
for j, node := range named {
if !taken[j] {
ordered = append(ordered, node)
}
}

return ordered, nil
}

// checkDeletable refuses a delete that would strand a peer still resyncing
// from this replica — upstream U130.
//
Expand Down Expand Up @@ -714,11 +762,24 @@ func checkDeletable(ctx context.Context, run *runContext, rdName, node string) e
return fmt.Errorf("get resource %s on %s: %w", rdName, node, err)
}

rd, err := run.Store.ResourceDefinitions().Get(ctx, rdName)
if err != nil && !isNotFound(err) {
return fmt.Errorf("get resource definition %s: %w", rdName, err)
}

rdFound := err == nil

siblings, err := run.Store.Resources().ListByDefinition(ctx, rdName)
if err != nil {
return fmt.Errorf("list replicas of %s: %w", rdName, err)
}

// Only a replica dropped from a volume that stays is guarded; see
// validate.DefinitionBeingDeleted.
if rdFound && validate.DefinitionBeingDeleted(&rd, siblings) {
return nil
}

if validate.MidSyncDeleteRefusal(&target, siblings) {
return fmt.Errorf("refusing to delete %s on %s: %w (pass --force to override)",
rdName, node, validate.ErrLastSyncSourceDelete)
Expand Down
188 changes: 188 additions & 0 deletions internal/cli/write_more_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

apiv1 "github.com/cozystack/blockstor/pkg/api/v1"
"github.com/cozystack/blockstor/pkg/store"
"github.com/cozystack/blockstor/pkg/store/storetest"
)

func seedDefinition(ctx context.Context, backend store.Store) {
Expand Down Expand Up @@ -358,3 +359,190 @@ func TestResourceGroupSpawnEnforcesBounds(t *testing.T) {
t.Error("spawn accepted a sub-floor volume size")
}
}

// `r d` naming every replica of a volume still in its initial sync, the
// source first: the Inconsistent replica is deleted before the copies it
// depends on, so the last complete copy is never refused over a peer the
// same command was about to delete.
func TestResourceDeleteOfEveryReplicaMidInitialSync(t *testing.T) {
t.Parallel()

app, _, errBuf := newApp(t, func(ctx context.Context, backend store.Store) {
seedDefinition(ctx, backend)

for node, disk := range map[string]string{
"node-a": "UpToDate",
"node-b": "Inconsistent",
} {
_ = backend.Resources().Create(ctx, &apiv1.Resource{
Name: "pvc-x", NodeName: node,
Volumes: []apiv1.Volume{{State: apiv1.VolumeState{DiskState: disk}}},
})
}
})

if got := app.Run(t.Context(), []string{"r", "d", "node-a", "node-b", "pvc-x"}); got != 0 {
t.Fatalf("delete exit = %d (stderr: %s)", got, errBuf.String())
}

resources, err := appStore(t, app).Resources().List(t.Context())
if err != nil {
t.Fatalf("list: %v", err)
}

if len(resources) != 0 {
t.Errorf("replicas survived the delete: %+v", resources)
}
}

// The last complete copy of a volume that stays is still refused.
func TestResourceDeleteOfLastCompleteCopyStaysGuarded(t *testing.T) {
t.Parallel()

app, _, _ := newApp(t, func(ctx context.Context, backend store.Store) {
seedDefinition(ctx, backend)

for node, disk := range map[string]string{
"node-a": "UpToDate",
"node-b": "Inconsistent",
} {
_ = backend.Resources().Create(ctx, &apiv1.Resource{
Name: "pvc-x", NodeName: node,
Volumes: []apiv1.Volume{{State: apiv1.VolumeState{DiskState: disk}}},
})
}
})

if got := app.Run(t.Context(), []string{"r", "d", "node-a", "pvc-x"}); got == 0 {
t.Fatal("the last complete copy was deleted while a peer was still syncing")
}
}

// A replica delete on a definition linstor-csi's DeleteVolume is tearing
// down (balancing switched off first) is not guarded: every replica is
// going, so the Inconsistent one is not stranded.
func TestResourceDeleteDuringVolumeTeardownIsNotGuarded(t *testing.T) {
t.Parallel()

app, _, errBuf := newApp(t, func(ctx context.Context, backend store.Store) {
_ = backend.ResourceDefinitions().Create(ctx, &apiv1.ResourceDefinition{
Name: "pvc-x",
Props: map[string]string{apiv1.PropBalanceResourcesEnabled: "False"},
})

for node, disk := range map[string]string{
"node-a": "UpToDate",
"node-b": "Inconsistent",
} {
_ = backend.Resources().Create(ctx, &apiv1.Resource{
Name: "pvc-x", NodeName: node,
Volumes: []apiv1.Volume{{State: apiv1.VolumeState{DiskState: disk}}},
})
}
})

if got := app.Run(t.Context(), []string{"r", "d", "node-a", "pvc-x"}); got != 0 {
t.Fatalf("delete exit = %d (stderr: %s)", got, errBuf.String())
}
}

// `rd d` flags the definition DELETE before the first replica goes, the
// way the REST door does.
func TestDefinitionDeleteFlagsDefinitionBeforeItsReplicas(t *testing.T) {
t.Parallel()

app, _, errBuf := newApp(t, func(ctx context.Context, backend store.Store) {
seedDefinition(ctx, backend)

for node, disk := range map[string]string{
"node-a": "UpToDate",
"node-b": "Inconsistent",
} {
_ = backend.Resources().Create(ctx, &apiv1.Resource{
Name: "pvc-x", NodeName: node,
Volumes: []apiv1.Volume{{State: apiv1.VolumeState{DiskState: disk}}},
})
}
})

rec := storetest.NewDeleteRecorder(appStore(t, app))
app.StoreFor = func(context.Context) (store.Store, error) { return rec, nil }

if got := app.Run(t.Context(), []string{"rd", "d", "pvc-x"}); got != 0 {
t.Fatalf("delete exit = %d (stderr: %s)", got, errBuf.String())
}

deletes := rec.Deletes()
if len(deletes) != 2 {
t.Errorf("deletes = %+v, want both replicas", deletes)
}

for _, d := range deletes {
if !d.DefinitionFlagged {
t.Errorf("replica on %s deleted before the definition was flagged DELETE", d.Node)
}
}
}

// U130 on a definition placed by hand: balancing off, a diskless Primary,
// a diskful replica still syncing. Deleting the complete copy stays
// refused; only a teardown with nothing InUse lifts the guard.
func TestResourceDeleteWithBalancingOffAndAPrimaryStaysGuarded(t *testing.T) {
t.Parallel()

app, _, _ := newApp(t, func(ctx context.Context, backend store.Store) {
_ = backend.ResourceDefinitions().Create(ctx, &apiv1.ResourceDefinition{
Name: "pvc-x",
Props: map[string]string{apiv1.PropBalanceResourcesEnabled: "False"},
})

for node, disk := range map[string]string{
"node-a": "UpToDate",
"node-b": "Inconsistent",
} {
_ = backend.Resources().Create(ctx, &apiv1.Resource{
Name: "pvc-x", NodeName: node,
Volumes: []apiv1.Volume{{State: apiv1.VolumeState{DiskState: disk}}},
})
}

inUse := true
_ = backend.Resources().Create(ctx, &apiv1.Resource{
Name: "pvc-x", NodeName: "node-p",
Flags: []string{apiv1.ResourceFlagDiskless},
State: apiv1.ResourceState{InUse: &inUse},
})
})

if got := app.Run(t.Context(), []string{"r", "d", "node-a", "pvc-x"}); got == 0 {
t.Fatal("the Primary's last complete copy was deleted while a peer was still syncing")
}
}

// A definition read that fails refuses the delete rather than skipping the
// guard.
func TestResourceDeleteRefusedWhenTheDefinitionCannotBeRead(t *testing.T) {
t.Parallel()

app, _, _ := newApp(t, func(ctx context.Context, backend store.Store) {
seedDefinition(ctx, backend)

_ = backend.Resources().Create(ctx, &apiv1.Resource{
Name: "pvc-x", NodeName: "node-a",
Volumes: []apiv1.Volume{{State: apiv1.VolumeState{DiskState: "UpToDate"}}},
})
})

backend := appStore(t, app)
app.StoreFor = func(context.Context) (store.Store, error) {
return storetest.FailingDefinitionGet{Store: backend}, nil
}

if got := app.Run(t.Context(), []string{"r", "d", "node-a", "pvc-x"}); got == 0 {
t.Fatal("delete went through although the definition could not be read")
}

if _, err := backend.Resources().Get(t.Context(), "pvc-x", "node-a"); err != nil {
t.Errorf("node-a was deleted: %v", err)
}
}
Loading
Loading