This is an automated email from the ASF dual-hosted git repository.
sreejasahithi 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 bdfef49ce69 HDDS-17445. Short-circuit GetBlock parks the opened block
file in a map shared by all requests instead of handing it to the request's own
context (#11745).
bdfef49ce69 is described below
commit bdfef49ce695d697e947e01660ba34121b19ab4c
Author: Siyao Meng <[email protected]>
AuthorDate: Tue Oct 27 03:39:08 2026 -0700
HDDS-17445. Short-circuit GetBlock parks the opened block file in a map
shared by all requests instead of handing it to the request's own context
(#11745).
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../ozone/container/common/interfaces/Handler.java | 4 --
.../common/transport/server/Receiver.java | 9 ++--
.../transport/server/ratis/DispatcherContext.java | 13 +++++
.../ozone/container/keyvalue/KeyValueHandler.java | 29 +++--------
.../container/common/impl/TestHddsDispatcher.java | 1 +
.../container/keyvalue/TestKeyValueHandler.java | 59 ++++++++++++++++++++--
.../TestKeyValueHandlerWithUnhealthyContainer.java | 4 +-
7 files changed, 83 insertions(+), 36 deletions(-)
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/interfaces/Handler.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/interfaces/Handler.java
index d6828423a36..5a4d84e7430 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/interfaces/Handler.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/interfaces/Handler.java
@@ -21,7 +21,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.RandomAccessFile;
import java.nio.file.Path;
import java.time.Clock;
import java.util.Collection;
@@ -284,9 +283,6 @@ public void setClusterID(String clusterID) {
this.clusterId = clusterID;
}
- public abstract RandomAccessFile getBlockFile(ContainerCommandRequestProto
request)
- throws IOException;
-
/**
* Copy container to the destination path.
*/
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/Receiver.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/Receiver.java
index 599be21e58c..281803246fc 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/Receiver.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/Receiver.java
@@ -52,7 +52,7 @@
import org.apache.hadoop.net.unix.DomainSocket;
import org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics;
import org.apache.hadoop.ozone.container.common.interfaces.ContainerDispatcher;
-import org.apache.hadoop.ozone.container.common.interfaces.Handler;
+import
org.apache.hadoop.ozone.container.common.transport.server.ratis.DispatcherContext;
import org.apache.hadoop.util.LimitInputStream;
import org.apache.ratis.thirdparty.com.google.protobuf.CodedInputStream;
import org.slf4j.Logger;
@@ -198,8 +198,10 @@ public void run() {
request.getTraceID());
try (Scope ignore = span.makeCurrent()) {
ContainerCommandResponseProto responseProto;
+ final DispatcherContext context =
+
DispatcherContext.newBuilder(DispatcherContext.Op.HANDLE_SHORT_CIRCUIT_READ).build();
if (isSupportedCmdType(type)) {
- responseProto = dispatcher.dispatch(request, null);
+ responseProto = dispatcher.dispatch(request, context);
} else {
responseProto = getContainerCommandResponse(request,
ContainerProtos.Result.UNSUPPORTED_REQUEST,
"This command is not supported through DomainSocket channel.")
@@ -207,8 +209,7 @@ public void run() {
}
if (responseProto.getResult() == ContainerProtos.Result.SUCCESS &&
type == ContainerProtos.Type.GetBlock) {
// get FileDescriptor
- Handler handler =
dispatcher.getHandler(ContainerProtos.ContainerType.KeyValueContainer);
- RandomAccessFile file = handler.getBlockFile(request);
+ RandomAccessFile file = context.getShortCircuitBlockFile();
Objects.requireNonNull(file,
"Failed to get block file for block " +
request.getGetBlock().getBlockID());
entry.setFile(file);
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/DispatcherContext.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/DispatcherContext.java
index 3f72b0cb15f..17ec28f9e28 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/DispatcherContext.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/DispatcherContext.java
@@ -17,6 +17,7 @@
package org.apache.hadoop.ozone.container.common.transport.server.ratis;
+import java.io.RandomAccessFile;
import java.util.Map;
import java.util.Objects;
import org.apache.hadoop.hdds.HDDSVersion;
@@ -60,6 +61,8 @@ public final class DispatcherContext {
private final boolean releaseSupported;
private volatile Runnable releaseMethod;
+ // block file opened for a short-circuit GetBlock; set and read on the same
Receiver task thread
+ private RandomAccessFile shortCircuitBlockFile;
private final long startTime = Time.monotonicNowNanos();
@@ -107,6 +110,7 @@ public enum Op {
HANDLE_WRITE_CHUNK,
HANDLE_GET_SMALL_FILE,
HANDLE_PUT_SMALL_FILE,
+ HANDLE_SHORT_CIRCUIT_READ,
READ_STATE_MACHINE_DATA,
WRITE_STATE_MACHINE_DATA,
@@ -196,6 +200,15 @@ public void release() {
}
}
+ public RandomAccessFile getShortCircuitBlockFile() {
+ return shortCircuitBlockFile;
+ }
+
+ public void setShortCircuitBlockFile(RandomAccessFile file) {
+ Preconditions.assertTrue(op == Op.HANDLE_SHORT_CIRCUIT_READ, "Unsupported
short-circuit block file");
+ this.shortCircuitBlockFile = file;
+ }
+
@Override
public String toString() {
return op + "-" + stage + TermIndex.valueOf(term, logIndex);
diff --git
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
index b851030399a..33985f93f94 100644
---
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
+++
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
@@ -61,7 +61,6 @@
import static
org.apache.hadoop.ozone.container.checksum.DNContainerOperationClient.createSingleNodePipeline;
import static
org.apache.hadoop.ozone.container.common.impl.ContainerLayoutVersion.DEFAULT_LAYOUT;
import static
org.apache.hadoop.ozone.container.common.impl.ContainerLayoutVersion.FILE_PER_BLOCK;
-import static
org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils.getBlockMapKey;
import static org.apache.ratis.util.Preconditions.assertTrue;
import com.google.common.annotations.VisibleForTesting;
@@ -92,7 +91,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -208,8 +206,6 @@ public class KeyValueHandler extends Handler {
private final Striped<Lock> containerCreationLocks;
private final ContainerChecksumTreeManager checksumManager;
private static FaultInjector injector;
- // map temporarily carries the RandomAccessFile for short-circuit read
requests
- private final Map<String, RandomAccessFile> blockFileMap = new
ConcurrentHashMap<>();
private OzoneContainer ozoneContainer;
private final Clock clock;
// Not final so tests can substitute a stubbed factory to drive
reconcileChunksPerBlock without a live peer.
@@ -359,7 +355,7 @@ static ContainerCommandResponseProto
dispatchRequest(KeyValueHandler handler,
case PutBlock:
return handler.handlePutBlock(request, kvContainer, dispatcherContext);
case GetBlock:
- return handler.handleGetBlock(request, kvContainer);
+ return handler.handleGetBlock(request, kvContainer, dispatcherContext);
case DeleteBlock:
return handler.handleDeleteBlock(request, kvContainer);
case ListBlock:
@@ -846,7 +842,7 @@ ContainerCommandResponseProto
handleGetContainerChecksumInfo(
* Handle Get Block operation. Calls BlockManager to process the request.
*/
ContainerCommandResponseProto handleGetBlock(
- ContainerCommandRequestProto request, KeyValueContainer kvContainer) {
+ ContainerCommandRequestProto request, KeyValueContainer kvContainer,
DispatcherContext dispatcherContext) {
if (!request.hasGetBlock()) {
if (LOG.isDebugEnabled()) {
@@ -863,15 +859,16 @@ ContainerCommandResponseProto handleGetBlock(
BlockID blockID = BlockID.getFromProtobuf(getBlock.getBlockID());
BlockUtils.verifyReplicaIdx(kvContainer, blockID);
responseData = blockManager.getBlock(kvContainer,
blockID).getProtoBufMessage();
- if (getBlock.hasRequestShortCircuitAccess() &&
getBlock.getRequestShortCircuitAccess()) {
+ // only the domain socket path can pass the opened file on, other
transports get the block data only
+ if (getBlock.hasRequestShortCircuitAccess() &&
getBlock.getRequestShortCircuitAccess()
+ && DispatcherContext.op(dispatcherContext) ==
DispatcherContext.Op.HANDLE_SHORT_CIRCUIT_READ) {
boolean domainSocketServerEnabled = ozoneContainer != null
&& ozoneContainer.getReadDomainSocketChannel() != null
&& ozoneContainer.getReadDomainSocketChannel().isStarted();
if (domainSocketServerEnabled) {
RandomAccessFile file = chunkManager.getShortCircuitFd(kvContainer,
blockID);
Preconditions.checkState(file != null);
- String mapKey = getBlockMapKey(request);
- blockFileMap.put(mapKey, file);
+ dispatcherContext.setShortCircuitBlockFile(file);
shortCircuitGranted = true;
}
}
@@ -891,20 +888,6 @@ ContainerCommandResponseProto handleGetBlock(
return getBlockDataResponse(request, responseData, shortCircuitGranted);
}
- @Override
- public RandomAccessFile getBlockFile(ContainerCommandRequestProto request)
throws IOException {
- if (request.getCmdType() != Type.GetBlock) {
- throw new StorageContainerException("Request type mismatch, expected " +
Type.GetBlock +
- ", received " + request.getCmdType(),
ContainerProtos.Result.MALFORMED_REQUEST);
- }
- String mapKey = getBlockMapKey(request);
- RandomAccessFile file = blockFileMap.remove(mapKey);
- if (LOG.isDebugEnabled()) {
- LOG.debug("File removed from blockFileMap for {}", mapKey);
- }
- return file;
- }
-
/**
* Handles GetCommittedBlockLength operation.
* Calls BlockManager to process the request.
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestHddsDispatcher.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestHddsDispatcher.java
index f6137361ca9..d1aed9459ba 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestHddsDispatcher.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestHddsDispatcher.java
@@ -923,6 +923,7 @@ public void verify(Token<?> token,
Op.HANDLE_PUT_SMALL_FILE,
Op.HANDLE_READ_CHUNK,
Op.HANDLE_WRITE_CHUNK,
+ Op.HANDLE_SHORT_CIRCUIT_READ,
Op.STREAM_INIT,
};
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandler.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandler.java
index 41e70f85335..a84b1a92d2b 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandler.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandler.java
@@ -292,7 +292,7 @@ public void testHandlerCommandHandling() throws Exception {
KeyValueHandler
.dispatchRequest(handler, getBlockRequest, container, null);
verify(handler, times(1)).handleGetBlock(
- any(ContainerCommandRequestProto.class), any());
+ any(ContainerCommandRequestProto.class), any(), any());
// Block Deletion is handled by BlockDeletingService and need not be
// tested here.
@@ -1358,10 +1358,11 @@ public void testGetBlockMetrics() throws Exception {
assertCounter("localBytesGetBlock", 0L, containerMetrics);
ContainerCommandRequestProto shortCircuitRequest =
newGetBlockRequest(containerID, blockID, true);
- response = getBlockDispatcher.dispatch(shortCircuitRequest, null);
+ DispatcherContext shortCircuitContext = newShortCircuitContext();
+ response = getBlockDispatcher.dispatch(shortCircuitRequest,
shortCircuitContext);
assertEquals(ContainerProtos.Result.SUCCESS, response.getResult());
assertTrue(response.getGetBlock().getShortCircuitAccessGranted());
- try (RandomAccessFile blockFile =
kvHandler.getBlockFile(shortCircuitRequest)) {
+ try (RandomAccessFile blockFile =
shortCircuitContext.getShortCircuitBlockFile()) {
assertNotNull(blockFile);
}
@@ -1375,6 +1376,58 @@ public void testGetBlockMetrics() throws Exception {
}
}
+ @Test
+ public void testShortCircuitGetBlockHandsFileToOwnContext() throws Exception
{
+ Path testDir =
Files.createTempDirectory("testShortCircuitGetBlockHandsFileToOwnContext");
+ try {
+ conf.set(OZONE_SCM_CONTAINER_LAYOUT_KEY,
ContainerLayoutVersion.FILE_PER_BLOCK.name());
+ HandlerWithVolumeSet handlerWithVolume =
createKeyValueHandlerWithVolumeSet(testDir,
+ mockOzoneContainerWithSCDomainSocket());
+ HddsDispatcher getBlockDispatcher =
createGetBlockDispatcher(handlerWithVolume);
+ long containerID = ContainerTestHelper.getTestContainerID();
+ KeyValueContainer container = createOpenContainer(containerID,
handlerWithVolume.getVolumeSet(),
+ handlerWithVolume.getContainerSet());
+ BlockID blockID = ContainerTestHelper.getTestBlockID(containerID);
+ writeTestBlockForGetBlock(handlerWithVolume.getHandler(), container,
blockID);
+ ContainerCommandRequestProto shortCircuitRequest =
newGetBlockRequest(containerID, blockID, true);
+
+ // Without a short-circuit context (gRPC) only the block data is
returned.
+ ContainerCommandResponseProto response =
getBlockDispatcher.dispatch(shortCircuitRequest, null);
+
assertThat(response.getResult()).isEqualTo(ContainerProtos.Result.SUCCESS);
+
assertThat(response.getGetBlock().getShortCircuitAccessGranted()).isFalse();
+ assertCounter("localBytesGetBlock", 0L,
getMetrics(ContainerMetrics.STORAGE_CONTAINER_METRICS));
+
+ // A short-circuit context without the access flag gets no file either.
+ DispatcherContext withoutFlag = newShortCircuitContext();
+ response = getBlockDispatcher.dispatch(newGetBlockRequest(containerID,
blockID, false), withoutFlag);
+
assertThat(response.getResult()).isEqualTo(ContainerProtos.Result.SUCCESS);
+
assertThat(response.getGetBlock().getShortCircuitAccessGranted()).isFalse();
+ assertThat(withoutFlag.getShortCircuitBlockFile()).isNull();
+
+ // Requests with identical ids each get their own file in their own
context.
+ DispatcherContext first = newShortCircuitContext();
+ DispatcherContext second = newShortCircuitContext();
+ ContainerCommandResponseProto firstResponse =
getBlockDispatcher.dispatch(shortCircuitRequest, first);
+ ContainerCommandResponseProto secondResponse =
getBlockDispatcher.dispatch(shortCircuitRequest, second);
+
assertThat(firstResponse.getGetBlock().getShortCircuitAccessGranted()).isTrue();
+
assertThat(secondResponse.getGetBlock().getShortCircuitAccessGranted()).isTrue();
+ try (RandomAccessFile firstFile = first.getShortCircuitBlockFile();
+ RandomAccessFile secondFile = second.getShortCircuitBlockFile()) {
+ assertThat(firstFile).isNotNull().isNotSameAs(secondFile);
+ assertThat(secondFile).isNotNull();
+ assertThat(firstFile.getFD().valid()).isTrue();
+ assertThat(secondFile.getFD().valid()).isTrue();
+ }
+ } finally {
+ FileUtils.deleteDirectory(testDir.toFile());
+ ContainerMetrics.remove();
+ }
+ }
+
+ private static DispatcherContext newShortCircuitContext() {
+ return
DispatcherContext.newBuilder(DispatcherContext.Op.HANDLE_SHORT_CIRCUIT_READ).build();
+ }
+
@Test
public void testReadBlockMetrics() throws Exception {
Path testDir = Files.createTempDirectory("testReadBlockMetrics");
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandlerWithUnhealthyContainer.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandlerWithUnhealthyContainer.java
index 358b56157fc..392e381c26b 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandlerWithUnhealthyContainer.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueHandlerWithUnhealthyContainer.java
@@ -107,7 +107,7 @@ public void testGetBlock() {
ContainerProtos.ContainerCommandResponseProto response =
handler.handleGetBlock(
getDummyCommandRequestProto(ContainerProtos.Type.GetBlock),
- container);
+ container, null);
assertEquals(UNKNOWN_BCSID, response.getResult());
}
@@ -125,7 +125,7 @@ public void
testGetBlockWithReplicaIndexMismatch(ClientVersion clientVersion, in
ContainerProtos.ContainerCommandResponseProto response =
handler.handleGetBlock(
getDummyCommandRequestProto(clientVersion,
ContainerProtos.Type.GetBlock, rid),
- container);
+ container, null);
assertEquals((replicaIndex > 0 && rid != 0 && rid != replicaIndex) ?
ContainerProtos.Result.CONTAINER_NOT_FOUND : UNKNOWN_BCSID,
response.getResult());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]