Skip to content

Commit 55a2ae8

Browse files
HDFS-15450. Fix NN trash emptier to work if ViewFSOveroadScheme enabled. Contributed by Uma Maheswara Rao G.
1 parent d20109c commit 55a2ae8

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.hadoop.hdfs.DFSConfigKeys;
4242
import org.apache.hadoop.hdfs.DFSUtil;
4343
import org.apache.hadoop.hdfs.DFSUtilClient;
44+
import org.apache.hadoop.hdfs.DistributedFileSystem;
4445
import org.apache.hadoop.hdfs.HAUtil;
4546
import org.apache.hadoop.hdfs.HdfsConfiguration;
4647
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
@@ -384,6 +385,7 @@ public long getProtocolVersion(String protocol,
384385
*/
385386
@Deprecated
386387
public static final int DEFAULT_PORT = DFS_NAMENODE_RPC_PORT_DEFAULT;
388+
public static final String FS_HDFS_IMPL_KEY = "fs.hdfs.impl";
387389
public static final Logger LOG =
388390
LoggerFactory.getLogger(NameNode.class.getName());
389391
public static final Logger stateChangeLog =
@@ -725,6 +727,11 @@ protected void initialize(Configuration conf) throws IOException {
725727
intervals);
726728
}
727729
}
730+
// Currently NN uses FileSystem.get to initialize DFS in startTrashEmptier.
731+
// If fs.hdfs.impl was overridden by core-site.xml, we may get other
732+
// filesystem. To make sure we get DFS, we are setting fs.hdfs.impl to DFS.
733+
// HDFS-15450
734+
conf.set(FS_HDFS_IMPL_KEY, DistributedFileSystem.class.getName());
728735

729736
UserGroupInformation.setConfiguration(conf);
730737
loginAsNameNodeUser(conf);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.fs.viewfs;
19+
20+
import org.apache.hadoop.conf.Configuration;
21+
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
22+
import org.apache.hadoop.fs.FsConstants;
23+
import org.apache.hadoop.hdfs.DFSConfigKeys;
24+
import org.apache.hadoop.hdfs.DistributedFileSystem;
25+
import org.apache.hadoop.hdfs.MiniDFSCluster;
26+
import org.apache.hadoop.hdfs.MiniDFSNNTopology;
27+
import org.junit.After;
28+
import org.junit.BeforeClass;
29+
import org.junit.Test;
30+
31+
/**
32+
* Tests that the NN startup is successful with ViewFSOverloadScheme.
33+
*/
34+
public class TestNNStartupWhenViewFSOverloadSchemeEnabled {
35+
private MiniDFSCluster cluster;
36+
private static final String FS_IMPL_PATTERN_KEY = "fs.%s.impl";
37+
private static final String HDFS_SCHEME = "hdfs";
38+
private static final Configuration CONF = new Configuration();
39+
40+
@BeforeClass
41+
public static void setUp() {
42+
CONF.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, 1);
43+
CONF.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
44+
CONF.setInt(
45+
CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1);
46+
CONF.set(String.format(FS_IMPL_PATTERN_KEY, HDFS_SCHEME),
47+
ViewFileSystemOverloadScheme.class.getName());
48+
CONF.set(String
49+
.format(FsConstants.FS_VIEWFS_OVERLOAD_SCHEME_TARGET_FS_IMPL_PATTERN,
50+
HDFS_SCHEME), DistributedFileSystem.class.getName());
51+
// By default trash interval is 0. To trigger TrashEmptier, let's set it to
52+
// >0 value.
53+
CONF.setLong(CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY, 100);
54+
}
55+
56+
/**
57+
* Tests that the HA mode NameNode startup is successful when
58+
* ViewFSOverloadScheme configured.
59+
*/
60+
@Test(timeout = 30000)
61+
public void testHANameNodeAndDataNodeStartup() throws Exception {
62+
cluster = new MiniDFSCluster.Builder(CONF)
63+
.nnTopology(MiniDFSNNTopology.simpleHATopology()).numDataNodes(1)
64+
.waitSafeMode(false).build();
65+
cluster.waitActive();
66+
cluster.transitionToActive(0);
67+
}
68+
69+
/**
70+
* Tests that the NameNode startup is successful when ViewFSOverloadScheme
71+
* configured.
72+
*/
73+
@Test(timeout = 30000)
74+
public void testNameNodeAndDataNodeStartup() throws Exception {
75+
cluster =
76+
new MiniDFSCluster.Builder(CONF).numDataNodes(1).waitSafeMode(false)
77+
.build();
78+
cluster.waitActive();
79+
}
80+
81+
@After
82+
public void shutdownCluster() {
83+
if (cluster != null) {
84+
cluster.shutdown();
85+
cluster = null;
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)