@@ -201,7 +201,6 @@ public static boolean isHFileLink(final Path path) {
201201 return isHFileLink (path .getName ());
202202 }
203203
204-
205204 /**
206205 * @param fileName File name to check.
207206 * @return True if the path is a HFileLink.
@@ -322,10 +321,10 @@ public static String createHFileLinkName(final TableName tableName,
322321 * @param dstFamilyPath - Destination path (table/region/cf/)
323322 * @param hfileRegionInfo - Linked HFile Region Info
324323 * @param hfileName - Linked HFile name
325- * @return true if the file is created, otherwise the file exists .
326- * @throws IOException on file or parent directory creation failure
324+ * @return the file link name .
325+ * @throws IOException on file or parent directory creation failure.
327326 */
328- public static boolean create (final Configuration conf , final FileSystem fs ,
327+ public static String create (final Configuration conf , final FileSystem fs ,
329328 final Path dstFamilyPath , final RegionInfo hfileRegionInfo ,
330329 final String hfileName ) throws IOException {
331330 return create (conf , fs , dstFamilyPath , hfileRegionInfo , hfileName , true );
@@ -343,10 +342,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
343342 * @param hfileRegionInfo - Linked HFile Region Info
344343 * @param hfileName - Linked HFile name
345344 * @param createBackRef - Whether back reference should be created. Defaults to true.
346- * @return true if the file is created, otherwise the file exists .
347- * @throws IOException on file or parent directory creation failure
345+ * @return the file link name .
346+ * @throws IOException on file or parent directory creation failure.
348347 */
349- public static boolean create (final Configuration conf , final FileSystem fs ,
348+ public static String create (final Configuration conf , final FileSystem fs ,
350349 final Path dstFamilyPath , final RegionInfo hfileRegionInfo ,
351350 final String hfileName , final boolean createBackRef ) throws IOException {
352351 TableName linkedTable = hfileRegionInfo .getTable ();
@@ -366,17 +365,18 @@ public static boolean create(final Configuration conf, final FileSystem fs,
366365 * @param linkedTable - Linked Table Name
367366 * @param linkedRegion - Linked Region Name
368367 * @param hfileName - Linked HFile name
369- * @return true if the file is created, otherwise the file exists .
370- * @throws IOException on file or parent directory creation failure
368+ * @return the file link name .
369+ * @throws IOException on file or parent directory creation failure.
371370 */
372- public static boolean create (final Configuration conf , final FileSystem fs ,
371+ public static String create (final Configuration conf , final FileSystem fs ,
373372 final Path dstFamilyPath , final TableName linkedTable , final String linkedRegion ,
374373 final String hfileName ) throws IOException {
375374 return create (conf , fs , dstFamilyPath , linkedTable , linkedRegion , hfileName , true );
376375 }
377376
378377 /**
379- * Create a new HFileLink
378+ * Create a new HFileLink. In the event of link creation failure, this method throws an
379+ * IOException, so that the calling upper laying can decide on how to proceed with this.
380380 *
381381 * <p>It also adds a back-reference to the hfile back-reference directory
382382 * to simplify the reference-count and the cleaning process.
@@ -388,10 +388,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
388388 * @param linkedRegion - Linked Region Name
389389 * @param hfileName - Linked HFile name
390390 * @param createBackRef - Whether back reference should be created. Defaults to true.
391- * @return true if the file is created, otherwise the file exists .
392- * @throws IOException on file or parent directory creation failure
391+ * @return the file link name .
392+ * @throws IOException on file or parent directory creation failure.
393393 */
394- public static boolean create (final Configuration conf , final FileSystem fs ,
394+ public static String create (final Configuration conf , final FileSystem fs ,
395395 final Path dstFamilyPath , final TableName linkedTable , final String linkedRegion ,
396396 final String hfileName , final boolean createBackRef ) throws IOException {
397397 String familyName = dstFamilyPath .getName ();
@@ -417,10 +417,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
417417 * @param linkedRegion - Linked Region Name
418418 * @param hfileName - Linked HFile name
419419 * @param createBackRef - Whether back reference should be created. Defaults to true.
420- * @return true if the file is created, otherwise the file exists .
420+ * @return the file link name .
421421 * @throws IOException on file or parent directory creation failure
422422 */
423- public static boolean create (final Configuration conf , final FileSystem fs ,
423+ public static String create (final Configuration conf , final FileSystem fs ,
424424 final Path dstFamilyPath , final String familyName , final String dstTableName ,
425425 final String dstRegionName , final TableName linkedTable , final String linkedRegion ,
426426 final String hfileName , final boolean createBackRef ) throws IOException {
@@ -444,7 +444,9 @@ public static boolean create(final Configuration conf, final FileSystem fs,
444444 }
445445 try {
446446 // Create the link
447- return fs .createNewFile (new Path (dstFamilyPath , name ));
447+ if (fs .createNewFile (new Path (dstFamilyPath , name ))) {
448+ return name ;
449+ }
448450 } catch (IOException e ) {
449451 LOG .error ("couldn't create the link=" + name + " for " + dstFamilyPath , e );
450452 // Revert the reference if the link creation failed
@@ -453,25 +455,8 @@ public static boolean create(final Configuration conf, final FileSystem fs,
453455 }
454456 throw e ;
455457 }
456- }
457-
458- /**
459- * Create a new HFileLink starting from a hfileLink name
460- *
461- * <p>It also adds a back-reference to the hfile back-reference directory
462- * to simplify the reference-count and the cleaning process.
463- *
464- * @param conf {@link Configuration} to read for the archive directory name
465- * @param fs {@link FileSystem} on which to write the HFileLink
466- * @param dstFamilyPath - Destination path (table/region/cf/)
467- * @param hfileLinkName - HFileLink name (it contains hfile-region-table)
468- * @return true if the file is created, otherwise the file exists.
469- * @throws IOException on file or parent directory creation failure
470- */
471- public static boolean createFromHFileLink (final Configuration conf , final FileSystem fs ,
472- final Path dstFamilyPath , final String hfileLinkName )
473- throws IOException {
474- return createFromHFileLink (conf , fs , dstFamilyPath , hfileLinkName , true );
458+ throw new IOException ("File link=" + name + " already exists under " +
459+ dstFamilyPath + " folder." );
475460 }
476461
477462 /**
@@ -485,10 +470,10 @@ public static boolean createFromHFileLink(final Configuration conf, final FileSy
485470 * @param dstFamilyPath - Destination path (table/region/cf/)
486471 * @param hfileLinkName - HFileLink name (it contains hfile-region-table)
487472 * @param createBackRef - Whether back reference should be created. Defaults to true.
488- * @return true if the file is created, otherwise the file exists .
489- * @throws IOException on file or parent directory creation failure
473+ * @return the file link name .
474+ * @throws IOException on file or parent directory creation failure.
490475 */
491- public static boolean createFromHFileLink (final Configuration conf , final FileSystem fs ,
476+ public static String createFromHFileLink (final Configuration conf , final FileSystem fs ,
492477 final Path dstFamilyPath , final String hfileLinkName , final boolean createBackRef )
493478 throws IOException {
494479 Matcher m = LINK_NAME_PATTERN .matcher (hfileLinkName );
0 commit comments