haohao0103 commented on code in PR #5064:
URL: https://github.com/apache/hbase/pull/5064#discussion_r1121169968


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java:
##########
@@ -203,20 +202,21 @@ public static FSDataOutputStream create(Configuration 
conf, FileSystem fs, Path
         short replication = 
Short.parseShort(conf.get(ColumnFamilyDescriptorBuilder.DFS_REPLICATION,
           
String.valueOf(ColumnFamilyDescriptorBuilder.DEFAULT_DFS_REPLICATION)));
         try {
-          return (FSDataOutputStream) (DistributedFileSystem.class
-            .getDeclaredMethod("create", Path.class, FsPermission.class, 
boolean.class, int.class,
-              short.class, long.class, Progressable.class, 
InetSocketAddress[].class)
-            .invoke(backingFs, path, perm, true, 
CommonFSUtils.getDefaultBufferSize(backingFs),
-              replication > 0 ? replication : 
CommonFSUtils.getDefaultReplication(backingFs, path),
-              CommonFSUtils.getDefaultBlockSize(backingFs, path), null, 
favoredNodes));
-        } catch (InvocationTargetException ite) {
-          // Function was properly called, but threw it's own exception.
-          throw new IOException(ite.getCause());
-        } catch (NoSuchMethodException e) {
+          DistributedFileSystem dfs = (DistributedFileSystem) backingFs;
+          DistributedFileSystem.HdfsDataOutputStreamBuilder builder = 
dfs.createFile(path)
+            .permission(perm).create().overwrite(true)
+            .bufferSize(CommonFSUtils.getDefaultBufferSize(backingFs))
+            .replication(
+              replication > 0 ? replication : 
CommonFSUtils.getDefaultReplication(backingFs, path))
+            .blockSize(CommonFSUtils.getDefaultBlockSize(backingFs, path));
+          if (favoredNodes != null) {
+            builder.favoredNodes(favoredNodes);
+          }
+          builder.recursive();
+          return builder.build();
+        } catch (IllegalArgumentException | SecurityException e) {

Review Comment:
   This is my idea to communicate with you, the builder.build () is executed in 
addition to throw an IOException, code will throw a runtime exception: 
IllegalArgumentException,  the main purpose of handling a catch 
IllegalArgumentException is to prevent code from returning. the code can go 
down to get the normal stream (non favoritenodes) and the method still works; 
the SecurityException looks a little redundant,Maybe I need to remove the 
SecurityException?
   
   FSDataOutputStreamBuilder.build():
   /**
      * Create the FSDataOutputStream to write on the file system.
      *
      * @throws IllegalArgumentException if the parameters are not valid.
      * @throws IOException on errors when file system creates or appends the 
file.
      */
     public abstract S build() throws IllegalArgumentException, IOException;



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to