trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbirds...@apache.org
Subject [3/4] incubator-trafodion git commit: [TRAFODION-1988] Better Java exception handling in Trafodion
Date Wed, 18 May 2016 18:05:49 GMT
[TRAFODION-1988] Better Java exception handling in Trafodion


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/34abbbe7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/34abbbe7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/34abbbe7

Branch: refs/heads/master
Commit: 34abbbe70de21475d3a9e27ff74b7c290bd617c6
Parents: dcfc8e6
Author: selvaganesang <selva.govindarajan@esgyn.com>
Authored: Wed May 11 21:58:55 2016 +0000
Committer: selvaganesang <selva.govindarajan@esgyn.com>
Committed: Thu May 12 03:06:46 2016 +0000

----------------------------------------------------------------------
 .../hbase/client/transactional/RMInterface.java |  43 +-
 .../RetryTransactionException.java              |  54 ++
 .../RollbackUnsuccessfulException.java          |  62 ++
 .../transactional/SsccTransactionalTable.java   |  34 +-
 .../hbase/client/transactional/TmDDL.java       |  24 +-
 .../transactional/TransactionManager.java       | 626 ++++++++-----------
 .../TransactionalScanner.java.tmpl              |  97 ++-
 .../transactional/TransactionalTable.java       |  46 +-
 .../transactional/IdTmException.java            |  14 +
 .../java/org/trafodion/dtm/HBaseTxClient.java   |   7 +-
 .../java/org/trafodion/sql/ByteArrayList.java   |  54 --
 .../java/org/trafodion/sql/HBaseClient.java     |  76 +--
 .../java/org/trafodion/sql/HBulkLoadClient.java |  42 +-
 .../java/org/trafodion/sql/HTableClient.java    |  18 +-
 .../main/java/org/trafodion/sql/HiveClient.java |  59 +-
 .../java/org/trafodion/sql/ResultIterator.java  | 133 ----
 .../org/trafodion/sql/ResultKeyValueList.java   | 100 ---
 .../java/org/trafodion/sql/RowToInsert.java     |  44 --
 .../java/org/trafodion/sql/RowsToInsert.java    |  57 --
 .../org/trafodion/sql/SequenceFileWriter.java   | 129 +---
 .../java/org/trafodion/sql/StringArrayList.java |  47 --
 21 files changed, 515 insertions(+), 1251 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/34abbbe7/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RMInterface.java
----------------------------------------------------------------------
diff --git a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RMInterface.java
b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RMInterface.java
index a0e92ff..df74a45 100644
--- a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RMInterface.java
+++ b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RMInterface.java
@@ -163,8 +163,8 @@ public class RMInterface {
                  idServer.id(ID_TM_SERVER_TIMEOUT, startId);
                  if (LOG.isTraceEnabled()) LOG.trace("registerTransaction idServer.id returned:
" + startId.val);
               } catch (IdTmException exc) {
-                 LOG.error("registerTransaction: IdTm threw exception " + exc);
-                 throw new IOException("registerTransaction: IdTm threw exception " + exc);
+                 LOG.error("registerTransaction: IdTm threw exception " , exc);
+                 throw new IOException("registerTransaction: IdTm threw exception ", exc);
               }
               startIdVal = startId.val;
            }
