This is an automated email from the ASF dual-hosted git repository.
jojochuang 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 63c184729fb HDDS-16960. Keep secret key polling running after refresh
failures (#11824)
63c184729fb is described below
commit 63c184729fb3676a529af64db2ffaca5647b9e1b
Author: Andy Huang <[email protected]>
AuthorDate: Fri Oct 30 06:46:31 2026 +0800
HDDS-16960. Keep secret key polling running after refresh failures (#11824)
Co-authored-by: Specula (Claude Opus 5.5).
---
.../symmetric/DefaultSecretKeySignerClient.java | 13 ++++-
.../symmetric/TestDefaultSecretKeyClient.java | 65 ++++++++++++++++++++++
2 files changed, 75 insertions(+), 3 deletions(-)
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/symmetric/DefaultSecretKeySignerClient.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/symmetric/DefaultSecretKeySignerClient.java
index ab19fce56a9..cefd8e7e836 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/symmetric/DefaultSecretKeySignerClient.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/symmetric/DefaultSecretKeySignerClient.java
@@ -148,9 +148,16 @@ private void scheduleSecretKeyPoller(ConfigurationSource
conf,
LOG.info("Scheduling SecretKeyPoller with initial delay of {} " +
"and interval of {}", initialDelay, interval);
- executorService.scheduleAtFixedRate(() -> checkAndRefresh(rotateDuration),
- initialDelay.toMillis(), interval.toMillis(),
- TimeUnit.MILLISECONDS);
+ executorService.scheduleAtFixedRate(() -> {
+ try {
+ checkAndRefresh(rotateDuration);
+ } catch (VirtualMachineError | ThreadDeath t) {
+ throw t;
+ } catch (Throwable t) {
+ // Anything thrown from a periodic task suppresses all subsequent
executions.
+ LOG.warn("Failed to refresh the secret key, will retry at the next
check", t);
+ }
+ }, initialDelay.toMillis(), interval.toMillis(), TimeUnit.MILLISECONDS);
}
private synchronized void checkAndRefresh(Duration rotateDuration) {
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/symmetric/TestDefaultSecretKeyClient.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/symmetric/TestDefaultSecretKeyClient.java
index 174d770b587..273d84a17d2 100644
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/symmetric/TestDefaultSecretKeyClient.java
+++
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/security/symmetric/TestDefaultSecretKeyClient.java
@@ -17,9 +17,15 @@
package org.apache.hadoop.hdds.security.symmetric;
+import static
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SECRET_KEY_ROTATE_CHECK_DURATION;
+import static
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SECRET_KEY_ROTATE_DURATION;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -28,12 +34,71 @@
import java.io.UncheckedIOException;
import java.time.Duration;
import java.time.Instant;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.SecretKeyProtocol;
+import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.ArgumentCaptor;
+import org.mockito.MockedStatic;
/** Tests refreshing the signing key through the composite client. */
class TestDefaultSecretKeyClient {
+ static Error[] fatalErrors() {
+ return new Error[] {
+ new OutOfMemoryError("Test failure"), new StackOverflowError("Test
failure"), new ThreadDeath()
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("fatalErrors")
+ void pollerPropagatesFatalErrors(Error failure) throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ SecretKeyProtocol scm = mock(SecretKeyProtocol.class);
+ ManagedSecretKey oldKey = SecretKeyTestUtil.generateHmac(
+ Instant.now().minus(Duration.ofDays(2)), Duration.ofDays(9));
+ when(scm.getCurrentSecretKey()).thenReturn(oldKey).thenThrow(failure);
+ ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
+ try (MockedStatic<Executors> executors = mockStatic(Executors.class)) {
+ executors.when(() -> Executors.newScheduledThreadPool(eq(1),
any(ThreadFactory.class))).thenReturn(executor);
+ DefaultSecretKeySignerClient client = new
DefaultSecretKeySignerClient(scm, "test-");
+ client.start(conf);
+ ArgumentCaptor<Runnable> poller =
ArgumentCaptor.forClass(Runnable.class);
+ verify(executor).scheduleAtFixedRate(poller.capture(), anyLong(),
anyLong(), eq(TimeUnit.MILLISECONDS));
+ assertSame(failure, assertThrows(failure.getClass(), () ->
poller.getValue().run()));
+ assertSame(oldKey, client.getCurrentSecretKey());
+ }
+ }
+
+ @Test
+ void pollerKeepsRefreshingAfterFailedPolls() throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(HDDS_SECRET_KEY_ROTATE_DURATION, "1d");
+ conf.set(HDDS_SECRET_KEY_ROTATE_CHECK_DURATION, "10ms");
+ SecretKeyProtocol scm = mock(SecretKeyProtocol.class);
+ ManagedSecretKey oldKey = SecretKeyTestUtil.generateHmac(
+ Instant.now().minus(Duration.ofDays(2)), Duration.ofDays(9));
+ ManagedSecretKey newKey = SecretKeyTestUtil.generateHmac(Instant.now(),
Duration.ofDays(9));
+ when(scm.getCurrentSecretKey()).thenReturn(oldKey)
+ .thenThrow(new IOException("SCM fetch failed"))
+ .thenThrow(new IllegalStateException("Unexpected failure"))
+ .thenThrow(new LinkageError("Unexpected error"))
+ .thenReturn(newKey);
+ SecretKeyClient client = DefaultSecretKeyClient.create(conf, scm, "test-");
+ try {
+ client.start(conf);
+ GenericTestUtils.waitFor(() ->
newKey.equals(client.getCurrentSecretKey()), 10, 5_000);
+ verify(scm, times(5)).getCurrentSecretKey();
+ } finally {
+ client.stop();
+ }
+ }
+
@Test
void refetchSecretKeyUpdatesCurrentKey() throws Exception {
SecretKeyProtocol scm = mock(SecretKeyProtocol.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]