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 7f5e3367c4a HDDS-17851. StreamInitPutBlock should not create Raft log
when ozone.client.datastream.putblock.without.raft.enabled (#12081)
7f5e3367c4a is described below
commit 7f5e3367c4a3bf73d73d82a2146c0489a3908d6c
Author: Rui Wang <[email protected]>
AuthorDate: Wed Nov 18 22:35:39 2026 +0800
HDDS-17851. StreamInitPutBlock should not create Raft log when
ozone.client.datastream.putblock.without.raft.enabled (#12081)
---
.../apache/hadoop/hdds/scm/XceiverClientRatis.java | 6 +++-
.../hdds/scm/storage/BlockDataStreamOutput.java | 11 +++++--
.../hadoop/hdds/scm/TestXceiverClientRatis.java | 37 +++++++++++++++++++---
.../org/apache/hadoop/hdds/ratis/RatisHelper.java | 21 +++++++++++-
4 files changed, 67 insertions(+), 8 deletions(-)
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientRatis.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientRatis.java
index 0b2c9177e8c..de06ebc969e 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientRatis.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientRatis.java
@@ -46,6 +46,7 @@
import org.apache.hadoop.hdds.scm.client.ClientTrustManager;
import org.apache.hadoop.hdds.scm.client.HddsClientUtils;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.apache.hadoop.hdds.scm.storage.BlockDataStreamOutput;
import org.apache.hadoop.hdds.security.SecurityConfig;
import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.util.Time;
@@ -214,9 +215,12 @@ public void connect() throws Exception {
RatisHelper.toRaftPeerId(pipeline.getClosestNode()));
}
+ // StreamInitWithPutBlock streams commit PutBlock on stream close, so they
must not be forwarded to the Raft log.
+ final boolean skipSendForward =
BlockDataStreamOutput.isPutBlockWithoutRaft(
+ ozoneConfiguration.getObject(OzoneClientConfig.class), getPipeline());
if (!client.compareAndSet(null,
RatisHelper.newRaftClient(rpcType, getPipeline(), retryPolicy,
- tlsConfig, ozoneConfiguration))) {
+ tlsConfig, ozoneConfiguration, skipSendForward))) {
throw new IllegalStateException("Client is already connected.");
}
}
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockDataStreamOutput.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockDataStreamOutput.java
index cd2c5dba032..5c4f5be58ed 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockDataStreamOutput.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockDataStreamOutput.java
@@ -164,8 +164,7 @@ public BlockDataStreamOutput(
this.xceiverClientFactory = xceiverClientManager;
this.config = config;
this.isDatastreamPipelineMode = config.isDatastreamPipelineMode();
- this.putBlockWithoutRaft = config.isDatastreamPutBlockWithoutRaftEnabled()
- && allDatanodesSupportStreamPutBlock(pipeline);
+ this.putBlockWithoutRaft = isPutBlockWithoutRaft(config, pipeline);
this.syncSize = config.getDataStreamSyncSize();
this.blockID = new AtomicReference<>(blockID);
KeyValue keyValue =
@@ -203,6 +202,14 @@ public BlockDataStreamOutput(
metrics = XceiverClientManager.getXceiverClientMetrics();
}
+ /**
+ * @return whether the data streams on the given pipeline commit PutBlock
through the stream instead of the Raft log.
+ * Such a stream is opened with StreamInitWithPutBlock and is closed
without a Raft log entry.
+ */
+ public static boolean isPutBlockWithoutRaft(OzoneClientConfig config,
Pipeline pipeline) {
+ return config.isDatastreamPutBlockWithoutRaftEnabled() &&
allDatanodesSupportStreamPutBlock(pipeline);
+ }
+
private static boolean allDatanodesSupportStreamPutBlock(Pipeline pipeline) {
for (DatanodeDetails dn : pipeline.getNodes()) {
if (!STREAM_PUTBLOCK_WITHOUT_RAFT.isSupportedBy(dn.getCurrentVersion()))
{
diff --git
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientRatis.java
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientRatis.java
index 21fb7f55308..95524203644 100644
---
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientRatis.java
+++
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientRatis.java
@@ -21,6 +21,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
@@ -35,6 +36,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.ratis.RatisHelper;
import org.apache.hadoop.hdds.scm.pipeline.MockPipeline;
@@ -48,6 +50,8 @@
import org.apache.ratis.rpc.RpcType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.MockedStatic;
/**
@@ -67,13 +71,38 @@ class TestXceiverClientRatis {
void setUp() throws Exception {
when(raftClient.async()).thenReturn(async);
when(async.watch(INDEX,
ReplicationLevel.ALL_COMMITTED)).thenReturn(allCommitted);
+ client = connect(new OzoneConfiguration(), null);
+ }
+
+ private XceiverClientRatis connect(OzoneConfiguration conf,
AtomicReference<Boolean> skipSendForward)
+ throws Exception {
Pipeline pipeline = MockPipeline.createRatisPipeline();
- client = XceiverClientRatis.newXceiverClientRatis(pipeline, new
OzoneConfiguration());
+ XceiverClientRatis xceiverClient =
XceiverClientRatis.newXceiverClientRatis(pipeline, conf);
try (MockedStatic<RatisHelper> ratisHelper = mockStatic(RatisHelper.class,
CALLS_REAL_METHODS)) {
- ratisHelper.when(() -> RatisHelper.newRaftClient(any(RpcType.class),
any(Pipeline.class), any(), any(), any()))
- .thenReturn(raftClient);
- client.connect();
+ ratisHelper.when(() -> RatisHelper.newRaftClient(
+ any(RpcType.class), any(Pipeline.class), any(), any(), any(),
anyBoolean()))
+ .thenAnswer(invocation -> {
+ if (skipSendForward != null) {
+ skipSendForward.set(invocation.getArgument(5));
+ }
+ return raftClient;
+ });
+ xceiverClient.connect();
}
+ return xceiverClient;
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void dataStreamSkipsSendForwardOnlyWithPutBlockWithoutRaft(boolean
putBlockWithoutRaft) throws Exception {
+ OzoneConfiguration conf = new OzoneConfiguration();
+ OzoneClientConfig clientConfig = conf.getObject(OzoneClientConfig.class);
+ clientConfig.setDatastreamPutBlockWithoutRaftEnabled(putBlockWithoutRaft);
+ conf.setFromObject(clientConfig);
+ AtomicReference<Boolean> skipSendForward = new AtomicReference<>();
+
+ connect(conf, skipSendForward).close();
+ assertEquals(putBlockWithoutRaft, skipSendForward.get());
}
/** The client is closed (for example evicted and released) while the
ALL_COMMITTED watch is pending. */
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java
index eb858a74dbe..93b224646d8 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/ratis/RatisHelper.java
@@ -218,11 +218,20 @@ public static RaftGroup newRaftGroup(Pipeline pipeline) {
public static RaftClient newRaftClient(RpcType rpcType, Pipeline pipeline,
RetryPolicy retryPolicy, GrpcTlsConfig tlsConfig,
ConfigurationSource ozoneConfiguration) throws IOException {
+ return newRaftClient(rpcType, pipeline, retryPolicy, tlsConfig,
ozoneConfiguration, false);
+ }
+
+ /**
+ * Same as {@link #newRaftClient(RpcType, Pipeline, RetryPolicy,
GrpcTlsConfig, ConfigurationSource)}.
+ * @param skipSendForward whether the data streams of the client are closed
without a Raft log entry
+ */
+ public static RaftClient newRaftClient(RpcType rpcType, Pipeline pipeline,
RetryPolicy retryPolicy,
+ GrpcTlsConfig tlsConfig, ConfigurationSource ozoneConfiguration, boolean
skipSendForward) throws IOException {
return newRaftClient(rpcType,
toRaftPeerId(pipeline.getLeaderNode()),
toRaftPeer(pipeline.getClosestNode()),
newRaftGroup(pipeline.getId().getGroupId(),
- pipeline.getNodes()), retryPolicy, tlsConfig, ozoneConfiguration);
+ pipeline.getNodes()), retryPolicy, tlsConfig, ozoneConfiguration,
skipSendForward);
}
private static RpcType getRpcType(ConfigurationSource conf) {
@@ -263,6 +272,13 @@ public static RaftClient newRaftClient(RpcType rpcType,
RaftPeer leader,
private static RaftClient newRaftClient(RpcType rpcType, RaftPeerId leader,
RaftPeer primary, RaftGroup group, RetryPolicy retryPolicy,
GrpcTlsConfig tlsConfig, ConfigurationSource ozoneConfiguration) {
+ return newRaftClient(rpcType, leader, primary, group, retryPolicy,
tlsConfig, ozoneConfiguration, false);
+ }
+
+ @SuppressWarnings("checkstyle:ParameterNumber")
+ private static RaftClient newRaftClient(RpcType rpcType, RaftPeerId leader,
RaftPeer primary, RaftGroup group,
+ RetryPolicy retryPolicy, GrpcTlsConfig tlsConfig, ConfigurationSource
ozoneConfiguration,
+ boolean skipSendForward) {
if (LOG.isTraceEnabled()) {
LOG.trace("newRaftClient: {}, leader={}, group={}",
rpcType, leader, group);
@@ -272,6 +288,9 @@ private static RaftClient newRaftClient(RpcType rpcType,
RaftPeerId leader,
// Set the ratis client headers which are matching with regex.
createRaftClientProperties(ozoneConfiguration, properties);
+ if (skipSendForward) {
+ RaftConfigKeys.DataStream.setSkipSendForward(properties, true);
+ }
return RaftClient.newBuilder()
.setRaftGroup(group)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]