Skip to content

Commit 7dcd34f

Browse files
committed
Clarify periodic disk check config behavior and add unit test
1 parent 9901a0e commit 7dcd34f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ public class DatanodeConfiguration extends ReconfigurableConfig {
309309
defaultValue = "60",
310310
type = ConfigType.LONG,
311311
tags = { DATANODE },
312-
description = "Periodic disk check run interval in minutes."
312+
description = "Periodic disk check run interval in minutes. " +
313+
"A negative value disables periodic disk checks. " +
314+
"A value of 0 is invalid and defaults to 60."
313315
)
314316
private long periodicDiskCheckIntervalMinutes =
315317
PERIODIC_DISK_CHECK_INTERVAL_MINUTES_DEFAULT;

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolumeChecker.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ private void invokeCallback() {
420420
*/
421421
public void shutdownAndWait(int gracePeriod, TimeUnit timeUnit) {
422422
if (started.compareAndSet(true, false)) {
423-
periodicDiskChecker.cancel(true);
423+
if (periodicDiskChecker != null) {
424+
periodicDiskChecker.cancel(true);
425+
}
424426
diskCheckerservice.shutdownNow();
425427
checkVolumeResultHandlerExecutorService.shutdownNow();
426428
metrics.unregister();

hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestStorageVolumeChecker.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.common.util.concurrent.Futures;
3232
import com.google.common.util.concurrent.ListenableFuture;
3333
import java.io.File;
34+
import java.lang.reflect.Field;
3435
import java.nio.file.Path;
3536
import java.time.Duration;
3637
import java.util.ArrayList;
@@ -299,6 +300,28 @@ public void testNumScansSkipped() throws Exception {
299300
checker.shutdownAndWait(0, TimeUnit.SECONDS);
300301
}
301302

303+
/**
304+
* Verify that negative values disable the periodic disk checker.
305+
*/
306+
@Test
307+
public void testNegativeIntervalDisablesPeriodicDiskChecker() throws Exception {
308+
setup();
309+
conf.setLong("hdds.datanode.periodic.disk.check.interval.minutes", -1);
310+
311+
StorageVolumeChecker checker =
312+
new StorageVolumeChecker(conf, new FakeTimer(), "test-");
313+
314+
checker.start();
315+
316+
Field f = StorageVolumeChecker.class.getDeclaredField("periodicDiskChecker");
317+
f.setAccessible(true);
318+
// Expect no ScheduledFuture to be created, as a negative interval disables
319+
// the periodic disk checker entirely.
320+
assertThat(f.get(checker)).isNull();
321+
// Verify shutdown is safe when no periodic task was scheduled.
322+
checker.shutdownAndWait(0, TimeUnit.SECONDS);
323+
}
324+
302325
/**
303326
* A checker to wraps the result of {@link HddsVolume#check} in
304327
* an ImmediateFuture.

0 commit comments

Comments
 (0)