This is an automated email from the ASF dual-hosted git repository.
smengcl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 06a19642f24 HDDS-16949. BackgroundService stops permanently when
getTasks() throws a RuntimeException (#11496)
06a19642f24 is described below
commit 06a19642f24b65d73c379c6cd95ef48ace14fa12
Author: Siyao Meng <[email protected]>
AuthorDate: Tue Oct 13 11:47:03 2026 -0700
HDDS-16949. BackgroundService stops permanently when getTasks() throws a
RuntimeException (#11496)
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
---
.../hadoop/hdds/utils/BackgroundService.java | 9 +++++++-
.../apache/hadoop/util/TestBackgroundService.java | 24 ++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/BackgroundService.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/BackgroundService.java
index 89d6c032345..24990ceddd9 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/BackgroundService.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/BackgroundService.java
@@ -152,7 +152,14 @@ public void run() {
if (LOG.isDebugEnabled()) {
LOG.debug("Running background service : {}", serviceName);
}
- BackgroundTaskQueue tasks = getTasks();
+ final BackgroundTaskQueue tasks;
+ try {
+ tasks = getTasks();
+ } catch (RuntimeException e) {
+ // An exception escaping run() would cancel all future executions of
this periodic task.
+ LOG.error("Failed to get tasks for background service {}. Will retry
in the next interval.", serviceName, e);
+ return;
+ }
if (tasks.isEmpty()) {
// No task found, or some problems to init tasks
// return and retry in next interval.
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/util/TestBackgroundService.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/util/TestBackgroundService.java
index 2c5ed1bfea5..6d5ed78d7f8 100644
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/util/TestBackgroundService.java
+++
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/util/TestBackgroundService.java
@@ -17,6 +17,7 @@
package org.apache.hadoop.util;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -164,4 +165,27 @@ public void testSingleWorkerThread() throws
InterruptedException, TimeoutExcepti
assertEquals(expFinalValues, IntStream.range(0,
nTasks).boxed().map(map::get).collect(Collectors.toList()));
assertTrue(queue.isEmpty());
}
+
+ @Test
+ public void testServiceKeepsRunningAfterGetTasksThrows() throws
InterruptedException, TimeoutException {
+ int interval = 100;
+ int serviceTimeout = 3000;
+ AtomicInteger getTasksCalls = new AtomicInteger();
+ Map<Integer, Integer> map = new HashMap<>();
+ queue.add(new TestTask(0, map, new HashMap<>()));
+ backgroundService = new BackgroundService("testGetTasksThrows", interval,
TimeUnit.MILLISECONDS, 1,
+ serviceTimeout) {
+ @Override
+ public BackgroundTaskQueue getTasks() {
+ if (getTasksCalls.incrementAndGet() == 1) {
+ throw new RuntimeException("simulated failure");
+ }
+ return queue;
+ }
+ };
+ backgroundService.start();
+ // The first run throws, the periodic task must not be cancelled and the
task runs in a later interval.
+ GenericTestUtils.waitFor(() -> map.get(0) == 1, interval / 5,
serviceTimeout);
+ assertThat(getTasksCalls.get()).isGreaterThan(1);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]