-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HDFS-17733. [ARR] Optimize isMultiDestDirectory method using AsyncUtil class #7415
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
83847fe
HDFS-17733. [ARR] Optimize isMultiDestDirectory method using AsyncUti…
hfutatzhanghb a166979
fix checkstyle.
hfutatzhanghb d96666e
fix checkstyle
hfutatzhanghb b4ffc60
remove useless asyncComplete.
hfutatzhanghb 17644dc
fix unit test.
hfutatzhanghb 044a035
remove java doc.
hfutatzhanghb 3fe735a
fix doc.
hfutatzhanghb b918eeb
fix doc.
hfutatzhanghb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
...rver/federation/router/async/TestRouterAsyncRPCMultipleDestinationMountTableResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/** | ||
* 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.async; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FsServerDefaults; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.hdfs.DFSConfigKeys; | ||
import org.apache.hadoop.hdfs.DistributedFileSystem; | ||
import org.apache.hadoop.hdfs.MiniDFSCluster; | ||
import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder; | ||
import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster; | ||
import org.apache.hadoop.hdfs.server.federation.resolver.MountTableResolver; | ||
import org.apache.hadoop.hdfs.server.federation.resolver.MultipleDestinationMountTableResolver; | ||
import org.apache.hadoop.hdfs.server.federation.resolver.order.DestinationOrder; | ||
import org.apache.hadoop.hdfs.server.federation.router.RemoteMethod; | ||
import org.apache.hadoop.hdfs.server.federation.router.RouterClientProtocol; | ||
import org.apache.hadoop.hdfs.server.federation.router.RouterQuotaUsage; | ||
import org.apache.hadoop.hdfs.server.federation.router.TestRouterRPCMultipleDestinationMountTableResolver; | ||
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_ASYNC_RPC_ENABLE_KEY; | ||
import static org.apache.hadoop.hdfs.server.federation.router.async.utils.AsyncUtil.syncReturn; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Tests router async rpc with multiple destination mount table resolver. | ||
*/ | ||
public class TestRouterAsyncRPCMultipleDestinationMountTableResolver extends | ||
TestRouterRPCMultipleDestinationMountTableResolver { | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
|
||
// Build and start a federated cluster. | ||
cluster = new StateStoreDFSCluster(false, 3, | ||
MultipleDestinationMountTableResolver.class); | ||
Configuration routerConf = | ||
new RouterConfigBuilder().stateStore().admin().quota().rpc().build(); | ||
routerConf.setBoolean(DFS_ROUTER_ASYNC_RPC_ENABLE_KEY, true); | ||
|
||
Configuration hdfsConf = new Configuration(false); | ||
hdfsConf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true); | ||
|
||
cluster.addRouterOverrides(routerConf); | ||
cluster.addNamenodeOverrides(hdfsConf); | ||
cluster.startCluster(); | ||
cluster.startRouters(); | ||
cluster.waitClusterUp(); | ||
|
||
routerContext = cluster.getRandomRouter(); | ||
resolver = | ||
(MountTableResolver) routerContext.getRouter().getSubclusterResolver(); | ||
nnFs0 = (DistributedFileSystem) cluster | ||
.getNamenode(cluster.getNameservices().get(0), null).getFileSystem(); | ||
nnFs1 = (DistributedFileSystem) cluster | ||
.getNamenode(cluster.getNameservices().get(1), null).getFileSystem(); | ||
nnFs2 = (DistributedFileSystem) cluster | ||
.getNamenode(cluster.getNameservices().get(2), null).getFileSystem(); | ||
routerFs = (DistributedFileSystem) routerContext.getFileSystem(); | ||
rpcServer =routerContext.getRouter().getRpcServer(); | ||
} | ||
|
||
@Override | ||
hfutatzhanghb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Test | ||
public void testInvokeAtAvailableNs() throws IOException { | ||
// Create a mount point with multiple destinations. | ||
Path path = new Path("/testInvokeAtAvailableNs"); | ||
Map<String, String> destMap = new HashMap<>(); | ||
destMap.put("ns0", "/testInvokeAtAvailableNs"); | ||
destMap.put("ns1", "/testInvokeAtAvailableNs"); | ||
nnFs0.mkdirs(path); | ||
nnFs1.mkdirs(path); | ||
MountTable addEntry = | ||
MountTable.newInstance("/testInvokeAtAvailableNs", destMap); | ||
addEntry.setQuota(new RouterQuotaUsage.Builder().build()); | ||
addEntry.setDestOrder(DestinationOrder.RANDOM); | ||
addEntry.setFaultTolerant(true); | ||
assertTrue(addMountTable(addEntry)); | ||
|
||
// Make one subcluster unavailable. | ||
MiniDFSCluster dfsCluster = cluster.getCluster(); | ||
dfsCluster.shutdownNameNode(0); | ||
dfsCluster.shutdownNameNode(1); | ||
try { | ||
// Verify that #invokeAtAvailableNs works by calling #getServerDefaults. | ||
RemoteMethod method = new RemoteMethod("getServerDefaults"); | ||
FsServerDefaults serverDefaults = null; | ||
rpcServer.invokeAtAvailableNsAsync(method, FsServerDefaults.class); | ||
try { | ||
serverDefaults = syncReturn(FsServerDefaults.class); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
assertNotNull(serverDefaults); | ||
} finally { | ||
dfsCluster.restartNameNode(0); | ||
dfsCluster.restartNameNode(1); | ||
} | ||
} | ||
|
||
@Override | ||
@Test | ||
public void testIsMultiDestDir() throws Exception { | ||
RouterClientProtocol client = | ||
routerContext.getRouter().getRpcServer().getClientProtocolModule(); | ||
setupOrderMountPath(DestinationOrder.HASH_ALL); | ||
// Should be true only for directory and false for all other cases. | ||
client.isMultiDestDirectory("/mount/dir"); | ||
assertTrue(syncReturn(boolean.class)); | ||
client.isMultiDestDirectory("/mount/nodir"); | ||
assertFalse(syncReturn(boolean.class)); | ||
client.isMultiDestDirectory("/mount/dir/file"); | ||
assertFalse(syncReturn(boolean.class)); | ||
routerFs.createSymlink(new Path("/mount/dir/file"), | ||
new Path("/mount/dir/link"), true); | ||
client.isMultiDestDirectory("/mount/dir/link"); | ||
assertFalse(syncReturn(boolean.class)); | ||
routerFs.createSymlink(new Path("/mount/dir/dir"), | ||
new Path("/mount/dir/linkDir"), true); | ||
client.isMultiDestDirectory("/mount/dir/linkDir"); | ||
assertFalse(syncReturn(boolean.class)); | ||
resetTestEnvironment(); | ||
// Test single directory destination. Should be false for the directory. | ||
setupOrderMountPath(DestinationOrder.HASH); | ||
client.isMultiDestDirectory("/mount/dir"); | ||
assertFalse(syncReturn(boolean.class)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.