You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2018/04/24 02:18:57 UTC

hive git commit: HIVE-19263 : Improve ugly exception handling in HiveMetaStore (Igor Kryvenko via Vihang K)

Repository: hive
Updated Branches:
  refs/heads/master cce0e3777 -> 211baae45


HIVE-19263 : Improve ugly exception handling in HiveMetaStore (Igor Kryvenko via Vihang K)

Signed-off-by: Ashutosh Chauhan <ha...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/211baae4
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/211baae4
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/211baae4

Branch: refs/heads/master
Commit: 211baae45f76722f354a4c29edb83de90c549f0e
Parents: cce0e37
Author: Igor Kryvenko <kr...@gmail.com>
Authored: Mon Apr 23 19:18:18 2018 -0700
Committer: Ashutosh Chauhan <ha...@apache.org>
Committed: Mon Apr 23 19:18:18 2018 -0700

----------------------------------------------------------------------
 .../hadoop/hive/metastore/HiveMetaStore.java    | 493 +++++++------------
 1 file changed, 186 insertions(+), 307 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/211baae4/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
index cd50e1b..f3c2d8b 100644
--- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
@@ -1257,17 +1257,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         }
         create_database_core(getMS(), db);
         success = true;
+      } catch (MetaException | InvalidObjectException | AlreadyExistsException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else if (e instanceof AlreadyExistsException) {
-          throw (AlreadyExistsException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("create_database", success, ex);
       }
@@ -1591,13 +1586,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         } else {
           ret = getMS().getDatabases(parsedDbNamed[CAT_NAME], parsedDbNamed[DB_NAME]);
         }
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_databases", ret != null, ex);
       }
@@ -1639,17 +1633,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       try {
         create_type_core(getMS(), type);
         success = true;
+      } catch (MetaException | InvalidObjectException | AlreadyExistsException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else if (e instanceof AlreadyExistsException) {
-          throw (AlreadyExistsException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("create_type", success, ex);
       }
@@ -1944,17 +1933,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         LOG.warn("create_table_with_environment_context got ", e);
         ex = e;
         throw new InvalidObjectException(e.getMessage());
+      } catch (MetaException | InvalidObjectException | AlreadyExistsException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else if (e instanceof AlreadyExistsException) {
-          throw (AlreadyExistsException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("create_table", success, ex, tbl.getTableName());
       }
@@ -1978,17 +1962,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       } catch (NoSuchObjectException e) {
         ex = e;
         throw new InvalidObjectException(e.getMessage());
+      } catch (MetaException | InvalidObjectException | AlreadyExistsException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else if (e instanceof AlreadyExistsException) {
-          throw (AlreadyExistsException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("create_table", success, ex, tbl.getTableName());
       }
@@ -2019,13 +1998,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       } catch (NoSuchObjectException e) {
         ex = e;
         throw new InvalidObjectException(e.getMessage());
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         if (!success) {
           ms.rollbackTransaction();
@@ -2070,15 +2048,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           }
         }
         success = ms.commitTransaction();
+      } catch (MetaException | InvalidObjectException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         if (!success) {
           ms.rollbackTransaction();
@@ -2122,15 +2097,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           }
         }
         success = ms.commitTransaction();
+      } catch (MetaException | InvalidObjectException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         if (!success) {
           ms.rollbackTransaction();
@@ -2174,15 +2146,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           }
         }
         success = ms.commitTransaction();
+      } catch (MetaException | InvalidObjectException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         if (!success) {
           ms.rollbackTransaction();
@@ -2226,15 +2195,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           }
         }
         success = ms.commitTransaction();
+      } catch (MetaException | InvalidObjectException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         if (!success) {
           ms.rollbackTransaction();
@@ -2279,15 +2245,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           }
         }
         success = ms.commitTransaction();
+      } catch (MetaException | InvalidObjectException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         if (!success) {
           ms.rollbackTransaction();
@@ -2331,15 +2294,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           }
         }
         success = ms.commitTransaction();
