Damans227 commented on code in PR #14189:
URL: https://github.com/apache/cloudstack/pull/14189#discussion_r4158318464
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java:
##########
@@ -700,35 +700,30 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid,
KVMStoragePool pool) {
* adjust refcount
*/
private int adjustStoragePoolRefCount(String uuid, int adjustment) {
- final String mutexKey = storagePoolRefCounts.keySet().stream()
- .filter(k -> k.equals(uuid))
- .findFirst()
- .orElse(uuid);
- synchronized (mutexKey) {
- // some access on the storagePoolRefCounts.key(mutexKey) element
- int refCount = storagePoolRefCounts.computeIfAbsent(mutexKey, k ->
0);
- refCount += adjustment;
- if (refCount < 1) {
- storagePoolRefCounts.remove(mutexKey);
- } else {
- storagePoolRefCounts.put(mutexKey, refCount);
- }
- return refCount;
- }
+ /*
+ * compute() is atomic for the key, so concurrent callers cannot lose
an
+ * update. Returning null from the remapping function removes the
entry,
+ * which keeps the map free of pools that are no longer in use.
+ */
+ Integer refCount = storagePoolRefCounts.compute(uuid, (key, count) -> {
Review Comment:
the count itself is atomic now, but deleteStoragePool still does the destroy
and umount after this returns 0, outside any lock. if createStoragePool finds
the existing pool and increments right after that, wont the pool still get torn
down under it?
--
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]