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 2020/10/22 13:31:16 UTC

[GitHub] [cloudstack] ravening commented on a change in pull request #3997: New API endpoint: UpdateVlanIpRange

ravening commented on a change in pull request #3997:
URL: https://github.com/apache/cloudstack/pull/3997#discussion_r510163155



##########
File path: server/src/main/java/com/cloud/test/IPRangeConfig.java
##########
@@ -313,35 +313,35 @@ public static long getCidrSize(String pod, String zone) {
         return problemIPs;
     }
 
-    private Vector<String> deletePublicIPRange(TransactionLegacy txn, long startIP, long endIP, long vlanDbId) {
-        String deleteSql = "DELETE FROM `cloud`.`user_ip_address` WHERE public_ip_address = ? AND vlan_id = ?";
-        String isPublicIPAllocatedSelectSql = "SELECT * FROM `cloud`.`user_ip_address` WHERE public_ip_address = ? AND vlan_id = ?";
+    public Vector<String> deletePublicIPRange(TransactionLegacy txn, long startIP, long endIP, long vlanDbId) {
+        String deleteSql = "DELETE FROM `cloud`.`user_ip_address` WHERE public_ip_address = ? AND vlan_db_id = ?";
+        String isPublicIPAllocatedSelectSql = "SELECT * FROM `cloud`.`user_ip_address` WHERE public_ip_address = ? AND vlan_db_id = ?";
 
         Vector<String> problemIPs = new Vector<String>();
         Connection conn = null;
         try {
             conn = txn.getConnection();
         }
         catch (SQLException e) {
-            System.out.println("deletePublicIPRange. Exception: " +e.getMessage());
+            System.out.println("deletePublicIPRange. Exception: " + e.getMessage());
             return null;
         }
-        try(PreparedStatement stmt = conn.prepareStatement(deleteSql);
+        try (PreparedStatement stmt = conn.prepareStatement(deleteSql);
             PreparedStatement isAllocatedStmt = conn.prepareStatement(isPublicIPAllocatedSelectSql);) {
             while (startIP <= endIP) {
-                if (!isPublicIPAllocated(startIP, vlanDbId, isAllocatedStmt)) {
+                if (!isPublicIPAllocated(NetUtils.long2Ip(startIP), vlanDbId, isAllocatedStmt)) {

Review comment:
       If start ip 10.10.10.1 and endip is 10.10.10.250 then you are running sql query 250 times right which is bad?
   Why dont you fetch all ip's of particular vldn id and check the state of ip address? so it will be just one query per ip range




----------------------------------------------------------------
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.

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