DaanHoogland commented on code in PR #12140:
URL: https://github.com/apache/cloudstack/pull/12140#discussion_r2569402496


##########
engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java:
##########
@@ -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();
+            doUpgrades(lock);
+        } finally {
+            lock.releaseRef();
+        }
+    }
+    private void checkIfStandalone() throws CloudRuntimeException {
+        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;
+            }
+        });
+        if (! standalone) {
+            String msg = "CloudStack is running multiple management servers 
and attempting to upgrade. Upgrades can only be run in standalone mode. 
Skipping database upgrade check.";

Review Comment:
   ```suggestion
               String msg = "CloudStack is running multiple management servers 
while attempting to upgrade. Upgrades can only be run in standalone mode. 
Aborting.";
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to