|
@@ -58,6 +58,7 @@ import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.crypto.CryptoProtocolVersion;
|
|
|
import org.apache.hadoop.fs.ContentSummary;
|
|
|
import org.apache.hadoop.fs.CreateFlag;
|
|
|
+import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
import org.apache.hadoop.fs.FileContext;
|
|
|
import org.apache.hadoop.fs.FileStatus;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
@@ -107,6 +108,7 @@ import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.NamenodeCon
|
|
|
import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.RouterContext;
|
|
|
import org.apache.hadoop.hdfs.server.federation.MockResolver;
|
|
|
import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
|
|
|
+import org.apache.hadoop.hdfs.server.federation.metrics.FederationRPCMetrics;
|
|
|
import org.apache.hadoop.hdfs.server.federation.metrics.NamenodeBeanMetrics;
|
|
|
import org.apache.hadoop.hdfs.server.federation.metrics.RBFMetrics;
|
|
|
import org.apache.hadoop.hdfs.server.federation.resolver.FileSubclusterResolver;
|
|
@@ -1450,6 +1452,101 @@ public class TestRouterRpc {
|
|
|
assertEquals(nnSuccess, routerSuccess);
|
|
|
}
|
|
|
|
|
|
+ private void testRenewLeaseInternal(DistributedFileSystem dfs,
|
|
|
+ FederationRPCMetrics rpcMetrics, Path testPath, boolean createFlag)
|
|
|
+ throws Exception {
|
|
|
+ FSDataOutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ if (createFlag) {
|
|
|
+ outputStream = dfs.create(testPath);
|
|
|
+ } else {
|
|
|
+ outputStream = dfs.append(testPath);
|
|
|
+ }
|
|
|
+ outputStream.write("hello world. \n".getBytes());
|
|
|
+ long proxyOpBeforeRenewLease = rpcMetrics.getProxyOps();
|
|
|
+ assertTrue(dfs.getClient().renewLease());
|
|
|
+ long proxyOpAfterRenewLease = rpcMetrics.getProxyOps();
|
|
|
+ assertEquals((proxyOpBeforeRenewLease + 1), proxyOpAfterRenewLease);
|
|
|
+ } finally {
|
|
|
+ if (outputStream != null) {
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testRenewLeaseForECFile() throws Exception {
|
|
|
+ String ecName = "RS-6-3-1024k";
|
|
|
+ FederationRPCMetrics metrics = router.getRouterRpcServer().getRPCMetrics();
|
|
|
+ // Install a mount point to a different path to check
|
|
|
+ MockResolver resolver =
|
|
|
+ (MockResolver)router.getRouter().getSubclusterResolver();
|
|
|
+ String ns0 = cluster.getNameservices().get(0);
|
|
|
+ resolver.addLocation("/testRenewLease0", ns0, "/testRenewLease0");
|
|
|
+
|
|
|
+ // Stop LeaseRenewer
|
|
|
+ DistributedFileSystem routerDFS = (DistributedFileSystem) routerFS;
|
|
|
+ routerDFS.getClient().getLeaseRenewer().interruptAndJoin();
|
|
|
+
|
|
|
+ Path testECPath = new Path("/testRenewLease0/ecDirectory/test_ec.txt");
|
|
|
+ routerDFS.mkdirs(testECPath.getParent());
|
|
|
+ routerDFS.setErasureCodingPolicy(
|
|
|
+ testECPath.getParent(), ecName);
|
|
|
+ testRenewLeaseInternal(routerDFS, metrics, testECPath, true);
|
|
|
+
|
|
|
+ ErasureCodingPolicy ecPolicy = routerDFS.getErasureCodingPolicy(testECPath);
|
|
|
+ assertNotNull(ecPolicy);
|
|
|
+ assertEquals(ecName, ecPolicy.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testRenewLeaseForReplicaFile() throws Exception {
|
|
|
+ FederationRPCMetrics metrics = router.getRouterRpcServer().getRPCMetrics();
|
|
|
+ // Install a mount point to a different path to check
|
|
|
+ MockResolver resolver =
|
|
|
+ (MockResolver)router.getRouter().getSubclusterResolver();
|
|
|
+ String ns0 = cluster.getNameservices().get(0);
|
|
|
+ resolver.addLocation("/testRenewLease0", ns0, "/testRenewLease0");
|
|
|
+
|
|
|
+ // Stop LeaseRenewer
|
|
|
+ DistributedFileSystem routerDFS = (DistributedFileSystem) routerFS;
|
|
|
+ routerDFS.getClient().getLeaseRenewer().interruptAndJoin();
|
|
|
+
|
|
|
+ // Test Replica File
|
|
|
+ Path testPath = new Path("/testRenewLease0/test_replica.txt");
|
|
|
+ testRenewLeaseInternal(routerDFS, metrics, testPath, true);
|
|
|
+ testRenewLeaseInternal(routerDFS, metrics, testPath, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testRenewLeaseWithMultiStream() throws Exception {
|
|
|
+ FederationRPCMetrics metrics = router.getRouterRpcServer().getRPCMetrics();
|
|
|
+ // Install a mount point to a different path to check
|
|
|
+ MockResolver resolver =
|
|
|
+ (MockResolver)router.getRouter().getSubclusterResolver();
|
|
|
+ String ns0 = cluster.getNameservices().get(0);
|
|
|
+ String ns1 = cluster.getNameservices().get(1);
|
|
|
+ resolver.addLocation("/testRenewLease0", ns0, "/testRenewLease0");
|
|
|
+ resolver.addLocation("/testRenewLease1", ns1, "/testRenewLease1");
|
|
|
+
|
|
|
+ // Stop LeaseRenewer
|
|
|
+ DistributedFileSystem routerDFS = (DistributedFileSystem) routerFS;
|
|
|
+ routerDFS.getClient().getLeaseRenewer().interruptAndJoin();
|
|
|
+
|
|
|
+ Path newTestPath0 = new Path("/testRenewLease0/test1.txt");
|
|
|
+ Path newTestPath1 = new Path("/testRenewLease1/test1.txt");
|
|
|
+ try (FSDataOutputStream outStream1 = routerDFS.create(newTestPath0);
|
|
|
+ FSDataOutputStream outStream2 = routerDFS.create(newTestPath1)) {
|
|
|
+ outStream1.write("hello world \n".getBytes());
|
|
|
+ outStream2.write("hello world \n".getBytes());
|
|
|
+ long proxyOpBeforeRenewLease2 = metrics.getProxyOps();
|
|
|
+ assertTrue(routerDFS.getClient().renewLease());
|
|
|
+ long proxyOpAfterRenewLease2 = metrics.getProxyOps();
|
|
|
+ assertEquals((proxyOpBeforeRenewLease2 + 2), proxyOpAfterRenewLease2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testProxyExceptionMessages() throws IOException {
|
|
|
|