|
@@ -1,3 +1,21 @@
|
|
|
+/**
|
|
|
+ * 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.namenode;
|
|
|
|
|
|
import java.io.File;
|
|
@@ -15,12 +33,17 @@ import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.FileUtil;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
+import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
+import org.apache.hadoop.hdfs.DFSClient;
|
|
|
+import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
|
+import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
|
|
|
import org.apache.hadoop.hdfs.server.common.HdfsConstants.StartupOption;
|
|
|
import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSImage.NameNodeDirType;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSImage.NameNodeFile;
|
|
|
import org.apache.hadoop.util.StringUtils;
|
|
|
+import org.junit.Test;
|
|
|
|
|
|
/**
|
|
|
* Startup and checkpoint tests
|
|
@@ -303,4 +326,29 @@ public class TestStartup extends TestCase {
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /** Test SafeMode counts only complete blocks */
|
|
|
+ @Test(timeout=60000)
|
|
|
+ public void testGetBlocks() throws Exception {
|
|
|
+ final Configuration CONF = new Configuration();
|
|
|
+
|
|
|
+ config.set(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_THRESHOLD_PCT_KEY, "1.0f");
|
|
|
+ MiniDFSCluster cluster = new MiniDFSCluster(CONF, 2, true, null);
|
|
|
+ try {
|
|
|
+ cluster.waitActive();
|
|
|
+
|
|
|
+ // Create a file and add one block, but not write to DataNode
|
|
|
+ DFSClient client = new DFSClient(CONF);
|
|
|
+ client.namenode.create("/tmp1.txt", new FsPermission("755"),
|
|
|
+ "clientName", false, (short) 2, 1024);
|
|
|
+ client.namenode.addBlock("/tmp1.txt", "clientName", new DatanodeInfo[0]);
|
|
|
+
|
|
|
+ // Restart NameNode waiting for exiting safemode, ensure NameNode doesn't
|
|
|
+ // get stuck in safemode
|
|
|
+ cluster.restartNameNode();
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|