+      } catch (MetaException | InvalidObjectException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         if (!success) {
           ms.rollbackTransaction();
@@ -2750,14 +2710,10 @@ public class HiveMetaStore extends ThriftHiveMetastore {
             tableName, tbl, partNames);
       } catch (IOException e) {
         throw new MetaException(e.getMessage());
+      } catch (MetaException | NoSuchObjectException e) {
+        throw e;
       } catch (Exception e) {
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof NoSuchObjectException) {
-          throw (NoSuchObjectException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       }
     }
 
@@ -2930,17 +2886,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
                 "insert-only tables", "get_table_req");
           }
         }
+      } catch (MetaException | InvalidOperationException | UnknownDBException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidOperationException) {
-          throw (InvalidOperationException) e;
-        } else if (e instanceof UnknownDBException) {
-          throw (UnknownDBException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_multi_table", tables != null, ex, join(tableNames, ","));
       }
@@ -2993,17 +2944,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           throw new InvalidOperationException(filter + " cannot apply null filter");
         }
         tables = getMS().listTableNamesByFilter(parsedDbName[CAT_NAME], parsedDbName[DB_NAME], filter, maxTables);
+      } catch (MetaException | InvalidOperationException | UnknownDBException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidOperationException) {
-          throw (InvalidOperationException) e;
-        } else if (e instanceof UnknownDBException) {
-          throw (UnknownDBException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_table_names_by_filter", tables != null, ex, join(tables, ","));
       }
@@ -3144,17 +3090,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = append_partition_common(getMS(), parsedDbName[CAT_NAME], parsedDbName[DB_NAME], tableName, part_vals, envContext);
+      } catch (MetaException | InvalidObjectException | AlreadyExistsException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else if (e instanceof AlreadyExistsException) {
-          throw (AlreadyExistsException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("append_partition", ret != null, ex, tableName);
       }
@@ -3434,17 +3375,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         ret = add_partitions_core(getMS(), parts.get(0).getCatName(), parts.get(0).getDbName(),
             parts.get(0).getTableName(), parts, false).size();
         assert ret == parts.size();
+      } catch (MetaException | InvalidObjectException | AlreadyExistsException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else if (e instanceof AlreadyExistsException) {
-          throw (AlreadyExistsException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         String tableName = parts.get(0).getTableName();
         endFunction("add_partition", ret != null, ex, tableName);
@@ -3819,17 +3755,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = add_partition_core(getMS(), part, envContext);
+      } catch (MetaException | InvalidObjectException | AlreadyExistsException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else if (e instanceof AlreadyExistsException) {
-          throw (AlreadyExistsException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("add_partition", ret != null, ex, part != null ?  part.getTableName(): null);
       }
@@ -4671,13 +4602,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       try {
         ret = getMS().listPartitionNames(parsedDbName[CAT_NAME], parsedDbName[DB_NAME], tbl_name,
             max_parts);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_partition_names", ret != null, ex, tbl_name);
       }
@@ -4780,15 +4710,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       } catch (AlreadyExistsException e) {
         ex = e;
         throw new InvalidOperationException(e.getMessage());
+      } catch (MetaException | InvalidOperationException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidOperationException) {
-          throw (InvalidOperationException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("alter_partition", oldPart != null, ex, tbl_name);
       }
@@ -4854,15 +4781,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       } catch (AlreadyExistsException e) {
         ex = e;
         throw new InvalidOperationException(e.getMessage());
+      } catch (MetaException | InvalidOperationException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidOperationException) {
-          throw (InvalidOperationException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("alter_partition", oldParts != null, ex, tbl_name);
       }
@@ -4940,15 +4864,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         // thrown when the table to be altered does not exist
         ex = e;
         throw new InvalidOperationException(e.getMessage());
+      } catch (MetaException | InvalidOperationException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else if (e instanceof InvalidOperationException) {
-          throw (InvalidOperationException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("alter_table", success, ex, name);
       }
@@ -4964,13 +4885,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       String[] parsedDbName = parseDbName(dbname, conf);
       try {
         ret = getMS().getTables(parsedDbName[CAT_NAME], parsedDbName[DB_NAME], pattern);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_tables", ret != null, ex);
       }
@@ -4987,13 +4907,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       String[] parsedDbName = parseDbName(dbname, conf);
       try {
         ret = getMS().getTables(parsedDbName[CAT_NAME], parsedDbName[DB_NAME], pattern, TableType.valueOf(tableType));
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_tables_by_type", ret != null, ex);
       }
@@ -5010,13 +4929,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       String[] parsedDbName = parseDbName(dbname, conf);
       try {
         ret = getMS().getMaterializedViewsForRewriting(parsedDbName[CAT_NAME], parsedDbName[DB_NAME]);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_materialized_views_for_rewriting", ret != null, ex);
       }
@@ -5032,13 +4950,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       String[] parsedDbName = parseDbName(dbname, conf);
       try {
         ret = getMS().getAllTables(parsedDbName[CAT_NAME], parsedDbName[DB_NAME]);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_all_tables", ret != null, ex);
       }
@@ -5079,15 +4996,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           StorageSchemaReader schemaReader = getStorageSchemaReader();
           ret = schemaReader.readSchema(tbl, envContext, getConf());
         }
+      } catch (UnknownTableException | MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof UnknownTableException) {
-          throw (UnknownTableException) e;
-        } else if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         if (orgHiveLoader != null) {
           conf.setClassLoader(orgHiveLoader);
@@ -5181,19 +5095,14 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         }
         success = true;
         return fieldSchemas;
+      } catch (UnknownDBException | UnknownTableException | MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof UnknownDBException) {
-          throw (UnknownDBException) e;
-        } else if (e instanceof UnknownTableException) {
-          throw (UnknownTableException) e;
-        } else if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          MetaException me = new MetaException(e.toString());
-          me.initCause(e);
-          throw me;
-        }
+        MetaException me = new MetaException(e.toString());
+        me.initCause(e);
+        throw me;
       } finally {
         endFunction("get_schema_with_environment_context", success, ex, tableName);
       }
@@ -5242,13 +5151,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         }
         success = true;
         return toReturn;
