ivandika3 commented on code in PR #9641: URL: https://github.com/apache/ozone/pull/9641#discussion_r2719263244
########## hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/ha/HadoopRpcOMFollowerReadFailoverProxyProvider.java: ########## @@ -0,0 +1,414 @@ +/* + * 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.om.ha; + +import static org.apache.hadoop.ozone.om.ha.OMFailoverProxyProviderBase.getLeaderNotReadyException; +import static org.apache.hadoop.ozone.om.ha.OMFailoverProxyProviderBase.getNotLeaderException; + +import com.google.common.annotations.VisibleForTesting; +import com.google.protobuf.Message; +import com.google.protobuf.RpcController; +import com.google.protobuf.ServiceException; +import java.io.IOException; +import java.io.InterruptedIOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.List; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.io.retry.FailoverProxyProvider; +import org.apache.hadoop.io.retry.RetryPolicy; +import org.apache.hadoop.ipc_.Client.ConnectionId; +import org.apache.hadoop.ipc_.RPC; +import org.apache.hadoop.ipc_.RpcInvocationHandler; +import org.apache.hadoop.ipc_.RpcNoSuchProtocolException; +import org.apache.hadoop.ozone.OmUtils; +import org.apache.hadoop.ozone.om.exceptions.OMLeaderNotReadyException; +import org.apache.hadoop.ozone.om.exceptions.OMNotLeaderException; +import org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolPB; +import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A {@link org.apache.hadoop.io.retry.FailoverProxyProvider} implementation + * that supports reading from follower OM(s) (i.e. non-leader OMs also includes + * OM listeners). + * <p> + * This constructs a wrapper proxy might send the read request to follower + * OM(s), if follower read is enabled. It will try to send read requests + * to the first OM node. If RPC failed, it will try to failover to the next OM node. + * It will fail back to the leader OM after it has exhausted all the OMs. + * TODO: Currently the logic does not prioritize forwarding to followers since + * it requires an extra RPC latency to check the OM role info. + * In the future, we can try to try to pick the followers before forwarding + * the request to the leader (similar to ObserverReadProxyProvider). + * <p> + * Read and write requests will still be sent to leader OM if reading from + * follower is disabled. + */ +public class HadoopRpcOMFollowerReadFailoverProxyProvider<T> implements FailoverProxyProvider<T> { + @VisibleForTesting + public static final Logger LOG = LoggerFactory.getLogger(HadoopRpcOMFollowerReadFailoverProxyProvider.class); + + private final Class<T> protocolClass; + + /** The inner proxy provider used for leader-based failover. */ + private final HadoopRpcOMFailoverProxyProvider<T> failoverProxy; + + /** The combined proxy which redirects to other proxies as necessary. */ + private final ProxyInfo<T> combinedProxy; + + /** + * Whether reading from follower is enabled. If this is false, all read + * requests will still go to OM leader. + */ + private volatile boolean followerReadEnabled; + + /** + * The current index of the underlying leader-based proxy provider's omNodesInOrder currently being used. + * Should only be accessed in synchronized methods. + */ + private int currentIndex = -1; + + /** + * The proxy currently being used to send the read request. + * Should only be accessed in synchronized methods. + */ + private OMProxyInfo<T> currentProxy; + + /** The last proxy that has been used. Only used for testing. */ + private volatile OMProxyInfo<T> lastProxy = null; + + public HadoopRpcOMFollowerReadFailoverProxyProvider( + ConfigurationSource configuration, UserGroupInformation ugi, String omServiceId, Class<T> protocol) + throws IOException { + this(omServiceId, protocol, + new HadoopRpcOMFailoverProxyProvider<>(configuration, ugi, omServiceId, protocol)); + } + + @SuppressWarnings("unchecked") + public HadoopRpcOMFollowerReadFailoverProxyProvider(String omServiceId, Class<T> protocol, Review Comment: Ok I understood. Since `HadoopRpcOMFollowerReadFailoverProxyProvider` is handles only `submitRequest` from `OzoneManagerProtocolPB`, we should simply make it to only handle `OzoneManagerProtocolPB`. -- 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]
