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 8069f672941 HDDS-16919. Preserve interrupt semantics on SCM checkpoint
download f… (#11819)
8069f672941 is described below
commit 8069f6729415684132062b3c97be3632a16b41d1
Author: Andy Huang <[email protected]>
AuthorDate: Fri Oct 30 06:53:05 2026 +0800
HDDS-16919. Preserve interrupt semantics on SCM checkpoint download f…
(#11819)
Co-authored-by: Specula (Claude Opus 5.5).
---
.../hadoop/hdds/scm/ha/SCMSnapshotProvider.java | 5 ++-
.../hdds/scm/ha/TestSCMSnapshotProvider.java | 52 ++++++++++++++++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMSnapshotProvider.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMSnapshotProvider.java
index 17f8259d76b..63fa6ea579d 100644
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMSnapshotProvider.java
+++
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMSnapshotProvider.java
@@ -133,7 +133,10 @@ public DBCheckpoint getSCMDBSnapshot(String
leaderSCMNodeID)
try (SCMSnapshotDownloader downloadClient =
new InterSCMGrpcClient(host, port, conf, scmCertificateClient)) {
downloadClient.download(targetFile.toPath()).get();
- } catch (ExecutionException | InterruptedException e) {
+ } catch (ExecutionException e) {
+ LOG.error("Rocks DB checkpoint downloading failed", e);
+ throw new IOException(e);
+ } catch (InterruptedException e) {
LOG.error("Rocks DB checkpoint downloading failed", e);
Thread.currentThread().interrupt();
throw new IOException(e);
diff --git
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMSnapshotProvider.java
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMSnapshotProvider.java
index fd5e35f48e6..617ab25d2ee 100644
---
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMSnapshotProvider.java
+++
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMSnapshotProvider.java
@@ -18,19 +18,30 @@
package org.apache.hadoop.hdds.scm.ha;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockConstruction;
+import static org.mockito.Mockito.when;
import java.io.File;
+import java.io.IOException;
+import java.net.InetSocketAddress;
import java.nio.file.Path;
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import
org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import org.mockito.MockedConstruction;
/**
* Test cases for {@link SCMSnapshotProvider}.
@@ -100,6 +111,47 @@ void testConstructorFailsWhenRatisDirMissing(@TempDir Path
tempDir) {
assertTrue(exception.getMessage().contains("Ratis storage directory does
not exist"));
}
+ @Test
+ void testFailedDownloadDoesNotInterruptThread(@TempDir Path tempDir) throws
Exception {
+ SCMSnapshotProvider provider = createProvider(tempDir);
+ CompletableFuture<Path> download = new CompletableFuture<>();
+ download.completeExceptionally(new IOException("Download failed"));
+ try (MockedConstruction<InterSCMGrpcClient> ignored =
mockConstruction(InterSCMGrpcClient.class,
+ (client, context) ->
when(client.download(any(Path.class))).thenReturn(download))) {
+ IOException exception = assertThrows(IOException.class, () ->
provider.getSCMDBSnapshot("leader"));
+ assertInstanceOf(ExecutionException.class, exception.getCause());
+ assertFalse(Thread.currentThread().isInterrupted());
+ } finally {
+ Thread.interrupted();
+ }
+ }
+
+ @Test
+ void testInterruptedDownloadKeepsInterruptFlag(@TempDir Path tempDir) throws
Exception {
+ SCMSnapshotProvider provider = createProvider(tempDir);
+ CompletableFuture<Path> download = new CompletableFuture<>();
+ try (MockedConstruction<InterSCMGrpcClient> ignored =
mockConstruction(InterSCMGrpcClient.class,
+ (client, context) ->
when(client.download(any(Path.class))).thenReturn(download))) {
+ Thread.currentThread().interrupt();
+ IOException exception = assertThrows(IOException.class, () ->
provider.getSCMDBSnapshot("leader"));
+ assertInstanceOf(InterruptedException.class, exception.getCause());
+ assertTrue(Thread.currentThread().isInterrupted());
+ } finally {
+ Thread.interrupted();
+ }
+ }
+
+ private SCMSnapshotProvider createProvider(Path tempDir) {
+ OzoneConfiguration conf = createConfig(tempDir);
+ assertTrue(new File(SCMHAUtils.getSCMRatisDirectory(conf)).mkdirs());
+ assertTrue(new
File(SCMHAUtils.getSCMRatisSnapshotDirectory(conf)).mkdirs());
+ SCMNodeDetails leader = new SCMNodeDetails.Builder()
+ .setSCMNodeId("leader")
+ .setRpcAddress(new InetSocketAddress("127.0.0.1", 0))
+ .build();
+ return new SCMSnapshotProvider(conf, Collections.singletonList(leader),
mock(CertificateClient.class));
+ }
+
/**
* Helper method to create OzoneConfiguration with temp directories.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]