diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java index c118aea..d50cf15 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/migration/NamespaceUpgrade.java @@ -64,6 +64,12 @@ public class NamespaceUpgrade implements Tool { private Path baseDirs[]; // First move everything to this tmp .data dir in case there is a table named 'data' private final String TMP_DATA_DIR = ".data"; + // Old dir names to migrate. + private final String DOT_LOGS = ".logs"; + private final String DOT_OLD_LOGS = ".oldlogs"; + private final String DOT_CORRUPT = ".corrupt"; + private final String DOT_SPLITLOG = "splitlog"; + private final String DOT_ARCHIVE = ".archive"; public NamespaceUpgrade() throws IOException { super(); @@ -122,11 +128,10 @@ public class NamespaceUpgrade implements Tool { // Dot dirs to rename. Leave the tmp dir named '.tmp' and snapshots as .hbase-snapshot. final Path archiveDir = new Path(rootDir, HConstants.HFILE_ARCHIVE_DIRECTORY); Path [][] dirs = new Path[][] { - new Path [] {new Path(rootDir, ".corrupt"), new Path(rootDir, HConstants.CORRUPT_DIR_NAME)}, - new Path [] {new Path(rootDir, ".logs"), new Path(rootDir, HConstants.HREGION_LOGDIR_NAME)}, - new Path [] {new Path(rootDir, ".oldlogs"), + new Path [] {new Path(rootDir, DOT_CORRUPT), new Path(rootDir, HConstants.CORRUPT_DIR_NAME)}, + new Path [] {new Path(rootDir, DOT_LOGS), new Path(rootDir, HConstants.HREGION_LOGDIR_NAME)}, + new Path [] {new Path(rootDir, DOT_OLD_LOGS), new Path(rootDir, HConstants.HREGION_OLDLOGDIR_NAME)}, - new Path [] {new Path(rootDir, ".archive"), archiveDir}, new Path [] {new Path(rootDir, TMP_DATA_DIR), new Path(rootDir, HConstants.BASE_NAMESPACE_DIR)}}; for (Path [] dir: dirs) { @@ -138,17 +143,26 @@ public class NamespaceUpgrade implements Tool { } rename(src, tgt); } - if (this.fs.exists(archiveDir)) { - // Rename the subdir name .data. - Path dotDataDir = new Path(archiveDir, ".data"); - Path dataDir = new Path(archiveDir, "data"); - if (this.fs.exists(dotDataDir)) rename(dotDataDir, dataDir); + // Do the .archive dir. Need to move its subdirs to the default ns dir under data dir... so + // from '.archive/foo', to 'archive/data/default/foo'. + Path oldArchiveDir = new Path(rootDir, DOT_ARCHIVE); + if (this.fs.exists(oldArchiveDir)) { + // This is a pain doing two nn calls but portable over h1 and h2. + mkdirs(archiveDir); + Path archiveDataDir = new Path(archiveDir, HConstants.BASE_NAMESPACE_DIR); + mkdirs(archiveDataDir); + rename(oldArchiveDir, new Path(archiveDataDir, + NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR)); } } + private void mkdirs(final Path p) throws IOException { + if (!this.fs.mkdirs(p)) throw new IOException("Failed make of " + p); + } + private void rename(final Path src, final Path tgt) throws IOException { if (!fs.rename(src, tgt)) { - throw new IOException("Failed move " + src + " to "+tgt); + throw new IOException("Failed move " + src + " to " + tgt); } } @@ -179,15 +193,15 @@ public class NamespaceUpgrade implements Tool { List sysTables = Lists.newArrayList("-ROOT-",".META."); /** Directories that are not HBase table directories */ final List nonUserTableDirs = Arrays.asList(new String[] { - ".logs", - ".oldlogs", - ".corrupt", - "splitlog", + DOT_LOGS, + DOT_OLD_LOGS, + DOT_CORRUPT, + DOT_SPLITLOG, HConstants.HBCK_SIDELINEDIR_NAME, - ".archive", + DOT_ARCHIVE, HConstants.SNAPSHOT_DIR_NAME, HConstants.HBASE_TEMP_DIRECTORY, - ".data"}); + TMP_DATA_DIR}); // Migrate tables including archive and tmp for (Path baseDir: baseDirs) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java index eeff846..7157033 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestNamespaceUpgrade.java @@ -44,8 +44,10 @@ import org.apache.hadoop.hbase.protobuf.generated.AdminProtos; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.util.ToolRunner; +import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -75,6 +77,7 @@ public class TestNamespaceUpgrade { private final static String currentKeys[] = {"1","2","3","4","5","6","7","8","9","A"}; private final static String tables[] = {"foo", "ns1.foo","ns.two.foo"}; + private FsShell shell; @BeforeClass public static void setUpBeforeClass() throws Exception { @@ -102,7 +105,6 @@ public class TestNamespaceUpgrade { Configuration toolConf = TEST_UTIL.getConfiguration(); conf.set(HConstants.HBASE_DIR, TEST_UTIL.getDefaultRootDirPath().toString()); ToolRunner.run(toolConf, new NamespaceUpgrade(), new String[]{"--upgrade"}); - doFsCommand(shell, new String [] {"-lsr", "/"}); assertTrue(FSUtils.getVersion(fs, hbaseRootDir).equals(HConstants.FILE_SYSTEM_VERSION)); TEST_UTIL.startMiniHBaseCluster(1, 1); @@ -170,7 +172,7 @@ public class TestNamespaceUpgrade { } @Test - public void testRenameUsingSnapshots() throws IOException, InterruptedException { + public void testRenameUsingSnapshots() throws Exception { String newNS = "newNS"; TEST_UTIL.getHBaseAdmin().createNamespace(NamespaceDescriptor.create(newNS).build()); for(String table: tables) { @@ -179,10 +181,9 @@ public class TestNamespaceUpgrade { Scan())) { assertEquals(currentKeys[count++], Bytes.toString(res.getRow())); } - TEST_UTIL.getHBaseAdmin().snapshot(table+"_snapshot3", table); - final String newTableName = - newNS+ TableName.NAMESPACE_DELIM+table+"_clone3"; - TEST_UTIL.getHBaseAdmin().cloneSnapshot(table+"_snapshot3", newTableName); + TEST_UTIL.getHBaseAdmin().snapshot(table + "_snapshot3", table); + final String newTableName = newNS + TableName.NAMESPACE_DELIM + table + "_clone3"; + TEST_UTIL.getHBaseAdmin().cloneSnapshot(table + "_snapshot3", newTableName); Thread.sleep(1000); count = 0; for(Result res: new HTable(TEST_UTIL.getConfiguration(), newTableName).getScanner(new @@ -223,7 +224,5 @@ public class TestNamespaceUpgrade { } Assert.assertEquals(newTableName, currentKeys.length, count); } - } -} - +} \ No newline at end of file