Skip to content

fix(linstor): plunger demotes idle-Primary DRBD resources - #2539

Merged
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
fix/linstor-plunger-idle-primary
Apr 30, 2026
Merged

Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
fix/linstor-plunger-idle-primary

Conversation

@kvaps

@kvaps Andrei Kvapil (kvaps) commented Apr 29, 2026 •

Copy link
Copy Markdown
Member

What this PR does

Adds a per-satellite plunger handler that detects DRBD resources
stuck in Primary on the local node with no consumer and demotes
them to Secondary.

Background

DRBD auto-promotes a resource to Primary during the provisioning
path (mkfs.ext4 against a freshly created replica, for example),
but auto-demote sometimes fails to fire on close. The resource then
stays Primary on a node that has no consumer pod, and CSI on the
legitimate target node fails NodePublishVolume with:

failed to set source device readwrite: exit status 1

The only recovery is an explicit drbdadm secondary on the stuck
node — there is no upstream automation for it.

This was hit deterministically in Cozystack e2e CI on freshly
provisioned PVCs without any pod migration or node failure. Upstream
tracker: piraeusdatastore/piraeus-operator#942 (and the related
piraeusdatastore/linstor-csi#172).

Implementation

In plunger-satellite.sh (already running as a privileged sidecar
on every linstor-satellite pod) add drbd_fix_idle_primary:

.[]?
| select(.role == "Primary")
| select(all(.devices[]?; .open == false))
| .name

For every match, run drbdadm secondary <res>.

Why this is safe

  • open == false on every device of the resource means no reader
    or writer holds the block device — the demote cannot interrupt I/O.
  • Both detection and action are local to the satellite, no peer
    coordination needed.
  • If a real consumer is about to arrive, DRBD auto-promote will redo
    the promotion when CSI opens the device — so even a misfire is a
    no-op.
  • The jq filter was validated against a live multi-node cluster
    (3 nodes, 22 legitimate Primaries, 0 false positives — every
    legitimate Primary has at least one open: true volume).

Release note

fix(linstor): plunger now demotes DRBD resources stuck in Primary
without a consumer, fixing transient `failed to set source device
readwrite` mount errors during PVC provisioning.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced DRBD resource management with automatic remediation for idle Primary resources. The system now detects resources lacking active device connections and safely demotes them to Secondary state during routine maintenance cycles. Robust error handling preserves existing recovery procedures while improving overall system stability and preventing potential resource conflicts.

DRBD auto-promotes a resource to Primary during the provisioning path
(e.g. mkfs.ext4 against a freshly created replica), but auto-demote
sometimes fails to fire on close. The resource then stays Primary on
a node that has no consumer, and CSI on the legitimate target node
fails NodePublishVolume with "failed to set source device readwrite".
The only recovery is an explicit drbdadm secondary on the stuck node.

Add a per-satellite plunger handler that detects local Primaries
where every device has open == false and demotes them. Both the
detection and the action are local to the satellite, so no peer
coordination is needed. open:no makes drbdadm secondary safe; if a
real consumer is about to arrive, auto-promote will redo it.

Upstream tracker: piraeusdatastore/piraeus-operator#942

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andrei Kvapil <[email protected]>
@github-actions github-actions Bot added area/storage Issues or PRs related to storage (linstor, seaweedfs, bucket, velero, harbor) kind/bug Categorizes issue or PR as related to a bug labels Apr 29, 2026
@coderabbitai

coderabbitai Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 775daa79-93c4-4fa7-8a37-40e25e7dac97

📥 Commits

Reviewing files that changed from the base of the PR and between f45facc and a6ac048.

📒 Files selected for processing (1)
  • packages/system/linstor/hack/plunger/plunger-satellite.sh

📝 Walkthrough

Walkthrough

Introduces a new DRBD remediation function that automatically demotes idle Primary resources to Secondary state. The function parses JSON status output, identifies Primary resources with no open devices on the current node, and attempts demotion via drbdadm secondary, maintaining system resilience by continuing existing workflows on errors.

Changes

