-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-28898. Use reflection to access recoverLease(), setSafeMode() APIs. #6342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
49f4fa7
1585209
8bc2b03
441e54a
8b48401
ad06438
e983c82
8f7d058
d75d68f
07c0831
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,23 @@ public final class FSUtils { | |
| // currently only used in testing. TODO refactor into a test class | ||
| public static final boolean WINDOWS = System.getProperty("os.name").startsWith("Windows"); | ||
|
|
||
| private static Class<?> safeModeClazz = null; | ||
| private static Class<?> safeModeActionClazz = null; | ||
| private static Object safeModeGet = null; | ||
| { | ||
| try { | ||
| safeModeClazz = Class.forName("org.apache.hadoop.fs.SafeMode"); | ||
| safeModeActionClazz = Class.forName("org.apache.hadoop.fs.SafeModeAction"); | ||
| safeModeGet = safeModeClazz.getField("SAFEMODE_GET").get(null); | ||
| } catch (ClassNotFoundException | NoSuchFieldException e) { | ||
| LOG.debug("SafeMode interface not in the classpath, this means Hadoop 3.3.5 or below."); | ||
| } catch (IllegalAccessException e) { | ||
| LOG.error("SafeModeAction.SAFEMODE_GET is not accessible. " | ||
| + "Unexpected Hadoop version or messy classpath?", e); | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| private FSUtils() { | ||
| } | ||
|
|
||
|
|
@@ -247,8 +264,20 @@ public static void checkFileSystemAvailable(final FileSystem fs) throws IOExcept | |
| * @param dfs A DistributedFileSystem object representing the underlying HDFS. | ||
| * @return whether we're in safe mode | ||
| */ | ||
| private static boolean isInSafeMode(DistributedFileSystem dfs) throws IOException { | ||
| return dfs.setSafeMode(SAFEMODE_GET, true); | ||
| private static boolean isInSafeMode(FileSystem dfs) throws IOException { | ||
| if (isDistributedFileSystem(dfs)) { | ||
| return ((DistributedFileSystem) dfs).setSafeMode(SAFEMODE_GET, true); | ||
| } else { | ||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just return false here if we could not find the method previously ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before calling isInSafeMode() it calls supportSafeMode(). If it's LocalFileSystem it will not enter isInSafeMode(). |
||
| Object ret = dfs.getClass() | ||
| .getMethod("setSafeMode", new Class[] { safeModeActionClazz, Boolean.class }) | ||
| .invoke(dfs, safeModeGet, true); | ||
| return (Boolean) ret; | ||
| } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { | ||
| LOG.error("The file system does not support setSafeMode(). Abort.", e); | ||
| throw new RuntimeException(e); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no Hadoop release where we expect to get here, right ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe log an error message to explain that this should never happen ? |
||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -257,9 +286,8 @@ private static boolean isInSafeMode(DistributedFileSystem dfs) throws IOExceptio | |
| public static void checkDfsSafeMode(final Configuration conf) throws IOException { | ||
| boolean isInSafeMode = false; | ||
| FileSystem fs = FileSystem.get(conf); | ||
| if (fs instanceof DistributedFileSystem) { | ||
| DistributedFileSystem dfs = (DistributedFileSystem) fs; | ||
| isInSafeMode = isInSafeMode(dfs); | ||
| if (supportSafeMode(fs)) { | ||
| isInSafeMode = isInSafeMode(fs); | ||
| } | ||
| if (isInSafeMode) { | ||
| throw new IOException("File system is in safemode, it can't be written now"); | ||
|
|
@@ -644,10 +672,11 @@ public static void setClusterId(final FileSystem fs, final Path rootdir, | |
| */ | ||
| public static void waitOnSafeMode(final Configuration conf, final long wait) throws IOException { | ||
| FileSystem fs = FileSystem.get(conf); | ||
| if (!(fs instanceof DistributedFileSystem)) return; | ||
| DistributedFileSystem dfs = (DistributedFileSystem) fs; | ||
| if (!supportSafeMode(fs)) { | ||
| return; | ||
| } | ||
| // Make sure dfs is not in safe mode | ||
| while (isInSafeMode(dfs)) { | ||
| while (isInSafeMode(fs)) { | ||
| LOG.info("Waiting for dfs to exit safe mode..."); | ||
| try { | ||
| Thread.sleep(wait); | ||
|
|
@@ -658,6 +687,19 @@ public static void waitOnSafeMode(final Configuration conf, final long wait) thr | |
| } | ||
| } | ||
|
|
||
| public static boolean supportSafeMode(FileSystem fs) { | ||
| // return true if HDFS. | ||
| if (fs instanceof DistributedFileSystem) { | ||
| return true; | ||
| } | ||
| // return true if the file system implements SafeMode interface. | ||
| if (safeModeClazz != null) { | ||
| return (safeModeClazz.isAssignableFrom(fs.getClass())); | ||
| } | ||
| // return false if the file system is not HDFS and does not implement SafeMode interface. | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if meta region exists | ||
| * @param fs file system | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We expect to have this on all supported releases, right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe log an error message to explain that this should never happen ?