From 711b4a38f86f51e75e3be99ca54f178c063069b5 Mon Sep 17 00:00:00 2001 From: Lea Morschel Date: Tue, 5 Dec 2023 14:37:33 +0100 Subject: [PATCH] cleaner-disk: prevent ConcurrentModificationException in cleaning run Motivation: Cleaner-disk cless use a shared PoolInformationBase, which contains a pools map that is updated regularly based on pools being up/down. In a regularly scheduled cleaner run, the map values are streamed over, and when it is modified at the same time, a `ConcurrentHashMap` exception will be thrown. Modification: Change the PoolInformationBase pools map to a thread-safe implementation. Result: No more `ConcurrentHashMap` exception in cleaner-disk runs due to concurrent pool status changes. Target: master, 9.2, 9.1, 9.0, 8.2 Fixes: #7446 Requires-notes: yes Requires-book: no Patch: https://rb.dcache.org/r/14179/ Acked-by: Tigran Mkrtchyan --- .../java/org/dcache/chimera/namespace/DiskCleaner.java | 4 +--- .../org/dcache/chimera/namespace/PoolInformationBase.java | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/DiskCleaner.java b/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/DiskCleaner.java index c09b2b601d3..fdae8aaa4e1 100644 --- a/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/DiskCleaner.java +++ b/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/DiskCleaner.java @@ -89,11 +89,9 @@ public void setReportRemove(String[] reportRemove) { /** * runDelete Delete files on each pool from the poolList. - * - * @throws InterruptedException */ @Override - protected void runDelete() throws InterruptedException { + protected void runDelete() { if (!_hasHaLeadership) { LOGGER.warn("Delete run triggered despite not having leadership. " + "We assume this is a transient problem."); diff --git a/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/PoolInformationBase.java b/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/PoolInformationBase.java index 79bdf81fab2..0b2221c1538 100644 --- a/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/PoolInformationBase.java +++ b/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/PoolInformationBase.java @@ -5,8 +5,7 @@ import dmg.cells.nucleus.CellMessageReceiver; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.dcache.util.Args; /** @@ -25,12 +24,12 @@ public class PoolInformationBase implements CellMessageReceiver { /** * Map of all pools currently up. */ - private final Map _pools = new HashMap<>(); + private final ConcurrentHashMap _pools = new ConcurrentHashMap<>(); /** * Map from HSM instance name to the set of pools attached to that HSM. */ - private final Map> _hsmToPool = new HashMap<>(); + private final ConcurrentHashMap> _hsmToPool = new ConcurrentHashMap<>(); /** *