@@ -224,63 +224,30 @@ public class RMInterface {
     public void createTable(HTableDescriptor desc, byte[][] keys, int numSplits, int keyLength,
long transID) throws IOException {
 
         if (LOG.isTraceEnabled()) LOG.trace("createTable ENTER: ");
-
-        try {
             byte[] lv_byte_desc = desc.toByteArray();
             byte[] lv_byte_tblname = desc.getNameAsString().getBytes();
             if (LOG.isTraceEnabled()) LOG.trace("createTable: htabledesc bytearray: " + lv_byte_desc
+ "desc in hex: " + Hex.encodeHexString(lv_byte_desc));
             createTableReq(lv_byte_desc, keys, numSplits, keyLength, transID, lv_byte_tblname);
-        } catch (Exception e) {
-            if (LOG.isTraceEnabled()) LOG.trace("Unable to createTable or convert table descriptor
to byte array " + e);
-            StringWriter sw = new StringWriter();
-            PrintWriter pw = new PrintWriter(sw);
-            e.printStackTrace(pw);
-            LOG.error("desc.ByteArray error " + sw.toString());
-            throw new IOException("createTable exception. Unable to create table.");
-        }
     }
 
     public void truncateTableOnAbort(String tblName, long transID) throws IOException {
         if (LOG.isTraceEnabled()) LOG.trace("truncateTableOnAbort ENTER: ");
-
-        try {
             byte[] lv_byte_tblName = tblName.getBytes();
             truncateOnAbortReq(lv_byte_tblName, transID);
-        } catch (Exception e) {
-            if (LOG.isTraceEnabled()) LOG.trace("Unable to truncateTableOnAbort" + e);
-            StringWriter sw = new StringWriter();
-            PrintWriter pw = new PrintWriter(sw);
-            e.printStackTrace(pw);
-            LOG.error("truncateTableOnAbort error: " + sw.toString());
-            throw new IOException("truncateTableOnAbort exception. Unable to create table.");
-        }
     }
 
     public void dropTable(String tblName, long transID) throws IOException {
         if (LOG.isTraceEnabled()) LOG.trace("dropTable ENTER: ");
 
-        try {
             byte[] lv_byte_tblname = tblName.getBytes();
             dropTableReq(lv_byte_tblname, transID);
-        } catch (Exception e) {
-            if (LOG.isTraceEnabled()) LOG.trace("Unable to dropTable " + e);
-            StringWriter sw = new StringWriter();
-            PrintWriter pw = new PrintWriter(sw);
-            e.printStackTrace(pw);
-            LOG.error("dropTable error " + sw.toString());
-        }
     }
 
     public void alter(String tblName, Object[] tableOptions, long transID) throws IOException
{
         if (LOG.isTraceEnabled()) LOG.trace("alter ENTER: ");
 
-        try {
             byte[] lv_byte_tblname = tblName.getBytes();
             alterTableReq(lv_byte_tblname, tableOptions, transID);
-        } catch (Exception e) {
-            if (LOG.isTraceEnabled()) LOG.trace("Unable to alter table, exception: " + e);
-            throw new IOException("alter exception. Unable to create table.");
-        }
     }   
 
     static public void clearTransactionStates(final long transactionID) {
@@ -294,13 +261,7 @@ public class RMInterface {
     static public synchronized void unregisterTransaction(final long transactionID) {
       TransactionState ts = null;
       if (LOG.isTraceEnabled()) LOG.trace("Enter unregisterTransaction txid: " + transactionID);
-      try {
         ts = mapTransactionStates.remove(transactionID);
-      } catch (Exception e) {
-        LOG.warn("Ignoring exception. mapTransactionStates.remove for transid " + transactionID
+ 
-                 " failed with exception " + e);
-        return;
-      }
       if (ts == null) {
         LOG.warn("mapTransactionStates.remove did not find transid " + transactionID);
       }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/34abbbe7/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RetryTransactionException.java
----------------------------------------------------------------------
diff --git a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RetryTransactionException.java
b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RetryTransactionException.java
new file mode 100644
index 0000000..e767bb3
--- /dev/null
+++ b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RetryTransactionException.java
@@ -0,0 +1,54 @@
+/**
+* @@@ START COPYRIGHT @@@
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+* @@@ END COPYRIGHT @@@
+**/
+
+package org.apache.hadoop.hbase.client.transactional;
+
+import java.io.IOException;
+/**
+ * Thrown if a region server is passed an unknown transaction id
+ */
+public class RetryTransactionException extends IOException {
+
+  private static final long serialVersionUID = 698575374929591089L;
+
+  /** constructor */
+  public RetryTransactionException() {
+    super();
+  }
+
+  /**
+   * Constructor
+   * @param s message
+   */
+  public RetryTransactionException(String s) {
+    super(s);
+  }
+
+  /**
+   * Constructor
+   * @param s message
+   */
+  public RetryTransactionException(String s, Throwable t) {
+    super(s, t);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/34abbbe7/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RollbackUnsuccessfulException.java
----------------------------------------------------------------------
diff --git a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RollbackUnsuccessfulException.java
b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RollbackUnsuccessfulException.java
new file mode 100644
index 0000000..fbf8d6d
--- /dev/null
+++ b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/RollbackUnsuccessfulException.java
@@ -0,0 +1,62 @@
+/**
+* @@@ START COPYRIGHT @@@
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+* @@@ END COPYRIGHT @@@
+**/
+
+package org.apache.hadoop.hbase.client.transactional;
+
+import java.io.IOException;
+
+/** Thrown when a transaction cannot be committed. 
+ * 
+ */
+public class RollbackUnsuccessfulException extends IOException {
+
+  private static final long serialVersionUID = 7062921444531109202L;
+
+  /** Default Constructor */
+  public RollbackUnsuccessfulException() {
+    super();
+  }
+
+  /**
+   * @param arg0 message
+   * @param arg1 cause
+   */
+  public RollbackUnsuccessfulException(String arg0, Throwable arg1) {
+    super(arg0, arg1);
+  }
+
+  /**
+   * @param arg0 message
+   */
+  public RollbackUnsuccessfulException(String arg0) {
+    super(arg0);
+  }
+
+  /**
+   * @param arg0 cause
+   */
+  public RollbackUnsuccessfulException(Throwable arg0) {
+    super(arg0);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/34abbbe7/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/SsccTransactionalTable.java
----------------------------------------------------------------------
diff --git a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/SsccTransactionalTable.java
b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/SsccTransactionalTable.java
index 31e6d1b..3735b63 100644
--- a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/SsccTransactionalTable.java
+++ b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/SsccTransactionalTable.java
@@ -157,13 +157,6 @@ public class SsccTransactionalTable extends HTable implements TransactionalTable
         super( tableName,connection, threadPool);       
     }
 
-    public void resetConnection() throws IOException {
-        if (LOG.isDebugEnabled()) LOG.debug("Resetting connection for " + this.getTableDescriptor().getTableName());
-        HConnection conn = this.getConnection();
-        conn = HConnectionManager.createConnection(this.getConfiguration());
-    }
-
-
     private void addLocation(final TransactionState transactionState, HRegionLocation location)
{
       if (LOG.isTraceEnabled()) LOG.trace("addLocation ENTRY");
       if (transactionState.addRegion(location)){
@@ -215,8 +208,7 @@ public class SsccTransactionalTable extends HTable implements TransactionalTable
           try {
             result = super.coprocessorService(SsccRegionService.class, get.getRow(), get.getRow(),
callable);
           } catch (Throwable e) {
-            e.printStackTrace();
-            throw new IOException("ERROR while calling coprocessor get");
+            throw new IOException("ERROR while calling coprocessor get", e);
           }            
           Collection<SsccGetTransactionalResponse> results = result.values();
           // Should only be one result, if more than one. Can't handle.
@@ -275,12 +267,8 @@ public class SsccTransactionalTable extends HTable implements TransactionalTable
             try {
               result = super.coprocessorService(SsccRegionService.class, row, row, callable);
 
-            } catch (ServiceException e) {
-              e.printStackTrace();
-              throw new IOException();
             } catch (Throwable t) {
-              t.printStackTrace();
-              throw new IOException();
+              throw new IOException("ERROR while calling coprocessor delete ",t);
             } 
             Collection<SsccDeleteTransactionalResponse> results = result.values();
             //GetTransactionalResponse[] resultArray = (GetTransactionalResponse[]) results.toArray();
@@ -342,8 +330,7 @@ public class SsccTransactionalTable extends HTable implements TransactionalTable
         try {
           result = super.coprocessorService(SsccRegionService.class, put.getRow(), put.getRow(),
callable);
         } catch (Throwable e) {
-          e.printStackTrace();
-          throw new IOException("ERROR while calling coprocessor put " + e);
+          throw new IOException("ERROR while calling coprocessor put ", e);
         }
         Collection<SsccPutTransactionalResponse> results = result.values();
         SsccPutTransactionalResponse[] resultArray = new SsccPutTransactionalResponse[results.size()];

@@ -425,8 +412,7 @@ public class SsccTransactionalTable extends HTable implements TransactionalTable
       try {
         result = super.coprocessorService(SsccRegionService.class, delete.getRow(), delete.getRow(),
callable);
       } catch (Throwable e) {
-        e.printStackTrace();
-        throw new IOException("ERROR while calling coprocessor checkAndDelete");
+        throw new IOException("ERROR while calling coprocessor checkAndDelete", e);
       }
 
       Collection<SsccCheckAndDeleteResponse> results = result.values();
@@ -504,11 +490,7 @@ if (LOG.isTraceEnabled()) LOG.trace("checkAndPut, seting request startid:
" + tr
       try {
          result = super.coprocessorService(SsccRegionService.class, put.getRow(), put.getRow(),
callable);
       } catch (Throwable e) {
-          StringWriter sw = new StringWriter();
-          PrintWriter pw = new PrintWriter(sw);
-          e.printStackTrace(pw);
-          //sw.toString();
-        throw new IOException("ERROR while calling coprocessor checkAndPut" + sw.toString());
+        throw new IOException("ERROR while calling coprocessor checkAndPut", e);
       }
       Collection<SsccCheckAndPutResponse> results = result.values();
       // Should only be one result, if more than one. Can't handle.
@@ -581,8 +563,7 @@ if (LOG.isTraceEnabled()) LOG.trace("checkAndPut, seting request startid:
" + tr
                                                    entry.getValue().get(0).getRow(),
                                                    callable);
  	      } catch (Throwable e) {
- 	        e.printStackTrace();
-	        throw new IOException("ERROR while calling coprocessor delete");
+	        throw new IOException("ERROR while calling coprocessor delete", e);
  	      }
 	      if(result.size() > 1) {
              LOG.error("result size for multiple delete:" + result.size());
@@ -660,8 +641,7 @@ if (LOG.isTraceEnabled()) LOG.trace("checkAndPut, seting request startid:
" + tr
                                           entry.getValue().get(0).getRow(),
                                           callable);
       } catch (Throwable e) {
-        e.printStackTrace();
-        throw new IOException("ERROR while calling coprocessor put");
+        throw new IOException("ERROR while calling coprocessor put", e);
       }
       Collection<SsccPutMultipleTransactionalResponse> results = result.values();
       SsccPutMultipleTransactionalResponse[] resultArray = new SsccPutMultipleTransactionalResponse[results.size()];

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/34abbbe7/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TmDDL.java
----------------------------------------------------------------------
diff --git a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TmDDL.java
b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TmDDL.java
index d0922e5..783b70c 100644
--- a/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TmDDL.java
+++ b/core/sqf/src/seatrans/hbase-trx/src/main/java/org/apache/hadoop/hbase/client/transactional/TmDDL.java
@@ -103,7 +103,7 @@ public class TmDDL {
       table = new HTable(config, tablename);
    }
 
-   public void putRow(final long transid, final String Operation, final String tableName)
throws Exception {
+   public void putRow(final long transid, final String Operation, final String tableName)
throws IOException {
 
         long threadId = Thread.currentThread().getId();
         if (LOG.isTraceEnabled()) LOG.trace("TmDDL putRow Operation, TxID: " + transid +
"Thread ID:" + threadId 
@@ -116,14 +116,7 @@ public class TmDDL {
 
         //Retrieve the row if it exists so we can append.
         Get g = new Get(Bytes.toBytes(transid));
-        try {
-                r = table.get(g);
-        }
-        catch(Exception e){
-          LOG.error("TmDDL putRow method, Get Exception TxID:" + transid + "Exception:" +
e);
-          throw e;
-        }
-
+        r = table.get(g);
         //Check and set State
         if(! r.isEmpty())
         {
@@ -216,24 +209,11 @@ public class TmDDL {
 
         }
 
-        try {
             synchronized (tablePutLock) {
-            try {
                   if (LOG.isTraceEnabled()) LOG.trace("TmDDL table.put, TxID: " + transid
+ "Put :" + p );
 
                   table.put(p);
-               }
-               catch (Exception e2){
-                  //Avoiding logging within a lock. Throwing Exception.
-                  throw e2;
-               }
             } // End global synchronization
-         }
-         catch (Exception e) {
-             //create record of the exception
-            LOG.error("TmDDL tablePutLock or Table.put Exception, TxID: " + transid + "Exception:"
+ e);
-            throw e;
-         }
       if (LOG.isTraceEnabled()) LOG.trace("TmDDL putRow exit, TxId:" + transid);
    }
 


Mime
View raw message