Skip to content

Keep management server IDs same across restarts - #14551

Open
MashrafeeAryan wants to merge 6 commits into
apache:mainfrom
MashrafeeAryan:fix/14253-stable-management-server-id
Open

MashrafeeAryan wants to merge 6 commits into
apache:mainfrom
MashrafeeAryan:fix/14253-stable-management-server-id

Conversation

@MashrafeeAryan

@MashrafeeAryan MashrafeeAryan commented Nov 1, 2026 •

Copy link
Copy Markdown

Description

Fixes: #14253

CloudStack could give a management server a new ID after a restart if it chose a different network card. This could prevent agents from reconnecting.

This PR saves the server ID in a file and reuses it after restarts. It also makes the other affected parts of CloudStack use the same ID.

I also updated the avoid list so an old Down record does not block an address that has an Up record. This helps installations already affected by the bug. (I am not sure if this is necessary. I am open to removing this part from the PR)

The main changes I did:

  • Save the ID once and reuse it after restarts
  • Use the shared ID for server identity, statistics jobs, network usage, and router management
  • Let admins choose an ID or a different file location when needed
  • Stop old duplicate records from making agents skip an address marked Up

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

Built the management server and ran 17 automated tests on Windows using OpenJDK 11 and Maven 3.9.9.

All 17 tests passed:

  • ManagementServerIdTest: 11 tests
  • ManagementServerHostDaoImplTest: 4 tests
  • ManagementServerIdentityTest: 2 tests

Whitespace checks also passed.

How did you try to break this feature and the system with this change?

  • Changed the MAC-based ID and checked that the saved ID was still used
  • Tried bad IDs, broken file paths, and failed writes
  • Had three programs use the same ID file at once
  • Checked that old offline records do not block an address marked Up
  • Checked that the right server still starts its statistics update

Reproduction
I have not reproduced this on a live CloudStack installation.

Save the initial ID and reuse it when network interfaces change. Add JVM overrides and regression tests for issue apache#14253.
Explain the ID file, JVM settings, and upgrade steps for issue apache#14253.
Flush the initial identity to a temporary sibling file and atomically publish it while holding the existing process lock. Clean up failed writes and verify that initialization can be retried without an invalid identity file.

Related to apache#14253.
Route the remaining management identity consumers through ManagementServerNode instead of reading the current MAC address. Cover the management service ID and disk statistics ownership when the saved identity differs from the MAC.

Related to apache#14253.
Build the avoid list from one snapshot of nonremoved management server records. An Up record takes precedence over stale non-Up identities sharing its IP; unavailable addresses remain avoided without duplicates. Retain database records and document the recovery behavior.

Related to apache#14253.
Explain the persistent ID flow, identity consumers, and regression tests with short comments without ending periods.

Keep installation instructions concise and document preserving the ID file, configuration overrides, and recovery for existing installations. Update release notes for stable IDs and active IP handling.

Restore CloudZonesStartupProcessor to its pre-fix version because its local node ID is unused. Keep its existing configure() behavior and exclude the file from the overall PR diff.
@boring-cyborg

boring-cyborg Bot commented Nov 1, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

@MashrafeeAryan
MashrafeeAryan marked this pull request as draft November 1, 2026 20:29
@MashrafeeAryan
MashrafeeAryan force-pushed the fix/14253-stable-management-server-id branch from baf944d to c22a289 Compare November 1, 2026 20:34
@MashrafeeAryan
MashrafeeAryan marked this pull request as ready for review November 1, 2026 20:44
@MashrafeeAryan MashrafeeAryan changed the title Management Server ID Fix Keep management server IDs same across restarts Nov 1, 2026
@MashrafeeAryan

Copy link
Copy Markdown
Author

Hi @DaanHoogland, would you please be able to review this PR when you have a chance? I understand you have other commitments, and I would appreciate any feedback or suggestions whenever you have time. Thank you so much!

@Damans227 Damans227 self-assigned this Nov 4, 2026
}

// First startup: obtain the initial MAC-derived ID and validate it
long id = parse(Long.toString(initialId.getAsLong()));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@MashrafeeAryan on upgrade, first start has no id file so it still takes id from mac. if the upgrade changes java and nic order flips, wont we save the wrong id forever? maybe reuse the old id from mshost table if one exists for this host?


private static final long s_nodeId = MacAddress.getMacAddress().toLong();
// Load the ID once and keep the same value for the life of this process
private static final long s_nodeId = ManagementServerId.get();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@MashrafeeAryan id is now loaded when the class loads. if reading the file fails, wont it break every class using ManagementServerNode instead of giving a clean error? can we load it in start() instead?

StandardOpenOption.CREATE, StandardOpenOption.WRITE);
FileLock lock = lockChannel.lock()) {
// Reuse the saved ID without checking network interfaces again
if (Files.exists(path)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@MashrafeeAryan if someone clones the ms vm, the clone gets the same id file and same id as the original. today the new mac would give it a new one. should we catch this somehow?

// This method handles duplicate records that already exist
// Old Down records must not make agents skip an address that also has an Up record
@Override
public List<String> listNonUpStateMsIPs() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@MashrafeeAryan instead of skipping old down rows in the avoid list, can we just mark old rows with the same ip as removed when the ms registers? fixes the leftover rows too, like in #14448

@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.77%. Comparing base (dfaae63) to head (c22a289).
⚠️ Report is 415 commits behind head on main.

Files with missing lines Patch % Lines
.../cloudstack/utils/identity/ManagementServerId.java 90.00% 2 Missing and 2 partials ⚠️
...in/java/com/cloud/server/ManagementServerImpl.java 0.00% 2 Missing ⚠️
...ava/com/cloud/network/NetworkUsageManagerImpl.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14551      +/-   ##
============================================
+ Coverage     18.05%   20.77%   +2.72%     
- Complexity    16320    21924    +5604     
============================================
  Files          5937     6497     +560     
  Lines        536919   591647   +54728     
  Branches      65810    72590    +6780     
============================================
+ Hits          96932   122931   +25999     
- Misses       428915   455380   +26465     
- Partials      11072    13336    +2264     
Flag Coverage Δ
uitests 3.88% <ø> (-0.16%) ⬇️
unittests 22.08% <87.50%> (+2.95%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Management server msid depends on volatile network interface order, causing agent reconnection failures

2 participants