From 2d8dbb2054060fd682d8e4b519a3ce0722419a54 Mon Sep 17 00:00:00 2001 From: Zhong Date: Thu, 14 Jul 2016 15:06:44 +0800 Subject: [PATCH] KYLIN-1889: Deal with the failure of renaming folder in hdfs when running the tool CubeMigrationCLI --- .../kylin/storage/hbase/util/CubeMigrationCLI.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/CubeMigrationCLI.java b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/CubeMigrationCLI.java index 32aa4b0..5bb0a94 100644 --- a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/CubeMigrationCLI.java +++ b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/CubeMigrationCLI.java @@ -411,7 +411,7 @@ public class CubeMigrationCLI { case RENAME_FOLDER_IN_HDFS: { String srcPath = (String) opt.params[0]; String dstPath = (String) opt.params[1]; - hdfsFS.rename(new Path(srcPath), new Path(dstPath)); + renameHDFSPath(srcPath, dstPath); logger.info("HDFS Folder renamed from " + srcPath + " to " + dstPath); break; } @@ -513,7 +513,7 @@ public class CubeMigrationCLI { String dstPath = (String) opt.params[0]; if (hdfsFS.exists(new Path(srcPath)) && !hdfsFS.exists(new Path(dstPath))) { - hdfsFS.rename(new Path(srcPath), new Path(dstPath)); + renameHDFSPath(srcPath, dstPath); logger.info("HDFS Folder renamed from " + srcPath + " to " + dstPath); } break; @@ -547,4 +547,17 @@ public class CubeMigrationCLI { } } } + + private static void renameHDFSPath(String srcPath, String dstPath) throws IOException, InterruptedException { + int nRetry = 0; + int sleepTime = 5000; + while (!hdfsFS.rename(new Path(srcPath), new Path(dstPath))) { + ++nRetry; + if (nRetry > 3) { + throw new InterruptedException("Cannot rename folder " + srcPath + " to folder " + dstPath); + } else { + Thread.sleep(sleepTime * nRetry * nRetry); + } + } + } } -- 2.5.4 (Apple Git-61)