-
Notifications
You must be signed in to change notification settings - Fork 1.2k
check for active MSses before starting DB upgrade #12140
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
base: 4.20
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -123,7 +123,10 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.cloud.utils.crypt.DBEncryptionUtil; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.cloud.utils.db.GlobalLock; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.cloud.utils.db.ScriptRunner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.cloud.utils.db.Transaction; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.cloud.utils.db.TransactionCallback; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.cloud.utils.db.TransactionLegacy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.cloud.utils.db.TransactionStatus; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.cloud.utils.exception.CloudRuntimeException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.google.common.annotations.VisibleForTesting; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -448,39 +451,71 @@ public void check() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new CloudRuntimeException("Unable to acquire lock to check for database integrity."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initializeDatabaseEncryptors(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // not sure about the right moment to do this yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checkIfStandalone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DaanHoogland marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doUpgrades(lock); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lock.releaseRef(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void checkIfStandalone() throws CloudRuntimeException { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DaanHoogland marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boolean standalone = Transaction.execute(new TransactionCallback<>() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public Boolean doInTransaction(TransactionStatus status) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String sql = "SELECT COUNT(*) FROM `cloud`.`management_server` WHERE `status` = 'UP'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DaanHoogland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try (Connection conn = TransactionLegacy.getStandaloneConnection(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DaanHoogland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PreparedStatement pstmt = conn.prepareStatement(sql); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ResultSet rs = pstmt.executeQuery()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (rs.next()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int count = rs.getInt(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return count <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DaanHoogland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DaanHoogland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (SQLException e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String errorMessage = "Unable to check if the management server is running in standalone mode."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LOGGER.error(errorMessage, e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new CloudRuntimeException(errorMessage, e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
462
to
480
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boolean standalone = Transaction.execute(new TransactionCallback<>() { | |
| @Override | |
| public Boolean doInTransaction(TransactionStatus status) { | |
| String sql = "SELECT COUNT(*) FROM `cloud`.`management_server` WHERE `status` = 'UP'"; | |
| try (Connection conn = TransactionLegacy.getStandaloneConnection(); | |
| PreparedStatement pstmt = conn.prepareStatement(sql); | |
| ResultSet rs = pstmt.executeQuery()) { | |
| if (rs.next()) { | |
| int count = rs.getInt(1); | |
| return count <= 1; | |
| } | |
| } catch (SQLException e) { | |
| String errorMessage = "Unable to check if the management server is running in standalone mode."; | |
| LOGGER.error(errorMessage, e); | |
| throw new CloudRuntimeException(errorMessage, e); | |
| } | |
| return true; | |
| } | |
| }); | |
| String sql = "SELECT COUNT(*) FROM `cloud`.`management_server` WHERE `status` = 'UP'"; | |
| boolean standalone = true; | |
| try (Connection conn = TransactionLegacy.getStandaloneConnection(); | |
| PreparedStatement pstmt = conn.prepareStatement(sql); | |
| ResultSet rs = pstmt.executeQuery()) { | |
| if (rs.next()) { | |
| int count = rs.getInt(1); | |
| standalone = count <= 1; | |
| } | |
| } catch (SQLException e) { | |
| String errorMessage = "Unable to check if the management server is running in standalone mode."; | |
| LOGGER.error(errorMessage, e); | |
| throw new CloudRuntimeException(errorMessage, e); | |
| } |
DaanHoogland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
DaanHoogland marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Nov 26, 2025
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.
The new checkIfStandalone() method lacks test coverage. Consider adding unit tests to verify:
- The behavior when no management servers are running (count = 0)
- The behavior when exactly one management server is running (count = 1)
- The behavior when multiple management servers are running (count > 1)
- The behavior when a SQLException occurs during the check
This is particularly important since this check prevents upgrades from proceeding when multiple servers are detected.
Uh oh!
There was an error while loading. Please reload this page.