This is an automated email from the ASF dual-hosted git repository.
adoroszlai 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 e3f4c350c8a HDDS-16745. OM Client call without RPC leaves callId set,
later calls on handler fail (#11826)
e3f4c350c8a is described below
commit e3f4c350c8a6aa2c20eb9b61c81a781703344848
Author: Ayush Saxena <[email protected]>
AuthorDate: Thu Oct 29 16:30:13 2026 +0530
HDDS-16745. OM Client call without RPC leaves callId set, later calls on
handler fail (#11826)
Co-authored-by: Claude Opus 5 <[email protected]>
---
.../hadoop/io_/retry/RetryInvocationHandler.java | 13 ++++++-----
.../main/java/org/apache/hadoop/ipc_/Client.java | 8 +++++++
.../apache/hadoop/io_/retry/TestRetryProxy.java | 26 ++++++++++++++++++++++
...doopRpcOMFollowerReadFailoverProxyProvider.java | 24 ++++++++++++++++----
4 files changed, 62 insertions(+), 9 deletions(-)
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/io_/retry/RetryInvocationHandler.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/io_/retry/RetryInvocationHandler.java
index f421a1dbd1b..657fcf158f2 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/io_/retry/RetryInvocationHandler.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/io_/retry/RetryInvocationHandler.java
@@ -48,9 +48,6 @@ public class RetryInvocationHandler<T> implements
RpcInvocationHandler {
public static final Logger LOG = LoggerFactory.getLogger(
RetryInvocationHandler.class);
- public static final ThreadLocal<Boolean> SET_CALL_ID_FOR_TEST =
- ThreadLocal.withInitial(() -> true);
-
static class Call {
private final Method method;
private final Object[] args;
@@ -153,10 +150,16 @@ CallReturn invoke() throws Throwable {
}
Object invokeMethod() throws Throwable {
- if (isRpc && SET_CALL_ID_FOR_TEST.get()) {
+ if (isRpc) {
Client.setCallIdAndRetryCount(callId, counters.retries);
}
- return retryInvocationHandler.invokeMethod(method, args);
+ try {
+ return retryInvocationHandler.invokeMethod(method, args);
+ } finally {
+ if (isRpc) {
+ Client.clearCallIdAndRetryCount();
+ }
+ }
}
@Override
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ipc_/Client.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ipc_/Client.java
index 3497cec258e..9408a3052a1 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ipc_/Client.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ipc_/Client.java
@@ -97,6 +97,14 @@ public static void setCallIdAndRetryCount(int cid, int rc) {
retryCount.set(rc);
}
+ /**
+ * Clear a call id and retry count set for the next call but never consumed
by a {@link Call}.
+ */
+ public static void clearCallIdAndRetryCount() {
+ callId.remove();
+ retryCount.remove();
+ }
+
private final ConcurrentMap<ConnectionId, Connection> connections =
new ConcurrentHashMap<>();
private final Object putLock = new Object();
diff --git
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/io_/retry/TestRetryProxy.java
b/hadoop-hdds/common/src/test/java/org/apache/hadoop/io_/retry/TestRetryProxy.java
index f6a10cfa7b3..a805c89f292 100644
---
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/io_/retry/TestRetryProxy.java
+++
b/hadoop-hdds/common/src/test/java/org/apache/hadoop/io_/retry/TestRetryProxy.java
@@ -26,6 +26,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.any;
@@ -324,4 +325,29 @@ public void testWrappedAccessControlException() throws
Exception {
assertEquals(RetryDecision.FAIL, caughtRetryAction.action);
}
}
+
+ @Test
+ public void testCallIdClearedWhenNoRpcIsIssued() throws Exception {
+ // Implementing RpcProxy makes the handler set the call id; the
implementation
+ // then throws without issuing an RPC, so nothing consumes it.
+ class UnreliableRpcProxy extends UnreliableImplementation implements
RpcProxy {
+ @Override
+ public ConnectionId getConnectionId() {
+ return null;
+ }
+
+ @Override
+ public void close() {
+ }
+ }
+
+ UnreliableInterface unreliable = (UnreliableInterface) RetryProxy.create(
+ UnreliableInterface.class, new UnreliableRpcProxy(),
TRY_ONCE_THEN_FAIL);
+
+ for (int i = 0; i < 2; i++) {
+ // Without the call id being cleared, the second attempt throws
IllegalStateException.
+ assertThrows(UnreliableInterface.FatalException.class,
+ unreliable::alwaysFailsWithFatalException);
+ }
+ }
}
diff --git
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/ha/TestHadoopRpcOMFollowerReadFailoverProxyProvider.java
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/ha/TestHadoopRpcOMFollowerReadFailoverProxyProvider.java
index ec42e895c07..430a26c73c3 100644
---
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/ha/TestHadoopRpcOMFollowerReadFailoverProxyProvider.java
+++
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/ha/TestHadoopRpcOMFollowerReadFailoverProxyProvider.java
@@ -45,6 +45,7 @@
import com.google.protobuf.ServiceException;
import java.io.IOException;
import java.io.InterruptedIOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collection;
@@ -54,7 +55,6 @@
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
-import org.apache.hadoop.io_.retry.RetryInvocationHandler;
import org.apache.hadoop.ipc_.Client.ConnectionId;
import org.apache.hadoop.ipc_.RPC;
import org.apache.hadoop.ipc_.RemoteException;
@@ -498,6 +498,25 @@ void testReadException() throws Exception {
assertHandledBy(1);
}
+ @Test
+ void testReadAfterAddressRefreshDropsCachedProxy() throws Exception {
+ setupProxyProvider(3);
+ doRead();
+ assertHandledBy(0);
+
+ // Stand in for the node having been rescheduled to a new IP: the cached
address has to differ
+ // from what re-resolving localhost returns, so refreshAddressIfChanged()
swaps it and drops the
+ // cached proxy. The port stays the node's own, since createOMProxy maps
it back to its mock.
+ OMProxyInfo<OzoneManagerProtocolPB> current =
proxyProvider.getCurrentProxy();
+ current.setCachedAddressForTest(new
InetSocketAddress(InetAddress.getByName("127.0.0.99"), 0));
+ assertTrue(current.refreshAddressIfChanged());
+ assertNull(current.getProxy());
+
+ // The read has to recreate the dropped proxy rather than dial the null
one.
+ doRead();
+ assertHandledBy(0);
+ }
+
private void setupProxyProvider(int omNodeCount) throws Exception {
OzoneConfiguration config = new OzoneConfiguration();
config.setBoolean(OZONE_CLIENT_FOLLOWER_READ_ENABLED_KEY, true);
@@ -587,9 +606,6 @@ protected List<OMProxyInfo<OzoneManagerProtocolPB>>
initOmProxiesFromConfigs(
assertTrue(proxyProvider.isOmServiceSupportsFollowerRead());
// Wrap the follower read proxy provider in retry proxy to allow automatic
failover
retryProxy = OzoneManagerProtocolPB.newProxy(proxyProvider, 2 *
omNodeCount);
- // This is currently added to prevent IllegalStateException in
- // Client#setCallIdAndRetryCount since it seems that callId is set but not
unset properly
- RetryInvocationHandler.SET_CALL_ID_FOR_TEST.set(false);
}
private void doRead() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]