Cohort / File(s) Summary
DRBD Remediation
packages/system/linstor/hack/plunger/plunger-satellite.sh
Added drbd_fix_idle_primary() function that parses drbdsetup status JSON output to identify and demote idle Primary DRBD resources to Secondary state, preventing resource stalls. Integrated into main loop with error resilience.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A primary sits still with no work to do,
Our plunger detects it and demotion ensues,
Parse, find, and demote with JSON insight,
DRBD stays balanced, the system stays right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding a plunger handler that demotes idle-Primary DRBD resources, which matches the core functionality added in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/linstor-plunger-idle-primary

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a recurring issue where DRBD resources fail to automatically demote from Primary after provisioning, causing subsequent mount failures on target nodes. By introducing a cleanup mechanism in the satellite sidecar, the system can now safely identify and demote these idle resources, ensuring that legitimate consumers can successfully publish volumes.

Highlights

  • Idle Primary Detection: Added a new function drbd_fix_idle_primary to detect DRBD resources that remain in a Primary state on a node without any active consumers.
  • Automatic Demotion: Implemented logic to automatically demote these idle resources to Secondary using drbdadm secondary, preventing mount errors during PVC provisioning.
  • Plunger Integration: Integrated the new fix into the main loop of plunger-satellite.sh to ensure continuous monitoring and cleanup.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@dosubot dosubot Bot added the size/M This PR changes 30-99 lines, ignoring generated files label Apr 29, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces the drbd_fix_idle_primary function to the plunger-satellite.sh script to automatically demote DRBD resources that remain in the Primary state without active consumers, addressing an issue where auto-promote can block volume publishing on other nodes. Feedback suggests a performance optimization to fetch the DRBD status JSON once in the main loop and pass it as an argument to both drbd_fix_idle_primary and drbd_fix_stalled_sync to avoid redundant, expensive calls to drbdsetup.

Comment on lines +34 to +49
drbd_fix_idle_primary() {
local json
json="$(drbd_status_json)"
[ -n "$json" ] || return 0

printf '%s' "$json" | jq -r '
.[]?
| select(.role == "Primary")
| select(all(.devices[]?; .open == false))
| .name
' | while IFS= read -r res; do
[ -n "$res" ] || continue
log "Idle Primary detected: res=$res open:no -> drbdadm secondary"
drbdadm secondary "$res" || log "WARN: secondary failed for $res"
done
}

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.

medium

The drbd_fix_idle_primary function calls drbd_status_json to fetch the DRBD status. However, drbd_fix_stalled_sync (called later in the main loop) also calls the same function. Since drbdsetup status --json can be relatively expensive on systems with many resources, it would be more efficient to fetch the JSON once in the main loop and pass it as an argument to both functions. Note that while drbd_fix_stalled_sync is not fully within the diff, its call site is, and its definition is available in the file context.

@IvanHunters

Copy link
Copy Markdown
Collaborator

I have a complementary fix in #2538 that targets the same root cause from the prevention side: retries drbdadm secondary with exponential backoff (7 attempts, 250 ms to 2 s) when stderr matches Device is held open by someone, applied only on the post-mkfs path in DrbdPrimary.close().

These compose naturally. #2538 prevents the race in-flight, this PR is the safety net when prevention misses or when a resource ends up in idle-Primary for other reasons. We've also seen a related symptom that the plunger's local check wouldn't catch: the controller snapshot freezing in SyncTarget(N%) / Inconsistent / DELETING while the satellite kernel state is Established/UpToDate. Only drbdadm down/up nudges the satellite to re-report.

Related upstream: LINBIT/linstor-server#268, LINBIT/drbd#74.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 29, 2026
@kvaps
Andrei Kvapil (kvaps) merged commit a4bd274 into main Apr 30, 2026
13 checks passed
@kvaps
Andrei Kvapil (kvaps) deleted the fix/linstor-plunger-idle-primary branch April 30, 2026 13:17
@myasnikovdaniil myasnikovdaniil added the kind/backport Categorizes issue or PR as requiring a backport to the current release line label May 6, 2026
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Successfully created backport PR for release-1.3:

myasnikovdaniil added a commit that referenced this pull request May 6, 2026
…D resources (#2580)

# Description
Backport of #2539 to `release-1.3`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/storage Issues or PRs related to storage (linstor, seaweedfs, bucket, velero, harbor) kind/backport Categorizes issue or PR as requiring a backport to the current release line kind/bug Categorizes issue or PR as related to a bug lgtm This PR has been approved by a maintainer size/M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants