diff --git a/server/manager/src/main/java/org/apache/accumulo/manager/compaction/coordinator/CompactionCoordinator.java b/server/manager/src/main/java/org/apache/accumulo/manager/compaction/coordinator/CompactionCoordinator.java index 7a0b275994b..941d6647d0c 100644 --- a/server/manager/src/main/java/org/apache/accumulo/manager/compaction/coordinator/CompactionCoordinator.java +++ b/server/manager/src/main/java/org/apache/accumulo/manager/compaction/coordinator/CompactionCoordinator.java @@ -1065,8 +1065,8 @@ private void cleanUpEmptyCompactorPathInZK() { } CompactionJobPriorityQueue queue = getJobQueues().getQueue(cgid); if (queue != null) { - queue.setMaxSize( - Math.min((int) (aliveCompactorsForGroup * queueSizeFactor), Integer.MAX_VALUE)); + queue.setMaxSize(Math.min( + Math.max(1, (int) (aliveCompactorsForGroup * queueSizeFactor)), Integer.MAX_VALUE)); } } diff --git a/server/manager/src/main/java/org/apache/accumulo/manager/compaction/queue/CompactionJobPriorityQueue.java b/server/manager/src/main/java/org/apache/accumulo/manager/compaction/queue/CompactionJobPriorityQueue.java index 2099dbed6d2..1f9738dac78 100644 --- a/server/manager/src/main/java/org/apache/accumulo/manager/compaction/queue/CompactionJobPriorityQueue.java +++ b/server/manager/src/main/java/org/apache/accumulo/manager/compaction/queue/CompactionJobPriorityQueue.java @@ -235,6 +235,8 @@ public synchronized int getMaxSize() { } public synchronized void setMaxSize(int maxSize) { + Preconditions.checkArgument(maxSize > 0, + "Maximum size of the Compaction job priority queue must be greater than 0"); this.maxSize.set(maxSize); } diff --git a/server/manager/src/test/java/org/apache/accumulo/manager/compaction/queue/CompactionJobPriorityQueueTest.java b/server/manager/src/test/java/org/apache/accumulo/manager/compaction/queue/CompactionJobPriorityQueueTest.java index 2592be35aab..37213cdc488 100644 --- a/server/manager/src/test/java/org/apache/accumulo/manager/compaction/queue/CompactionJobPriorityQueueTest.java +++ b/server/manager/src/test/java/org/apache/accumulo/manager/compaction/queue/CompactionJobPriorityQueueTest.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; @@ -345,6 +346,10 @@ public void testChangeMaxSize() { assertEquals(100, queue.getMaxSize()); queue.setMaxSize(50); assertEquals(50, queue.getMaxSize()); + assertThrows(IllegalArgumentException.class, () -> queue.setMaxSize(0)); + assertThrows(IllegalArgumentException.class, () -> queue.setMaxSize(-1)); + // Make sure previous value was not changed after invalid setting + assertEquals(50, queue.getMaxSize()); } }