+      } catch (ConfigValSecurityException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof ConfigValSecurityException) {
-          throw (ConfigValSecurityException) e;
-        } else {
-          throw new TException(e);
-        }
+        throw new TException(e);
       } finally {
         endFunction("get_config_value", success, ex);
       }
@@ -5344,17 +5252,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         RawStore ms = getMS();
         List<String> partVals = getPartValsFromName(ms, parsedDbName[CAT_NAME], parsedDbName[DB_NAME], tbl_name, part_name);
         ret = append_partition_common(ms, parsedDbName[CAT_NAME], parsedDbName[DB_NAME], tbl_name, partVals, env_context);
+      } catch (InvalidObjectException | AlreadyExistsException | MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof InvalidObjectException) {
-          throw (InvalidObjectException) e;
-        } else if (e instanceof AlreadyExistsException) {
-          throw (AlreadyExistsException) e;
-        } else if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("append_partition_by_name", ret != null, ex, tbl_name);
       }
@@ -6545,13 +6448,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = getMS().addToken(token_identifier, delegation_token);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("add_token", ret == true, ex);
       }
@@ -6565,13 +6467,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = getMS().removeToken(token_identifier);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("remove_token", ret == true, ex);
       }
@@ -6585,13 +6486,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = getMS().getToken(token_identifier);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_token", ret != null, ex);
       }
@@ -6606,13 +6506,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = getMS().getAllTokenIdentifiers();
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_all_token_identifiers.", ex == null, ex);
       }
@@ -6626,13 +6525,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = getMS().addMasterKey(key);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("add_master_key.", ex == null, ex);
       }
@@ -6645,13 +6543,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         getMS().updateMasterKey(seq_number, key);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("update_master_key.", ex == null, ex);
       }
@@ -6664,13 +6561,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       boolean ret;
       try {
         ret = getMS().removeMasterKey(key_seq);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("remove_master_key.", ex == null, ex);
       }
