Skip to content

fix(rest): let linstor-csi delete the definition of a volume it deletes - #288

Merged
Andrei Kvapil (kvaps) merged 3 commits into
mainfrom
fix/csi-delete-removes-rd
Nov 23, 2026
Merged

Andrei Kvapil (kvaps) merged 3 commits into
mainfrom
fix/csi-delete-removes-rd

Conversation

@kvaps

Copy link
Copy Markdown
Member

What

A replica delete now removes the auto-managed TIE_BREAKER witness before it answers whenever fewer than two voting diskful replicas remain, which is where LINSTOR v1.33.1 drops it inside the same call. The RD reconciler no longer counts replicas that are being deleted, so it cannot grow a new witness for a volume whose replicas are all on their way out.

Why

linstor-csi (v1.11.2, Delete and deleteResourceDefinitionAndGroupIfUnused) deletes every replica it listed, deletes the volume definitions, then lists the replicas again and deletes the resource definition only if every listed replica carries DELETE. It never retries after DeleteVolume returned success, so a single live replica in that last listing leaves an empty definition behind for good.

LINSTOR keeps that listing clean because its auto-tiebreaker helper runs inside the resource-delete transaction (CtrlRscDeleteApiCallHandler calls CtrlRscAutoHelper.manage). shouldTieBreakerExist counts only replicas not flagged DELETE, DRBD_DELETE or INACTIVE, so as soon as fewer than two diskful replicas remain the tiebreaker is marked deleted before the call returns.

blockstor runs the witness logic in the asynchronous RD reconciler. On a test cluster, deleting an RWX block volume (CDI prime and tmp PVCs) went like this: csi listed 2 diskful replicas plus the attach-time diskless, deleted the diskless first, the reconciler saw "2 diskful, no diskless" and created a fresh witness, csi deleted both diskful replicas, then listed again and found the new witness without DELETE. The reconciler removed the witness about seven seconds later, but csi had already returned. Two definitions were left with 0 resources and 0 volume definitions. RWO volumes, whose witness already existed and was deleted first (which suppresses re-creation), were cleaned up fully.

The same leak had a second path that a delete-time reap alone does not close. While a satellite holds a deleted diskful replica through a slow DRBD or ZFS teardown, or while it is down, the replica stays listed with DELETE synthesised from its DeletionTimestamp. The reconciler read the replicas without looking at the DeletionTimestamp and did not filter DELETE, so two terminating diskful replicas with the witness already gone looked like "2 diskful, no witness" and got a new, live TIE_BREAKER, exactly what csi's final listing must not see.

How

  • The RD reconciler marks a replica with a DeletionTimestamp as DELETE in its direct list, the way the store already does, and drops DELETE replicas from the voting set before the INACTIVE probe and the diskful/diskless split. This matches upstream's isDrbdResource filter and also applies to the quorum decision, which upstream counts the same way.
  • After the replica delete, the REST handler reaps the TIE_BREAKER witnesses when fewer than two voting diskful replicas remain. With exactly one left it keeps the reconciler's two carve-outs: --keep-tiebreaker and an INACTIVE replica waiting for a backfill onto the witness (Bug 393). With none left neither applies, as in the reconciler. Two or more diskful replicas leave the decision to the reconciler. Plain DISKLESS replicas are left alone.
  • The reap reads the replicas from the API server rather than the informer cache, so a diskful another apiserver replica has just created cannot make a healthy two-diskful definition look like it lost its tie. It deletes through DeleteIfTieBreaker, as the reconciler does, so a witness being promoted to a backfill replica survives, and logs a failed list or delete at V(1).

No tiebreaker-suppression stamp is added on this path. With the reconciler no longer counting terminating replicas it has nothing to suppress, and a five-minute stamp would keep a witness off a definition that gets two new diskful replicas within that window, which LINSTOR would give one.

LINSTOR's takeover (turning a deleted diskless into the witness) is not reproduced here. Without it the reconciler can still create a witness while csi is deleting, but that witness is gone before the last diskful delete returns.

Interactions with open PRs

#271 changes waitForResourceDeletionVisible to return whether the delete converged and edits the lines right around the new call in handleResourceDelete, so one of the two will need a small rebase. The new helper ignores the return value, which still compiles after #271. #273 adds a step to the RD reconciler's Reconcile and its watch predicate, in hunks this change does not touch. #277 and #283 also touch pkg/rest/autoplace.go, but not this handler.

