refactor the code for review comments
Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/f04d51f6 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/f04d51f6 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/f04d51f6 Branch: refs/heads/master Commit: f04d51f6e17676fc7c8a9b3cf3d2b225c8b2398a Parents: 335e9e8 Author: Liu Ming <[email protected]> Authored: Sun Jun 10 20:16:50 2018 -0400 Committer: Liu Ming <[email protected]> Committed: Sun Jun 10 20:16:50 2018 -0400 ---------------------------------------------------------------------- .../transactional/TransactionManager.java | 3 +- .../transactional/TrxRegionEndpoint.java.tmpl | 34 +++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/f04d51f6/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TransactionManager.java ---------------------------------------------------------------------- diff --git a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TransactionManager.java b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TransactionManager.java index 9dd9643..3705d62 100644 --- a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TransactionManager.java +++ b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TransactionManager.java @@ -3301,11 +3301,12 @@ public class TransactionManager { //handle result and error if( ret == null) { + retry = true; LOG.error("setStoragePolicy Response ret null "); } else if (ret.getStatus() == false) { - LOG.error("setStoragePolicy Response ret false: " + ret.getException()); + LOG.error("setStoragePolicy Response ret false." + ret.getException()); throw new IOException(ret.getException()); } if(retryCount == RETRY_ATTEMPTS) http://git-wip-us.apache.org/repos/asf/trafodion/blob/f04d51f6/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/coprocessor/transactional/TrxRegionEndpoint.java.tmpl ---------------------------------------------------------------------- diff --git a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/coprocessor/transactional/TrxRegionEndpoint.java.tmpl b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/coprocessor/transactional/TrxRegionEndpoint.java.tmpl index 050b9bc..2cbdc1e 100644 --- a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/coprocessor/transactional/TrxRegionEndpoint.java.tmpl +++ b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/coprocessor/transactional/TrxRegionEndpoint.java.tmpl @@ -470,6 +470,9 @@ CoprocessorService, Coprocessor { public static final int REGION_STATE_START = 2; public static final String trxkeyEPCPinstance = "EPCPinstance"; + + private static Method hdfsSetStoragePolicyMethod = null; + private static String hdfsSetStoragePolicyReflectErrorMsg = ""; #ifdef HDP2.3 HDP2.4 CDH5.5 CDH5.7 APACHE1.2 static ChoreService s_ChoreService = null; @@ -2450,26 +2453,16 @@ CoprocessorService, Coprocessor { final String storagePolicy) throws IOException { 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) { - m = null; - throw new IOException("FileSystem doesn't support setStoragePolicy"); - } catch (SecurityException e) { - m = null; - throw new IOException("No access to setStoragePolicy on FileSystem from the SecurityManager"); - } - if (m != null) { + if(hdfsSetStoragePolicyMethod == null) + throw new IOException(hdfsSetStoragePolicyReflectErrorMsg); + if (hdfsSetStoragePolicyMethod != null) { try { - m.invoke(fs, path, storagePolicy); + hdfsSetStoragePolicyMethod.invoke(fs, path, storagePolicy); if (LOG.isDebugEnabled()) { LOG.debug("Set storagePolicy=" + storagePolicy + " for path=" + path); } } catch (Exception e) { - LOG.error("invoke set storage policy error : " + e); + LOG.error("invoke set storage policy error : " , e); throw new IOException(e); } } @@ -3450,6 +3443,17 @@ CoprocessorService, Coprocessor { this.config = tmp_env.getConfiguration(); this.fs = FileSystem.get(config); + try { + hdfsSetStoragePolicyMethod = fs.getClass().getDeclaredMethod("setStoragePolicy", + new Class<?>[] { Path.class, String.class }); + hdfsSetStoragePolicyMethod.setAccessible(true); + } catch (NoSuchMethodException e) { + hdfsSetStoragePolicyMethod = null; + hdfsSetStoragePolicyReflectErrorMsg = "FileSystem doesn't support setStoragePolicy"; + } catch (SecurityException e) { + hdfsSetStoragePolicyMethod = null; + hdfsSetStoragePolicyReflectErrorMsg = "No access to setStoragePolicy on FileSystem from the SecurityManager"; + } synchronized (stoppableLock) { try {