@@ -6684,13 +6580,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       String [] ret = null;
       try {
         ret = getMS().getMasterKeys();
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_master_keys.", ret != null, ex);
       }
@@ -6729,20 +6624,14 @@ public class HiveMetaStore extends ThriftHiveMetastore {
         for (MetaStoreEventListener listener : listeners) {
           listener.onLoadPartitionDone(new LoadPartitionDoneEvent(true, tbl, partName, this));
         }
+      } catch (UnknownTableException | InvalidPartitionException | MetaException e) {
+        ex = e;
+        LOG.error("Exception caught in mark partition event ", e);
+        throw e;
       } catch (Exception original) {
         ex = original;
         LOG.error("Exception caught in mark partition event ", original);
-        if (original instanceof UnknownTableException) {
-          throw (UnknownTableException) original;
-        } else if (original instanceof UnknownPartitionException) {
-          throw (UnknownPartitionException) original;
-        } else if (original instanceof InvalidPartitionException) {
-          throw (InvalidPartitionException) original;
-        } else if (original instanceof MetaException) {
-          throw (MetaException) original;
-        } else {
-          throw newMetaException(original);
-        }
+        throw newMetaException(original);
       } finally {
         if (!success) {
           ms.rollbackTransaction();
@@ -6764,20 +6653,14 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       try {
         ret = getMS().isPartitionMarkedForEvent(parsedDbName[CAT_NAME], parsedDbName[DB_NAME],
             tbl_name, partName, evtType);
+      } catch (UnknownTableException | UnknownPartitionException | InvalidPartitionException | MetaException e) {
+        ex = e;
+        LOG.error("Exception caught for isPartitionMarkedForEvent ", e);
+        throw e;
       } catch (Exception original) {
-        LOG.error("Exception caught for isPartitionMarkedForEvent ",original);
+        LOG.error("Exception caught for isPartitionMarkedForEvent ", original);
         ex = original;
-        if (original instanceof UnknownTableException) {
-          throw (UnknownTableException) original;
-        } else if (original instanceof UnknownPartitionException) {
-          throw (UnknownPartitionException) original;
-        } else if (original instanceof InvalidPartitionException) {
-          throw (InvalidPartitionException) original;
-        } else if (original instanceof MetaException) {
-          throw (MetaException) original;
-        } else {
-          throw newMetaException(original);
-        }
+        throw newMetaException(original);
       } finally {
                 endFunction("isPartitionMarkedForEvent", ret != null, ex, tbl_name);
       }
@@ -6805,15 +6688,15 @@ public class HiveMetaStore extends ThriftHiveMetastore {
           ret = MetaStoreUtils.partitionNameHasValidCharacters(part_vals,
               partitionValidationPattern);
         }
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException)e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
+      } finally {
+        endFunction("partition_name_has_valid_characters", true, ex);
       }
-      endFunction("partition_name_has_valid_characters", true, ex);
       return ret;
     }
 
@@ -7742,13 +7625,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = getMS().getUniqueConstraints(catName, db_name, tbl_name);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_unique_constraints", ret != null, ex, tbl_name);
       }
@@ -7766,13 +7648,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = getMS().getNotNullConstraints(catName, db_name, tbl_name);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_not_null_constraints", ret != null, ex, tbl_name);
       }
@@ -7790,13 +7671,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = getMS().getDefaultConstraints(catName, db_name, tbl_name);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_default_constraints", ret != null, ex, tbl_name);
       }
@@ -7814,13 +7694,12 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       Exception ex = null;
       try {
         ret = getMS().getCheckConstraints(catName, db_name, tbl_name);
+      } catch (MetaException e) {
+        ex = e;
+        throw e;
       } catch (Exception e) {
         ex = e;
-        if (e instanceof MetaException) {
-          throw (MetaException) e;
-        } else {
-          throw newMetaException(e);
-        }
+        throw newMetaException(e);
       } finally {
         endFunction("get_check_constraints", ret != null, ex, tbl_name);
       }