You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/03/07 16:46:03 UTC

[GitHub] [cloudstack] nvazquez commented on a change in pull request #5382: fix mismatching between db uuids and custom attributes uuids

nvazquez commented on a change in pull request #5382:
URL: https://github.com/apache/cloudstack/pull/5382#discussion_r820895751



##########
File path: engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java
##########
@@ -75,6 +78,29 @@ public void performDataMigration(Connection conn) {
         generateUuidForExistingSshKeyPairs(conn);
         populateAnnotationPermissions(conn);
         correctGuestOsIdsInHypervisorMapping(conn);
+        fixWrongPoolUuid(conn);
+    }
+
+    public void fixWrongPoolUuid(Connection conn) {
+        LOG.debug("Replacement of faulty pool uuids");
+        try (PreparedStatement pstmt = conn.prepareStatement("SELECT id,uuid FROM storage_pool "
+                + "WHERE uuid NOT LIKE \"%-%-%-%\" AND removed IS NULL;"); ResultSet rs = pstmt.executeQuery()) {
+            PreparedStatement updateStmt = conn.prepareStatement("update storage_pool set uuid = ? where id = ?");
+            while (rs.next()) {
+                    UUID poolUuid = new UUID(
+                            new BigInteger(rs.getString(2).substring(0, 16), 16).longValue(),
+                            new BigInteger(rs.getString(2).substring(16), 16).longValue()
+                    );
+                    updateStmt.setLong(2, rs.getLong(1));
+                    updateStmt.setString(1, poolUuid.toString());
+                    updateStmt.addBatch();
+            }
+            updateStmt.executeBatch();
+        } catch (SQLException ex) {
+            String errorMsg = "fixWrongPoolUuid:Exception while updating faulty pool uuids";
+            LOG.error(errorMsg,ex);
+            throw new CloudRuntimeException(errorMsg, ex);        

Review comment:
       ```suggestion
               throw new CloudRuntimeException(errorMsg, ex);
   ```




-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org