Github user selvaganesang commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1532#discussion_r184142826
  
    --- Diff: core/sql/src/main/java/org/trafodion/sql/HBaseClient.java ---
    @@ -552,10 +578,84 @@ public boolean createk(String tblName, Object[] 
tableOptions,
                          admin.createTable(desc);
                       }
                    }
    -            admin.close();
    +
    +            if(setDescRet!= null)
    +              if(setDescRet.storagePolicyChanged())
    +              {
    +                 //change the HDFS storage policy
    +                 //get the HBase table path
    +                 String hbaseRoot = config.get("hbase.rootdir");
    +                 FileSystem fs = FileSystem.get(config);
    +                 //Construct the HDFS dir
    +                 //find out if namespace is there
    +                 String[] parts = tblName.split(":");
    +                 String namespacestr="";
    +
    +                 //guess the path pattern
    +                 //different HBase version may have different path pattern
    +                 //There is no interface to get this information using 
HBase User API
    +                 //Since it is HBase internal behavior
    +                 //At present, before HBase 2.0 release and before 
HBASE-19858 released in HBase 1.5.0
    +                 //Trafodion here need a trick to guess
    +                 String fullPath = hbaseRoot + "/data/" ;
    +                 String fullPath2 = hbaseRoot + "/data/default/";
    +
    +                 //check if fullPath2 exist
    +                 if(fs.exists(new Path(fullPath2)))
    +                    fullPath = fullPath2;
    +
    +                 if(parts.length >1) //have namespace
    +                   fullPath = fullPath + parts[0] + "/" + parts[1];
    +                 else
    +                   fullPath = fullPath + tblName;
    +
    +                 if (logger.isDebugEnabled()) logger.debug("createk table 
fullPath is " + fullPath);
    +
    +                 String invokeret = invokeSetStoragePolicy(fs, fullPath, 
setDescRet.storagePolicy_ ) ;
    +
    +                 if( invokeret != null)
    +                 {
    +                   //error handling
    +                   admin.close();
    +                   throw new IOException(invokeret);
    +                 }
    +              }
    +
    +        admin.close();
             return true;
         }
     
    +    private static String invokeSetStoragePolicy(final FileSystem fs, 
final String pathstr,
    +      final String storagePolicy) {
    +        String ret = null;
    +        Path path = new Path(pathstr);
    +        Method m = null;
    +        try {
    +            m = fs.getClass().getDeclaredMethod("setStoragePolicy",
    +            new Class<?>[] { Path.class, String.class });
    +            m.setAccessible(true);
    +        } catch (NoSuchMethodException e) {
    +            ret = "FileSystem doesn't support setStoragePolicy";
    +            m = null;
    +        } catch (SecurityException e) {
    +          ret = "No access to setStoragePolicy on FileSystem from the 
SecurityManager";
    +          m = null; // could happen on setAccessible() or 
getDeclaredMethod()
    +        }
    +        if (m != null) {
    +          try {
    +            m.invoke(fs, path, storagePolicy);
    +            if (logger.isDebugEnabled()) {
    +              logger.debug("Set storagePolicy=" + storagePolicy + " for 
path=" + path);
    +            }
    +          } catch (Exception e) {
    +               logger.error("invoke set storage policy error : " + e);
    +               ret = "invoke set storage policy error : " + e.getMessage();
    --- End diff --
    
    To preserve the call stack, either let the method to throw all the 
exceptions.  If the generic Exception needs to be caught due to underlying API, 
throw new IOException(e). Let the caller also throw this IOException to be 
handled in the JNI layer


---

Reply via email to