ivandika3 commented on code in PR #11252:
URL: https://github.com/apache/ozone/pull/11252#discussion_r4162493616


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/ReadConsistencyContext.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.s3.util;
+
+import static 
org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_ARGUMENT;
+import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError;
+import static 
org.apache.hadoop.ozone.s3.util.S3Consts.LOCAL_LEASE_LOG_LIMIT_HEADER;
+import static org.apache.hadoop.ozone.s3.util.S3Consts.READ_CONSISTENCY_HEADER;
+
+import java.util.Locale;
+import javax.ws.rs.core.HttpHeaders;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.ozone.om.helpers.ReadConsistency;
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+
+/**
+ * Read consistency values parsed from S3 request headers.
+ */
+public final class ReadConsistencyContext {
+  private final ReadConsistency readConsistency;
+  private final Long localLeaseLogLimit;
+
+  private ReadConsistencyContext(ReadConsistency readConsistency,
+      Long localLeaseLogLimit) {
+    this.readConsistency = readConsistency;
+    this.localLeaseLogLimit = localLeaseLogLimit;
+  }
+
+  public static ReadConsistencyContext fromHeaders(HttpHeaders headers) {
+    return fromHeaders(headers.getHeaderString(READ_CONSISTENCY_HEADER),
+        headers.getHeaderString(LOCAL_LEASE_LOG_LIMIT_HEADER));
+  }
+
+  public static ReadConsistencyContext fromHeaders(String 
readConsistencyHeader,
+      String localLeaseLogLimitHeader) {
+    ReadConsistency readConsistency = 
parseReadConsistency(readConsistencyHeader);
+    Long localLeaseLogLimit = 
parseLocalLeaseLogLimit(localLeaseLogLimitHeader);
+    if (readConsistency != ReadConsistency.LOCAL_LEASE
+        && localLeaseLogLimit != null) {
+      OS3Exception ex = newError(INVALID_ARGUMENT, READ_CONSISTENCY_HEADER);
+      ex.setErrorMessage("Local lease context requires read consistency: 
follower-stale");
+      throw ex;
+    }
+    return new ReadConsistencyContext(readConsistency, localLeaseLogLimit);
+  }
+
+  public ReadConsistency getReadConsistency() {
+    return readConsistency;
+  }
+
+  public Long getLocalLeaseLogLimit() {
+    return localLeaseLogLimit;
+  }
+
+  private static ReadConsistency parseReadConsistency(String header) {
+    if (StringUtils.isBlank(header)) {
+      return null;
+    }
+    switch (header.trim().toLowerCase(Locale.ROOT)) {
+    case "follower-stale":
+      return ReadConsistency.LOCAL_LEASE;
+    case "leader-only":
+      return ReadConsistency.LINEARIZABLE_LEADER_ONLY;
+    case "follower-linearizable":

Review Comment:
   Sure, updated.



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/ha/HadoopRpcOMFollowerReadFailoverProxyProvider.java:
##########
@@ -117,7 +111,8 @@ public HadoopRpcOMFollowerReadFailoverProxyProvider(
         .map(a -> a.proxyInfo)
         .reduce((a, b) -> a + ", " + b).orElse("") + "]";
     combinedProxy = new ProxyInfo<>(new FollowerReadProxy(), combinedInfo);
-    this.useFollowerRead = useFollowerRead;
+    this.omServiceSupportsFollowerRead = true;

Review Comment:
   Added a comment for this. The idea is that the client doesn't know that the 
OM actually supports follower read. Therefore, instead of asking the OM for the 
follower read capability, we optimisitcally assume that OM service supports 
follower read and only disable this if proven otherwise (i.e. OM throws 
OMNotLeaderException).
   
   Normally, client should know whether OM service supports follower read and 
set the configuration accordingly.



##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/GrpcOmTransport.java:
##########
@@ -324,6 +334,25 @@ private synchronized String getCurrentFollowerReadNodeId() 
{
         .get(currentFollowerReadIndex);
   }
 
+  private synchronized String getCurrentFollowerReadNodeId(
+      ReadConsistency readConsistency) {
+    String nodeId = getCurrentFollowerReadNodeId();
+    if (readConsistency != ReadConsistency.LOCAL_LEASE) {
+      return nodeId;
+    }
+
+    String leaderNodeId = omFailoverProxyProvider.getCurrentProxyOMNodeId();
+    for (int i = 0; i < 
omFailoverProxyProvider.getOMProxyMap().getNodeIds().size();
+         i++) {
+      if (!nodeId.equals(leaderNodeId)) {
+        return nodeId;
+      }
+      changeFollowerReadProxy(nodeId);
+      nodeId = getCurrentFollowerReadNodeId();
+    }
+    return null;
+  }

Review Comment:
   Sure, renamed the method to `selectFollowerReadnodeId`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to