|
@@ -18,15 +18,19 @@
|
|
package org.apache.hadoop.hdfs.server.namenode;
|
|
package org.apache.hadoop.hdfs.server.namenode;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.FilenameFilter;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.hdfs.server.common.Storage;
|
|
import org.apache.hadoop.hdfs.server.common.Storage;
|
|
import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
|
|
import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory;
|
|
import org.apache.hadoop.hdfs.server.common.StorageInfo;
|
|
import org.apache.hadoop.hdfs.server.common.StorageInfo;
|
|
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.base.Preconditions;
|
|
|
|
+import org.apache.hadoop.io.IOUtils;
|
|
|
|
|
|
abstract class NNUpgradeUtil {
|
|
abstract class NNUpgradeUtil {
|
|
|
|
|
|
@@ -99,15 +103,17 @@ abstract class NNUpgradeUtil {
|
|
* a call to any JM's or local storage dir's doPreUpgrade method fails, then
|
|
* a call to any JM's or local storage dir's doPreUpgrade method fails, then
|
|
* doUpgrade will not be called for any JM. The existing current dir is
|
|
* doUpgrade will not be called for any JM. The existing current dir is
|
|
* renamed to previous.tmp, and then a new, empty current dir is created.
|
|
* renamed to previous.tmp, and then a new, empty current dir is created.
|
|
- *
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param conf configuration for creating {@link EditLogFileOutputStream}
|
|
* @param sd the storage directory to perform the pre-upgrade procedure.
|
|
* @param sd the storage directory to perform the pre-upgrade procedure.
|
|
* @throws IOException in the event of error
|
|
* @throws IOException in the event of error
|
|
*/
|
|
*/
|
|
- static void doPreUpgrade(StorageDirectory sd) throws IOException {
|
|
|
|
|
|
+ static void doPreUpgrade(Configuration conf, StorageDirectory sd)
|
|
|
|
+ throws IOException {
|
|
LOG.info("Starting upgrade of storage directory " + sd.getRoot());
|
|
LOG.info("Starting upgrade of storage directory " + sd.getRoot());
|
|
File curDir = sd.getCurrentDir();
|
|
File curDir = sd.getCurrentDir();
|
|
File prevDir = sd.getPreviousDir();
|
|
File prevDir = sd.getPreviousDir();
|
|
- File tmpDir = sd.getPreviousTmp();
|
|
|
|
|
|
+ final File tmpDir = sd.getPreviousTmp();
|
|
|
|
|
|
Preconditions.checkState(curDir.exists(),
|
|
Preconditions.checkState(curDir.exists(),
|
|
"Current directory must exist for preupgrade.");
|
|
"Current directory must exist for preupgrade.");
|
|
@@ -123,6 +129,35 @@ abstract class NNUpgradeUtil {
|
|
if (!curDir.mkdir()) {
|
|
if (!curDir.mkdir()) {
|
|
throw new IOException("Cannot create directory " + curDir);
|
|
throw new IOException("Cannot create directory " + curDir);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ List<String> fileNameList = IOUtils.listDirectory(tmpDir, new FilenameFilter() {
|
|
|
|
+ @Override
|
|
|
|
+ public boolean accept(File dir, String name) {
|
|
|
|
+ return dir.equals(tmpDir)
|
|
|
|
+ && name.startsWith(NNStorage.NameNodeFile.EDITS.getName());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ for (String s : fileNameList) {
|
|
|
|
+ File prevFile = new File(tmpDir, s);
|
|
|
|
+ Preconditions.checkState(prevFile.canRead(),
|
|
|
|
+ "Edits log file " + s + " is not readable.");
|
|
|
|
+ File newFile = new File(curDir, prevFile.getName());
|
|
|
|
+ Preconditions.checkState(newFile.createNewFile(),
|
|
|
|
+ "Cannot create new edits log file in " + curDir);
|
|
|
|
+ EditLogFileInputStream in = new EditLogFileInputStream(prevFile);
|
|
|
|
+ EditLogFileOutputStream out =
|
|
|
|
+ new EditLogFileOutputStream(conf, newFile, 512*1024);
|
|
|
|
+ FSEditLogOp logOp = in.nextValidOp();
|
|
|
|
+ while (logOp != null) {
|
|
|
|
+ out.write(logOp);
|
|
|
|
+ logOp = in.nextOp();
|
|
|
|
+ }
|
|
|
|
+ out.setReadyToFlush();
|
|
|
|
+ out.flushAndSync(true);
|
|
|
|
+ out.close();
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|