-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-17596. [ARR] RouterStoragePolicy supports asynchronous rpc. #6988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e7c516d
2af8558
9bc5c7f
f03962d
6a8eacf
bde6bf1
215e3b5
8d2879f
9f2d6d0
9a617e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * 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.hdfs.server.federation.router; | ||
|
|
||
| import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy; | ||
| import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation; | ||
| import org.apache.hadoop.hdfs.server.namenode.NameNode; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| import static org.apache.hadoop.hdfs.server.federation.router.async.AsyncUtil.asyncReturn; | ||
|
|
||
| public class RouterAsyncStoragePolicy extends RouterStoragePolicy { | ||
| /** RPC server to receive client calls. */ | ||
| private final RouterRpcServer rpcServer; | ||
| /** RPC clients to connect to the Namenodes. */ | ||
| private final RouterRpcClient rpcClient; | ||
|
|
||
| public RouterAsyncStoragePolicy(RouterRpcServer server) { | ||
| super(server); | ||
| this.rpcServer = server; | ||
| this.rpcClient = this.rpcServer.getRPCClient(); | ||
| } | ||
|
|
||
| @Override | ||
| public BlockStoragePolicy[] getStoragePolicies() throws IOException { | ||
| rpcServer.checkOperation(NameNode.OperationCategory.READ); | ||
|
|
||
| RemoteMethod method = new RemoteMethod("getStoragePolicies"); | ||
| return rpcServer.invokeAtAvailableNsAsync(method, BlockStoragePolicy[].class); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,13 @@ | |
| import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_FEDERATION_RENAME_OPTION; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_FEDERATION_RENAME_OPTION_DEFAULT; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.RouterFederationRename.RouterRenameOption; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.RouterRpcClient.isExpectedClass; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.async.AsyncUtil.asyncApply; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.async.AsyncUtil.asyncCatch; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.async.AsyncUtil.asyncComplete; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.async.AsyncUtil.asyncForEach; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.async.AsyncUtil.asyncReturn; | ||
| import static org.apache.hadoop.hdfs.server.federation.router.async.AsyncUtil.asyncTry; | ||
| import static org.apache.hadoop.tools.fedbalance.FedBalanceConfigs.SCHEDULER_JOURNAL_URI; | ||
|
|
||
| import java.io.FileNotFoundException; | ||
|
|
@@ -49,6 +56,7 @@ | |
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.EnumSet; | ||
| import java.util.Iterator; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
|
|
@@ -68,6 +76,7 @@ | |
| import org.apache.hadoop.hdfs.HAUtil; | ||
| import org.apache.hadoop.hdfs.protocol.UnresolvedPathException; | ||
| import org.apache.hadoop.hdfs.protocolPB.AsyncRpcProtocolPBUtil; | ||
| import org.apache.hadoop.hdfs.server.federation.router.async.AsyncCatchFunction; | ||
| import org.apache.hadoop.thirdparty.com.google.common.cache.CacheBuilder; | ||
| import org.apache.hadoop.thirdparty.com.google.common.cache.CacheLoader; | ||
| import org.apache.hadoop.thirdparty.com.google.common.cache.LoadingCache; | ||
|
|
@@ -791,6 +800,36 @@ <T> T invokeAtAvailableNs(RemoteMethod method, Class<T> clazz) | |
| return invokeOnNs(method, clazz, io, nss); | ||
| } | ||
|
|
||
| <T> T invokeAtAvailableNsAsync(RemoteMethod method, Class<T> clazz) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about to split this changes to separate PR which is common update and not relate with StoragePolicy only. Others look good to me. Thanks.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Hexiaoqiao @KeeProMise Agree with you, sir. This PR depends on #7108 |
||
| throws IOException { | ||
| String nsId = subclusterResolver.getDefaultNamespace(); | ||
| // If default Ns is not present return result from first namespace. | ||
| Set<FederationNamespaceInfo> nss = namenodeResolver.getNamespaces(); | ||
| // If no namespace is available, throw IOException. | ||
| IOException io = new IOException("No namespace available."); | ||
|
|
||
| asyncComplete(null); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @hfutatzhanghb IMO, asyncComplete(null) is not needed in this place.
hfutatzhanghb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!nsId.isEmpty()) { | ||
| asyncTry(() -> { | ||
| rpcClient.invokeSingle(nsId, method, clazz); | ||
|
||
| }); | ||
|
|
||
| asyncCatch((AsyncCatchFunction<T, IOException>)(res, ioe) -> { | ||
| if (!clientProto.isUnavailableSubclusterException(ioe)) { | ||
| LOG.debug("{} exception cannot be retried", | ||
| ioe.getClass().getSimpleName()); | ||
| throw ioe; | ||
| } | ||
| nss.removeIf(n -> n.getNameserviceId().equals(nsId)); | ||
| invokeOnNs(method, clazz, io, nss); | ||
hfutatzhanghb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, IOException.class); | ||
| } else { | ||
| // If not have default NS. | ||
| invokeOnNsAsync(method, clazz, io, nss); | ||
| } | ||
| return asyncReturn(clazz); | ||
| } | ||
|
|
||
| /** | ||
| * Invoke the method sequentially on available namespaces, | ||
| * throw no namespace available exception, if no namespaces are available. | ||
|
|
@@ -824,6 +863,49 @@ <T> T invokeOnNs(RemoteMethod method, Class<T> clazz, IOException ioe, | |
| throw ioe; | ||
| } | ||
|
|
||
| <T> T invokeOnNsAsync(RemoteMethod method, Class<T> clazz, IOException ioe, | ||
| Set<FederationNamespaceInfo> nss) throws IOException { | ||
| if (nss.isEmpty()) { | ||
| throw ioe; | ||
| } | ||
|
|
||
| asyncComplete(null); | ||
hfutatzhanghb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Iterator<FederationNamespaceInfo> nsIterator = nss.iterator(); | ||
| asyncForEach(nsIterator, (foreach, fnInfo) -> { | ||
| String nsId = fnInfo.getNameserviceId(); | ||
| LOG.debug("Invoking {} on namespace {}", method, nsId); | ||
| asyncTry(() -> { | ||
| rpcClient.invokeSingle(nsId, method, clazz); | ||
|
||
| asyncApply(result -> { | ||
| if (result != null && isExpectedClass(clazz, result)) { | ||
| foreach.breakNow(); | ||
| return result; | ||
| } | ||
| return null; | ||
| }); | ||
| }); | ||
|
|
||
| asyncCatch((AsyncCatchFunction<T, IOException>)(ret, ex) -> { | ||
|
||
| LOG.debug("Failed to invoke {} on namespace {}", method, nsId, ex); | ||
| // Ignore the exception and try on other namespace, if the tried | ||
| // namespace is unavailable, else throw the received exception. | ||
| if (!clientProto.isUnavailableSubclusterException(ex)) { | ||
| throw ex; | ||
| } | ||
| }, IOException.class); | ||
| }); | ||
|
|
||
| asyncApply(obj -> { | ||
| if (obj == null) { | ||
| // Couldn't get a response from any of the namespace, throw ioe. | ||
| throw ioe; | ||
| } | ||
| return obj; | ||
| }); | ||
|
|
||
| return asyncReturn(clazz); | ||
| } | ||
|
|
||
| @Override // ClientProtocol | ||
| public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer) | ||
| throws IOException { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.