JoaoJandre commented on code in PR #9498:
URL: https://github.com/apache/cloudstack/pull/9498#discussion_r1768562494


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java:
##########
@@ -637,6 +639,39 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, 
KVMStoragePool pool) {
         }
     }
 
+    /**
+     * adjust refcount
+     */
+    private int adjustStoragePoolRefCount(String uuid, int adjustment) {
+        synchronized (uuid) {
+            // some access on the storagePoolRefCounts.key(uuid) element
+            int refCount = storagePoolRefCounts.computeIfAbsent(uuid, k -> 0);
+            refCount += adjustment;
+            storagePoolRefCounts.put(uuid, refCount);
+            if (refCount < 1) {
+                storagePoolRefCounts.remove(uuid);
+            } else {
+                storagePoolRefCounts.put(uuid, refCount);
+            }

Review Comment:
   ```suggestion
               if (refCount < 1) {
                   storagePoolRefCounts.remove(uuid);
               } else {
                   storagePoolRefCounts.put(uuid, refCount);
               }
   ```
   Why put the refCount only to remove or put it again in the next instruction?



##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java:
##########
@@ -637,6 +639,39 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, 
KVMStoragePool pool) {
         }
     }
 
+    /**
+     * adjust refcount
+     */
+    private int adjustStoragePoolRefCount(String uuid, int adjustment) {
+        synchronized (uuid) {

Review Comment:
   Will this synchronized work as expected? Do we guarantee that every String 
with the same uuid as value is the same object? 



-- 
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-unsubscr...@cloudstack.apache.org

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

Reply via email to