@@ -79,11 +79,9 @@ public class HRegionFileSystem {
7979 public final static String REGION_INFO_FILE = ".regioninfo" ;
8080
8181 /** Temporary subdirectory of the region directory used for merges. */
82- @ Deprecated
8382 public static final String REGION_MERGES_DIR = ".merges" ;
8483
8584 /** Temporary subdirectory of the region directory used for splits. */
86- @ Deprecated
8785 public static final String REGION_SPLITS_DIR = ".splits" ;
8886
8987 /** Temporary subdirectory of the region directory used for compaction output. */
@@ -978,6 +976,31 @@ public static void deleteRegionFromFileSystem(final Configuration conf, final Fi
978976 }
979977 }
980978
979+ /**
980+ * Retrieves the Region ID from the given HFile path.
981+ * @param hFilePath The path of the HFile.
982+ * @return The Region ID extracted from the HFile path.
983+ * @throws IOException If an I/O error occurs or if the HFile path is incorrect.
984+ */
985+ public static String getRegionId (Path hFilePath ) throws IOException {
986+ if (hFilePath .getParent () == null || hFilePath .getParent ().getParent () == null ) {
987+ throw new IOException ("Incorrect HFile Path: " + hFilePath );
988+ }
989+ Path dir = hFilePath .getParent ().getParent ();
990+ if (isTemporaryDirectoryName (dir .getName ())) {
991+ if (dir .getParent () == null ) {
992+ throw new IOException ("Incorrect HFile Path: " + hFilePath );
993+ }
994+ return dir .getParent ().getName ();
995+ }
996+ return dir .getName ();
997+ }
998+
999+ private static boolean isTemporaryDirectoryName (String dirName ) {
1000+ return REGION_MERGES_DIR .equals (dirName ) || REGION_SPLITS_DIR .equals (dirName )
1001+ || REGION_TEMP_DIR .equals (dirName );
1002+ }
1003+
9811004 /**
9821005 * Creates a directory. Assumes the user has already checked for this directory existence.
9831006 * @return the result of fs.mkdirs(). In case underlying fs throws an IOException, it checks
0 commit comments