Testing

  • pkg/rest/resource_delete_orphan_witness_test.go replays the delete shapes against the REST server and reads /v1/view/resources with the predicate csi uses: csi deleting both diskful replicas (the witness is gone after the first delete, as on LINSTOR), --keep-tiebreaker, an INACTIVE replica holding the witness, two diskful left, and a plain DISKLESS replica.
  • The same file runs csi's sequence on the CRD store with the diskful replicas held by a finalizer for longer than the handler waits, and runs the RD reconciler after each delete. It fails without the reconciler change (a fresh witness is listed without DELETE).
  • A test with a cache that hides a just-created diskful checks the witness of a two-diskful definition survives; it fails when the reap reads the cache.
  • internal/controller/ensure_tiebreaker_deleting_replicas_test.go checks that the reconciler grows no witness for two terminating diskful replicas, through both the direct reader and the store path. Both fail without the change.
  • go test ./... passes with envtest assets 1.35.0, including the provenance guard.
  • make lint-config && make lint (golangci-lint v2.11.4): 0 issues.
  • Integration groups C, F, G, J, K and the smoke test (go test -tags=integration): pass. In the first combined run, two group F auto-place create tests timed out while the full unit suite ran on the same machine at the same time; both pass alone and group F passes in full on a rerun. Neither test deletes a replica.

Not tested

  • The full linstor-csi DeleteVolume against a live cluster with this build. The cluster evidence comes from apiserver, controller and csi logs of the current release.
  • The interleaving where the reconciler creates a witness between csi's two listings, end to end under envtest. It depends on reconciler timing; the unit tests drive the reconciler explicitly between deletes instead.

linstor-csi deletes every replica it listed, then lists again and
deletes the resource definition only if each remaining replica
carries DELETE; it never retries once DeleteVolume returned success.
LINSTOR runs its auto-tiebreaker helper inside the resource-delete
transaction, so a tiebreaker left without diskful peers is already
flagged DELETE when the last diskful delete returns.

blockstor manages the witness from the asynchronous RD reconciler.
Dropping the attach-time diskless of a 2-diskful RWX volume makes it
stamp a fresh witness while csi is still deleting, and it reaps that
witness only after csi's final listing. csi then sees a live
TIE_BREAKER and leaves an empty resource definition behind.

When a replica delete leaves no diskful replica, delete the remaining
auto-managed witnesses in the same request. That shape has no witness
in any branch of the reconciler or of LINSTOR, so the two cannot
disagree; every other witness decision stays with the reconciler.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
linstor-csi deletes every replica of a volume, lists what is left and
deletes the resource definition only when each remaining replica is
flagged DELETE; it never retries. While a satellite holds a deleted
diskful replica through a slow DRBD or ZFS teardown, the RD
reconciler still counted it: its direct list ignored the
DeletionTimestamp, and neither the active filter nor the diskful
split looked at DELETE. Two terminating diskful replicas with the
witness already gone read as "2 diskful, no witness", the reconciler
grew a fresh TIE_BREAKER, csi's final listing saw it live and the
definition was left behind.

Upstream's auto-tiebreaker and auto-quorum helpers skip DELETE and
INACTIVE replicas before counting anything. Mark the direct list the
same way the store marks it and drop DELETE replicas from the voting
set, so the witness and quorum decisions run over the replicas that
stay.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The reap ran only once no diskful replica was left, so after the
first of two diskful deletes the witness stayed live until the RD
reconciler caught up. LINSTOR v1.33.1 decides the witness inside the
`r d` transaction and flags it DELETE as soon as fewer than two
voting diskful replicas remain; the reap now covers that shape too,
keeping the reconciler's carve-outs at one diskful: --keep-tiebreaker
and an INACTIVE replica waiting for a backfill onto the witness.

The decision read the informer cache, which can miss a diskful
another apiserver replica has just created, and would then drop the
third quorum voter of a healthy two-diskful definition. It now reads
the replicas from the API server. The delete goes through
DeleteIfTieBreaker so a witness being promoted to a backfill replica
survives, and a failed list or delete is logged at V(1) so a leaked
definition can be traced back.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68053a20-f9f9-40b5-b472-99da2d0e1f39
Commits

Reviewing files that changed from the base of the PR and between 216e577 and 11e6c78.

Files selected for processing: 5

  • internal/controller/ensure_tiebreaker_deleting_replicas_test.go
  • internal/controller/resourcedefinition_controller.go
  • pkg/rest/autoplace.go
  • pkg/rest/resource_delete_orphan_witness.go
  • pkg/rest/resource_delete_orphan_witness_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this against linstor-server v1.35.3. CtrlRscAutoTieBreakerHelper.isDrbdResource (L553-561) skips DELETE, DRBD_DELETE and INACTIVE replicas, and shouldTieBreakerExist (L447-487) wants at least two diskful replicas, an even count and no diskless. Reaping only below two diskful is therefore a subset of what upstream drops inside the delete call, and the reconciler still owns every other case. The reap reads past the cache through store.LiveReplicas and deletes through DeleteIfTieBreaker, so neither a fresh diskful from another apiserver nor a witness being promoted can be lost. CI is green. LGTM.

@kvaps
Andrei Kvapil (kvaps) merged commit 837614f into main Nov 23, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants