Skip to content

Commit 4f62751

Browse files
committed
Refactor specifiedReadConsistency
1 parent 5e58306 commit 4f62751

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_NODES_KEY;
3939
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_PORT_DEFAULT;
4040
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY;
41+
import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ReadConsistencyProto.READ_CONSISTENCY_UNSPECIFIED;
4142

4243
import com.google.common.annotations.VisibleForTesting;
4344
import com.google.common.base.Preconditions;
@@ -1149,4 +1150,10 @@ public static void resolveOmHost(String omHost, int omPort)
11491150
throw e;
11501151
}
11511152
}
1153+
1154+
public static boolean specifiedReadConsistency(OMRequest request) {
1155+
return request.hasReadConsistencyHint()
1156+
&& request.getReadConsistencyHint().hasReadConsistency()
1157+
&& request.getReadConsistencyHint().getReadConsistency() != READ_CONSISTENCY_UNSPECIFIED;
1158+
}
11521159
}

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient;
5757
import org.apache.hadoop.hdds.tracing.TracingUtil;
5858
import org.apache.hadoop.ipc_.ProtobufRpcEngine.Server;
59+
import org.apache.hadoop.ozone.OmUtils;
5960
import org.apache.hadoop.ozone.om.OMConfigKeys;
6061
import org.apache.hadoop.ozone.om.OMPerformanceMetrics;
6162
import org.apache.hadoop.ozone.om.OzoneManager;
@@ -69,7 +70,6 @@
6970
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
7071
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
7172
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
72-
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ReadConsistencyProto;
7373
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Status;
7474
import org.apache.ratis.conf.Parameters;
7575
import org.apache.ratis.conf.RaftProperties;
@@ -521,8 +521,7 @@ private RaftClientRequest createRaftRequestImpl(OMRequest omRequest, boolean isW
521521
}
522522

523523
private static RaftClientRequest.Type getRaftReadRequestType(OMRequest omRequest) {
524-
if (!omRequest.hasReadConsistencyHint() || !omRequest.getReadConsistencyHint().hasReadConsistency() ||
525-
omRequest.getReadConsistencyHint().getReadConsistency() == ReadConsistencyProto.READ_CONSISTENCY_UNSPECIFIED) {
524+
if (!OmUtils.specifiedReadConsistency(omRequest)) {
526525
// If there is no consistency hint, we simply follow the Raft server read option
527526
return RaftClientRequest.readRequestType();
528527
}

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerProtocolServerSideTranslatorPB.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer.RaftServerStatus.LEADER_AND_READY;
2121
import static org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer.RaftServerStatus.NOT_LEADER;
2222
import static org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerRatisUtils.createErrorResponse;
23-
import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ReadConsistencyProto.READ_CONSISTENCY_UNSPECIFIED;
2423
import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type.PrepareStatus;
2524
import static org.apache.hadoop.ozone.util.MetricUtil.captureLatencyNs;
2625

@@ -229,8 +228,7 @@ private OMResponse submitReadRequestToOM(OMRequest request)
229228
return handler.handleReadRequest(request);
230229
}
231230

232-
if (!request.hasReadConsistencyHint() || !request.getReadConsistencyHint().hasReadConsistency() ||
233-
request.getReadConsistencyHint().getReadConsistency() == READ_CONSISTENCY_UNSPECIFIED) {
231+
if (!OmUtils.specifiedReadConsistency(request)) {
234232
return submitReadRequestToOmWithoutHint(request);
235233
} else {
236234
// If read consistency hint is specified, we should try to respect it although

0 commit comments

Comments
 (0)