@@ -202,7 +202,6 @@ public static boolean isHFileLink(final Path path) {
202202 return isHFileLink (path .getName ());
203203 }
204204
205-
206205 /**
207206 * @param fileName File name to check.
208207 * @return True if the path is a HFileLink.
@@ -323,10 +322,10 @@ public static String createHFileLinkName(final TableName tableName,
323322 * @param dstFamilyPath - Destination path (table/region/cf/)
324323 * @param hfileRegionInfo - Linked HFile Region Info
325324 * @param hfileName - Linked HFile name
326- * @return true if the file is created, otherwise the file exists .
327- * @throws IOException on file or parent directory creation failure
325+ * @return the file link name .
326+ * @throws IOException on file or parent directory creation failure.
328327 */
329- public static boolean create (final Configuration conf , final FileSystem fs ,
328+ public static String create (final Configuration conf , final FileSystem fs ,
330329 final Path dstFamilyPath , final RegionInfo hfileRegionInfo ,
331330 final String hfileName ) throws IOException {
332331 return create (conf , fs , dstFamilyPath , hfileRegionInfo , hfileName , true );
@@ -344,10 +343,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
344343 * @param hfileRegionInfo - Linked HFile Region Info
345344 * @param hfileName - Linked HFile name
346345 * @param createBackRef - Whether back reference should be created. Defaults to true.
347- * @return true if the file is created, otherwise the file exists .
348- * @throws IOException on file or parent directory creation failure
346+ * @return the file link name .
347+ * @throws IOException on file or parent directory creation failure.
349348 */
350- public static boolean create (final Configuration conf , final FileSystem fs ,
349+ public static String create (final Configuration conf , final FileSystem fs ,
351350 final Path dstFamilyPath , final RegionInfo hfileRegionInfo ,
352351 final String hfileName , final boolean createBackRef ) throws IOException {
353352 TableName linkedTable = hfileRegionInfo .getTable ();
@@ -367,17 +366,18 @@ public static boolean create(final Configuration conf, final FileSystem fs,
367366 * @param linkedTable - Linked Table Name
368367 * @param linkedRegion - Linked Region Name
369368 * @param hfileName - Linked HFile name
370- * @return true if the file is created, otherwise the file exists .
371- * @throws IOException on file or parent directory creation failure
369+ * @return the file link name .
370+ * @throws IOException on file or parent directory creation failure.
372371 */
373- public static boolean create (final Configuration conf , final FileSystem fs ,
372+ public static String create (final Configuration conf , final FileSystem fs ,
374373 final Path dstFamilyPath , final TableName linkedTable , final String linkedRegion ,
375374 final String hfileName ) throws IOException {
376375 return create (conf , fs , dstFamilyPath , linkedTable , linkedRegion , hfileName , true );
377376 }
378377
379378 /**
380- * Create a new HFileLink
379+ * Create a new HFileLink. In the event of link creation failure, this method throws an
380+ * IOException, so that the calling upper laying can decide on how to proceed with this.
381381 *
382382 * <p>It also adds a back-reference to the hfile back-reference directory
383383 * to simplify the reference-count and the cleaning process.
@@ -389,10 +389,10 @@ public static boolean create(final Configuration conf, final FileSystem fs,
389389 * @param linkedRegion - Linked Region Name
390390 * @param hfileName - Linked HFile name
391391 * @param createBackRef - Whether back reference should be created. Defaults to true.
392- * @return true if the file is created, otherwise the file exists .
393- * @throws IOException on file or parent directory creation failure
392+ * @return the file link name .
393+ * @throws IOException on file or parent directory creation failure.
394394 */
395- public static boolean create (final Configuration conf , final FileSystem fs ,
395+ public static String create (final Configuration conf , final FileSystem fs ,
396396 final Path dstFamilyPath , final TableName linkedTable , final String linkedRegion ,
397397 final String hfileName , final boolean createBackRef ) throws IOException {
398398 String familyName = dstFamilyPath .getName ();
@@ -420,7 +420,9 @@ public static boolean create(final Configuration conf, final FileSystem fs,
420420 }
421421 try {
422422 // Create the link
423- return fs .createNewFile (new Path (dstFamilyPath , name ));
423+ if (fs .createNewFile (new Path (dstFamilyPath , name ))){
424+ return name ;
425+ }
424426 } catch (IOException e ) {
425427 LOG .error ("couldn't create the link=" + name + " for " + dstFamilyPath , e );
426428 // Revert the reference if the link creation failed
@@ -429,25 +431,8 @@ public static boolean create(final Configuration conf, final FileSystem fs,
429431 }
430432 throw e ;
431433 }
432- }
433-
434- /**
435- * Create a new HFileLink starting from a hfileLink name
436- *
437- * <p>It also adds a back-reference to the hfile back-reference directory
438- * to simplify the reference-count and the cleaning process.
439- *
440- * @param conf {@link Configuration} to read for the archive directory name
441- * @param fs {@link FileSystem} on which to write the HFileLink
442- * @param dstFamilyPath - Destination path (table/region/cf/)
443- * @param hfileLinkName - HFileLink name (it contains hfile-region-table)
444- * @return true if the file is created, otherwise the file exists.
445- * @throws IOException on file or parent directory creation failure
446- */
447- public static boolean createFromHFileLink (final Configuration conf , final FileSystem fs ,
448- final Path dstFamilyPath , final String hfileLinkName )
449- throws IOException {
450- return createFromHFileLink (conf , fs , dstFamilyPath , hfileLinkName , true );
434+ throw new IOException ("File link=" + name + " already exists under " +
435+ dstFamilyPath + " folder." );
451436 }
452437
453438 /**
@@ -461,10 +446,10 @@ public static boolean createFromHFileLink(final Configuration conf, final FileSy
461446 * @param dstFamilyPath - Destination path (table/region/cf/)
462447 * @param hfileLinkName - HFileLink name (it contains hfile-region-table)
463448 * @param createBackRef - Whether back reference should be created. Defaults to true.
464- * @return true if the file is created, otherwise the file exists .
465- * @throws IOException on file or parent directory creation failure
449+ * @return the file link name .
450+ * @throws IOException on file or parent directory creation failure.
466451 */
467- public static boolean createFromHFileLink (final Configuration conf , final FileSystem fs ,
452+ public static String createFromHFileLink (final Configuration conf , final FileSystem fs ,
468453 final Path dstFamilyPath , final String hfileLinkName , final boolean createBackRef )
469454 throws IOException {
470455 Matcher m = LINK_NAME_PATTERN .matcher (hfileLinkName );
0 commit comments