tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [6/8] tajo git commit: TAJO-1670: Refactor client errors and exceptions.
Date Mon, 20 Jul 2015 11:43:55 GMT
http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
index b1410dd..6a3fc16 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
@@ -23,14 +23,13 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.protobuf.RpcController;
 import com.google.protobuf.ServiceException;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.service.AbstractService;
 import org.apache.tajo.TajoConstants;
 import org.apache.tajo.annotation.ThreadSafe;
-import org.apache.tajo.catalog.CatalogProtocol.CatalogProtocolService;
+import org.apache.tajo.catalog.CatalogProtocol.*;
 import org.apache.tajo.catalog.dictionary.InfoSchemaMetadataDictionary;
 import org.apache.tajo.catalog.exception.*;
 import org.apache.tajo.catalog.proto.CatalogProtos.*;
@@ -40,12 +39,15 @@ import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.common.TajoDataTypes.DataType;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.conf.TajoConf.ConfVars;
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.exception.ReturnStateUtil;
+import org.apache.tajo.exception.TajoInternalError;
 import org.apache.tajo.rpc.BlockingRpcServer;
-import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.BoolProto;
 import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.NullProto;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringListResponse;
 import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringProto;
 import org.apache.tajo.util.NetUtils;
-import org.apache.tajo.util.ProtoUtil;
 import org.apache.tajo.util.TUtil;
 
 import java.io.IOException;
@@ -58,8 +60,9 @@ import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceCommand;
-import static org.apache.tajo.catalog.proto.CatalogProtos.FunctionType.*;
-import static org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringListProto;
+import static org.apache.tajo.exception.ExceptionUtil.printStackTraceIfError;
+import static org.apache.tajo.exception.ReturnStateUtil.*;
+import static org.apache.tajo.function.FunctionUtil.buildSimpleFunctionSignature;
 
 /**
  * This class provides the catalog service. The catalog service enables clients
@@ -87,16 +90,6 @@ public class CatalogServer extends AbstractService {
   private String bindAddressStr;
   final CatalogProtocolHandler handler;
 
-  // Server status variables
-  private volatile boolean stopped = false;
-  @SuppressWarnings("unused")
-  private volatile boolean isOnline = false;
-
-  private static BoolProto BOOL_TRUE = BoolProto.newBuilder().
-      setValue(true).build();
-  private static BoolProto BOOL_FALSE = BoolProto.newBuilder().
-      setValue(false).build();
-
   private Collection<FunctionDesc> builtingFuncs;
 
   public CatalogServer() throws IOException {
@@ -123,7 +116,7 @@ public class CatalogServer extends AbstractService {
       if (conf instanceof TajoConf) {
         this.conf = (TajoConf) conf;
       } else {
-        throw new CatalogException("conf must be a TajoConf instance");
+        throw new TajoInternalError("conf must be a TajoConf instance");
       }
 
       Class<?> storeClass = this.conf.getClass(CatalogConstants.STORE_CLASS, DerbyStore.class);
@@ -137,7 +130,7 @@ public class CatalogServer extends AbstractService {
       initBuiltinFunctions(builtingFuncs);
     } catch (Throwable t) {
       LOG.error("CatalogServer initialization failed", t);
-      throw new CatalogException(t);
+      throw new TajoInternalError(t);
     }
 
     super.serviceInit(conf);
@@ -186,7 +179,7 @@ public class CatalogServer extends AbstractService {
       conf.setVar(ConfVars.CATALOG_ADDRESS, bindAddressStr);
     } catch (Exception e) {
       LOG.error("CatalogServer startup failed", e);
-      throw new CatalogException(e);
+      throw new TajoInternalError(e);
     }
 
     LOG.info("Catalog Server startup (" + bindAddressStr + ")");
@@ -219,116 +212,138 @@ public class CatalogServer extends AbstractService {
   public class CatalogProtocolHandler implements CatalogProtocolService.BlockingInterface {
 
     @Override
-    public BoolProto createTablespace(RpcController controller, CreateTablespaceRequest request) throws ServiceException {
+    public ReturnState createTablespace(RpcController controller, CreateTablespaceRequest request) {
+
       final String tablespaceName = request.getTablespaceName();
       final String uri = request.getTablespaceUri();
 
       wlock.lock();
       try {
         if (store.existTablespace(tablespaceName)) {
-          throw new AlreadyExistsDatabaseException(tablespaceName);
+          throw new DuplicateDatabaseException(tablespaceName);
         }
 
         store.createTablespace(tablespaceName, uri);
         LOG.info(String.format("tablespace \"%s\" (%s) is created", tablespaceName, uri));
-        return ProtoUtil.TRUE;
 
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+        return OK;
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
       } finally {
         wlock.unlock();
       }
     }
 
     @Override
-    public BoolProto dropTablespace(RpcController controller, StringProto request) throws ServiceException {
+    public ReturnState dropTablespace(RpcController controller, StringProto request) {
       String tablespaceName = request.getValue();
 
       wlock.lock();
       try {
         if (tablespaceName.equals(TajoConstants.DEFAULT_TABLESPACE_NAME)) {
-          throw new CatalogException("default tablespace cannot be dropped.");
+          throw new CatalogException(ResultCode.INSUFFICIENT_PRIVILEGE, "drop to default tablespace");
         }
 
         if (!store.existTablespace(tablespaceName)) {
-          throw new NoSuchTablespaceException(tablespaceName);
+          throw new UndefinedTablespaceException(tablespaceName);
         }
 
         store.dropTablespace(tablespaceName);
-        return ProtoUtil.TRUE;
 
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
       } finally {
         wlock.unlock();
       }
     }
 
     @Override
-    public BoolProto existTablespace(RpcController controller, StringProto request) throws ServiceException {
-      String tablespaceName = request.getValue();
+    public ReturnState existTablespace(RpcController controller, StringProto request) {
+      String spaceName = request.getValue();
 
       rlock.lock();
       try {
-        if (store.existTablespace(tablespaceName)) {
-          return ProtoUtil.TRUE;
+        if (store.existTablespace(spaceName)) {
+          return OK;
         } else {
-          return ProtoUtil.FALSE;
+          return errUndefinedTablespace(spaceName);
         }
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public StringListProto getAllTablespaceNames(RpcController controller, NullProto request) throws ServiceException {
+    public StringListResponse getAllTablespaceNames(RpcController controller, NullProto request) throws ServiceException {
       rlock.lock();
       try {
-        return ProtoUtil.convertStrings(store.getAllDatabaseNames());
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+        return StringListResponse.newBuilder()
+            .setState(OK)
+            .addAllValues(store.getAllDatabaseNames())
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnFailedStringList(t);
       } finally {
         rlock.unlock();
       }
     }
     
     @Override
-    public GetTablespacesProto getAllTablespaces(RpcController controller, NullProto request) throws ServiceException {
+    public GetTablespaceListResponse getAllTablespaces(RpcController controller, NullProto request)
+        throws ServiceException {
       rlock.lock();
       try {
-        return GetTablespacesProto.newBuilder().addAllTablespace(store.getTablespaces()).build();
-      } catch (Exception e) {
-        throw new ServiceException(e);
+        return GetTablespaceListResponse.newBuilder()
+            .setState(OK)
+            .addAllTablespace(store.getTablespaces())
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        throw new ServiceException(t);
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public TablespaceProto getTablespace(RpcController controller, StringProto request) throws ServiceException {
+    public GetTablespaceResponse getTablespace(RpcController controller, StringProto request) {
       rlock.lock();
+
       try {
-        return store.getTablespace(request.getValue());
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+
+        return GetTablespaceResponse.newBuilder()
+            .setState(OK)
+            .setTablespace(store.getTablespace(request.getValue()))
+            .build();
+
+      } catch (Throwable t) {
+
+        printStackTraceIfError(LOG, t);
+        return GetTablespaceResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public BoolProto alterTablespace(RpcController controller, AlterTablespaceProto request) throws ServiceException {
+    public ReturnState alterTablespace(RpcController controller, AlterTablespaceProto request) {
       wlock.lock();
       try {
         if (!store.existTablespace(request.getSpaceName())) {
-          throw new NoSuchTablespaceException(request.getSpaceName());
+          throw new UndefinedTablespaceException(request.getSpaceName());
         }
 
         if (request.getCommandList().size() > 0) {
@@ -346,191 +361,231 @@ public class CatalogServer extends AbstractService {
         }
 
         store.alterTablespace(request);
-        return ProtoUtil.TRUE;
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         wlock.unlock();
       }
     }
 
     @Override
-    public BoolProto createDatabase(RpcController controller, CreateDatabaseRequest request) throws ServiceException {
+    public ReturnState createDatabase(RpcController controller, CreateDatabaseRequest request) {
       String databaseName = request.getDatabaseName();
       String tablespaceName = request.getTablespaceName();
 
+      // check virtual database manually because catalog actually does not contain them.
       if (metaDictionary.isSystemDatabase(databaseName)) {
-        throw new ServiceException(databaseName + " is a system database name.");
+        return errDuplicateDatabase(databaseName);
       }
       
       wlock.lock();
       try {
         if (store.existDatabase(databaseName)) {
-          throw new AlreadyExistsDatabaseException(databaseName);
+          return errDuplicateDatabase(databaseName);
         }
 
         store.createDatabase(databaseName, tablespaceName);
         LOG.info(String.format("database \"%s\" is created", databaseName));
-        return ProtoUtil.TRUE;
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         wlock.unlock();
       }
     }
 
     @Override
-    public BoolProto updateTableStats(RpcController controller, UpdateTableStatsProto proto) throws
-      ServiceException {
+    public ReturnState updateTableStats(RpcController controller, UpdateTableStatsProto proto) {
+
       wlock.lock();
+
       try {
         String [] split = CatalogUtil.splitTableName(proto.getTableName());
         if (!store.existTable(split[0], split[1])) {
-          throw new NoSuchTableException(proto.getTableName());
+          return errDuplicateTable(proto.getTableName());
         }
         store.updateTableStats(proto);
-      } catch (Exception e) {
-        LOG.error(e.getMessage(), e);
-        return BOOL_FALSE;
+
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         wlock.unlock();
-        LOG.info("Table " + proto.getTableName() + " is updated in the catalog ("
-          + bindAddressStr + ")");
       }
-      return BOOL_TRUE;
     }
 
     @Override
-    public BoolProto alterTable(RpcController controller, AlterTableDescProto proto) throws ServiceException {
+    public ReturnState alterTable(RpcController controller, AlterTableDescProto proto) {
       String [] split = CatalogUtil.splitTableName(proto.getTableName());
       
       if (metaDictionary.isSystemDatabase(split[0])) {
-        throw new ServiceException(split[0] + " is a system database.");
+        return errInsufficientPrivilege("alter a table in database '" + split[0] + "'");
       }
       
       wlock.lock();
+
       try {
         if (!store.existTable(split[0], split[1])) {
-          throw new NoSuchTableException(proto.getTableName());
+          return errUndefinedTable(proto.getTableName());
         }
         store.alterTable(proto);
-      } catch (Exception e) {
-        LOG.error(e.getMessage(), e);
-        return BOOL_FALSE;
+
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         wlock.unlock();
-        LOG.info("Table " + proto.getTableName() + " is altered in the catalog ("
-            + bindAddressStr + ")");
       }
-      return BOOL_TRUE;
     }
 
     @Override
-    public BoolProto dropDatabase(RpcController controller, StringProto request) throws ServiceException {
+    public ReturnState dropDatabase(RpcController controller, StringProto request) {
       String databaseName = request.getValue();
       
       if (metaDictionary.isSystemDatabase(databaseName)) {
-        throw new ServiceException(databaseName + " is a system database.");
+        return errInsufficientPrivilege("drop a table in database '" + databaseName + "'");
       }
 
       wlock.lock();
       try {
         if (!store.existDatabase(databaseName)) {
-          throw new NoSuchDatabaseException(databaseName);
+          return errUndefinedDatabase(databaseName);
         }
 
         store.dropDatabase(databaseName);
-        return ProtoUtil.TRUE;
 
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
       } finally {
         wlock.unlock();
       }
     }
 
     @Override
-    public BoolProto existDatabase(RpcController controller, StringProto request) throws ServiceException {
-      String databaseName = request.getValue();
+    public ReturnState existDatabase(RpcController controller, StringProto request) {
+      String dbName = request.getValue();
 
-      if (!metaDictionary.isSystemDatabase(databaseName)) {
-        rlock.lock();
-        try {
-          if (store.existDatabase(databaseName)) {
-            return ProtoUtil.TRUE;
-          } else {
-            return ProtoUtil.FALSE;
-          }
-        } catch (Exception e) {
-          LOG.error(e);
-          throw new ServiceException(e);
-        } finally {
-          rlock.unlock();
+      if (metaDictionary.isSystemDatabase(dbName)) {
+        return OK;
+      }
+
+      rlock.lock();
+      try {
+        if (store.existDatabase(dbName)) {
+          return OK;
+        } else {
+          return errUndefinedDatabase(dbName);
         }
-      } else {
-        return ProtoUtil.TRUE;
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
+      } finally {
+        rlock.unlock();
       }
     }
 
     @Override
-    public StringListProto getAllDatabaseNames(RpcController controller, NullProto request) throws ServiceException {
+    public StringListResponse getAllDatabaseNames(RpcController controller, NullProto request) {
       rlock.lock();
       try {
-        StringListProto.Builder builder = StringListProto.newBuilder();
-        builder.addAllValues(store.getAllDatabaseNames());
-        builder.addValues(metaDictionary.getSystemDatabaseName());
-        return builder.build();
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+        return StringListResponse.newBuilder()
+            .setState(OK)
+            .addAllValues(store.getAllDatabaseNames())
+            .addValues(metaDictionary.getSystemDatabaseName())
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnFailedStringList(t);
+
       } finally {
         rlock.unlock();
       }
     }
     
     @Override
-    public GetDatabasesProto getAllDatabases(RpcController controller, NullProto request) throws ServiceException {
+    public GetDatabasesResponse getAllDatabases(RpcController controller, NullProto request) throws ServiceException {
       rlock.lock();
       try {
-        return GetDatabasesProto.newBuilder().addAllDatabase(store.getAllDatabases()).build();
-      } catch (Exception e) {
-        throw new ServiceException(e);
+        return GetDatabasesResponse.newBuilder()
+            .setState(OK)
+            .addAllDatabase(store.getAllDatabases())
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetDatabasesResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public TableDescProto getTableDesc(RpcController controller,
+    public TableResponse getTableDesc(RpcController controller,
                                        TableIdentifierProto request) throws ServiceException {
-      String databaseName = request.getDatabaseName();
-      String tableName = request.getTableName();
-
-      if (metaDictionary.isSystemDatabase(databaseName)){
-        return metaDictionary.getTableDesc(tableName);
+      String dbName = request.getDatabaseName();
+      String tbName = request.getTableName();
+
+      if (metaDictionary.isSystemDatabase(dbName)) {
+        return TableResponse.newBuilder()
+            .setState(OK)
+            .setTable(metaDictionary.getTableDesc(tbName))
+            .build();
       } else {
         rlock.lock();
         try {
           boolean contain;
 
-          contain = store.existDatabase(databaseName);
+          contain = store.existDatabase(dbName);
 
           if (contain) {
-            contain = store.existTable(databaseName, tableName);
+            contain = store.existTable(dbName, tbName);
             if (contain) {
-              return store.getTable(databaseName, tableName);
+              return TableResponse.newBuilder()
+                  .setState(OK)
+                  .setTable(store.getTable(dbName, tbName))
+                  .build();
             } else {
-              throw new NoSuchTableException(tableName);
+              return TableResponse.newBuilder()
+                  .setState(errUndefinedTable(tbName))
+                  .build();
             }
           } else {
-            throw new NoSuchDatabaseException(databaseName);
+            return TableResponse.newBuilder()
+                .setState(errUndefinedDatabase(dbName))
+                .build();
           }
-        } catch (Exception e) {
-          LOG.error(e);
-          throw new ServiceException(e);
+
+        } catch (Throwable t) {
+          printStackTraceIfError(LOG, t);
+
+          return TableResponse.newBuilder()
+              .setState(returnError(t))
+              .build();
+
         } finally {
           rlock.unlock();
         }
@@ -538,24 +593,29 @@ public class CatalogServer extends AbstractService {
     }
 
     @Override
-    public StringListProto getAllTableNames(RpcController controller, StringProto request)
-        throws ServiceException {
+    public StringListResponse getAllTableNames(RpcController controller, StringProto request) {
 
-      String databaseName = request.getValue();
+      String dbName = request.getValue();
+
+      if (metaDictionary.isSystemDatabase(dbName)) {
+
+        return returnStringList(metaDictionary.getAllSystemTables());
 
-      if (metaDictionary.isSystemDatabase(databaseName)) {
-        return ProtoUtil.convertStrings(metaDictionary.getAllSystemTables());
       } else {
         rlock.lock();
         try {
-          if (store.existDatabase(databaseName)) {
-            return ProtoUtil.convertStrings(store.getAllTableNames(databaseName));
+          if (store.existDatabase(dbName)) {
+            return returnStringList(store.getAllTableNames(dbName));
           } else {
-            throw new NoSuchDatabaseException(databaseName);
+            return StringListResponse.newBuilder()
+                .setState(errUndefinedDatabase(dbName))
+                .build();
           }
-        } catch (Exception e) {
-          LOG.error(e);
-          throw new ServiceException(e);
+
+        } catch (Throwable t) {
+          printStackTraceIfError(LOG, t);
+          return returnFailedStringList(t);
+
         } finally {
           rlock.unlock();
         }
@@ -575,166 +635,201 @@ public class CatalogServer extends AbstractService {
     }
 
     @Override
-    public BoolProto createTable(RpcController controller, TableDescProto request)throws ServiceException {
+    public ReturnState createTable(RpcController controller, TableDescProto request) {
 
-      String [] splitted =
-          CatalogUtil.splitFQTableName(request.getTableName());
+      String [] splitted = CatalogUtil.splitFQTableName(request.getTableName());
 
-      String databaseName = splitted[0];
-      String tableName = splitted[1];
+      String dbName = splitted[0];
+      String tbName = splitted[1];
 
-      if (metaDictionary.isSystemDatabase(databaseName)) {
-        throw new ServiceException(databaseName + " is a system database.");
+      if (metaDictionary.isSystemDatabase(dbName)) {
+        return errInsufficientPrivilege("create a table in database '" + dbName + "'");
       }
       
       wlock.lock();
       try {
 
-        boolean contain = store.existDatabase(databaseName);
+        boolean contain = store.existDatabase(dbName);
 
         if (contain) {
-          if (store.existTable(databaseName, tableName)) {
-            throw new AlreadyExistsTableException(databaseName, tableName);
+          if (store.existTable(dbName, tbName)) {
+            return errDuplicateTable(tbName);
           }
 
           store.createTable(request);
           LOG.info(String.format("relation \"%s\" is added to the catalog (%s)",
-              CatalogUtil.getCanonicalTableName(databaseName, tableName), bindAddressStr));
+              CatalogUtil.getCanonicalTableName(dbName, tbName), bindAddressStr));
         } else {
-          throw new NoSuchDatabaseException(databaseName);
+          return errUndefinedDatabase(dbName);
         }
-      } catch (Exception e) {
-        LOG.error(e.getMessage(), e);
-        return ProtoUtil.FALSE;
+
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         wlock.unlock();
       }
-
-      return ProtoUtil.TRUE;
     }
 
     @Override
-    public BoolProto dropTable(RpcController controller, TableIdentifierProto request) throws ServiceException {
+    public ReturnState dropTable(RpcController controller, TableIdentifierProto request) throws ServiceException {
 
-      String databaseName = request.getDatabaseName();
-      String tableName = request.getTableName();
+      String dbName = request.getDatabaseName();
+      String tbName = request.getTableName();
       
-      if (metaDictionary.isSystemDatabase(databaseName)) {
-        throw new ServiceException(databaseName + " is a system database.");
+      if (metaDictionary.isSystemDatabase(dbName)) {
+        return errInsufficientPrivilege("drop a table in database '" + dbName + "'");
       }
 
       wlock.lock();
       try {
-        boolean contain = store.existDatabase(databaseName);
+        boolean contain = store.existDatabase(dbName);
 
         if (contain) {
-          if (!store.existTable(databaseName, tableName)) {
-            throw new NoSuchTableException(databaseName, tableName);
+          if (!store.existTable(dbName, tbName)) {
+            return errUndefinedTable(tbName);
           }
 
-          store.dropTable(databaseName, tableName);
+          store.dropTable(dbName, tbName);
           LOG.info(String.format("relation \"%s\" is deleted from the catalog (%s)",
-              CatalogUtil.getCanonicalTableName(databaseName, tableName), bindAddressStr));
+              CatalogUtil.getCanonicalTableName(dbName, tbName), bindAddressStr));
         } else {
-          throw new NoSuchDatabaseException(databaseName);
+          return errUndefinedDatabase(dbName);
         }
-      } catch (Exception e) {
-        LOG.error(e.getMessage(), e);
-        return BOOL_FALSE;
+
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         wlock.unlock();
       }
-
-      return BOOL_TRUE;
     }
 
     @Override
-    public BoolProto existsTable(RpcController controller, TableIdentifierProto request)
-        throws ServiceException {
-      String databaseName = request.getDatabaseName();
-      String tableName = request.getTableName();
+    public ReturnState existsTable(RpcController controller, TableIdentifierProto request) {
+      String dbName = request.getDatabaseName();
+      String tbName = request.getTableName();
 
-      if (!metaDictionary.isSystemDatabase(databaseName)) {
+      if (metaDictionary.isSystemDatabase(dbName)) {
+        return metaDictionary.existTable(tbName) ? OK : errUndefinedTable(tbName);
+
+      } else {
         rlock.lock();
         try {
 
-          boolean contain = store.existDatabase(databaseName);
+          boolean contain = store.existDatabase(dbName);
 
           if (contain) {
-            if (store.existTable(databaseName, tableName)) {
-              return BOOL_TRUE;
+            if (store.existTable(dbName, tbName)) {
+              return OK;
             } else {
-              return BOOL_FALSE;
+              return errUndefinedTable(tbName);
             }
           } else {
-            throw new NoSuchDatabaseException(databaseName);
+            return errUndefinedDatabase(dbName);
           }
-        } catch (Exception e) {
-          LOG.error(e);
-          throw new ServiceException(e);
+
+        } catch (Throwable t) {
+          printStackTraceIfError(LOG, t);
+          return returnError(t);
+
         } finally {
           rlock.unlock();
         }
-      } else {
-        if (metaDictionary.existTable(tableName)) {
-          return BOOL_TRUE;
-        } else {
-          return BOOL_FALSE;
-        }
       }
-
     }
     
     @Override
-    public GetTablesProto getAllTables(RpcController controller, NullProto request) throws ServiceException {
+    public GetTablesResponse getAllTables(RpcController controller, NullProto request) throws ServiceException {
       rlock.lock();
       try {
-        return GetTablesProto.newBuilder().addAllTable(store.getAllTables()).build();
-      } catch (Exception e) {
-        throw new ServiceException(e);
+        return GetTablesResponse.newBuilder()
+            .setState(OK)
+            .addAllTable(store.getAllTables())
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetTablesResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
     
     @Override
-    public GetTableOptionsProto getAllTableOptions(RpcController controller, NullProto request) throws ServiceException {
+    public GetTablePropertiesResponse getAllTableProperties(RpcController controller, NullProto request) {
       rlock.lock();
       try {
-        return GetTableOptionsProto.newBuilder().addAllTableOption(store.getAllTableOptions()).build();
-      } catch (Exception e) {
-        throw new ServiceException(e);
+        return GetTablePropertiesResponse.newBuilder()
+        .setState(OK)
+        .addAllProperties(store.getAllTableProperties())
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetTablePropertiesResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
     
     @Override
-    public GetTableStatsProto getAllTableStats(RpcController controller, NullProto request) throws ServiceException {
+    public GetTableStatsResponse getAllTableStats(RpcController controller, NullProto request) {
       rlock.lock();
       try {
-        return GetTableStatsProto.newBuilder().addAllStat(store.getAllTableStats()).build();
-      } catch (Exception e) {
-        throw new ServiceException(e);
+        return GetTableStatsResponse.newBuilder()
+            .addAllStats(store.getAllTableStats())
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetTableStatsResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
     
     @Override
-    public GetColumnsProto getAllColumns(RpcController controller, NullProto request) throws ServiceException {
+    public GetColumnsResponse getAllColumns(RpcController controller, NullProto request) throws ServiceException {
       rlock.lock();
       try {
-        return GetColumnsProto.newBuilder().addAllColumn(store.getAllColumns()).build();
-      } catch (Exception e) {
-        throw new ServiceException(e);
+        return GetColumnsResponse
+            .newBuilder()
+            .addAllColumn(store.getAllColumns())
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetColumnsResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public PartitionMethodProto getPartitionMethodByTableName(RpcController controller,
+    public GetPartitionMethodResponse getPartitionMethodByTableName(RpcController controller,
                                                               TableIdentifierProto request)
         throws ServiceException {
       String databaseName = request.getDatabaseName();
@@ -753,33 +848,48 @@ public class CatalogServer extends AbstractService {
         if (contain) {
           contain = store.existTable(databaseName, tableName);
           if (contain) {
+
             if (store.existPartitionMethod(databaseName, tableName)) {
-              return store.getPartitionMethod(databaseName, tableName);
+
+              return GetPartitionMethodResponse.newBuilder()
+                  .setState(OK)
+                  .setPartition(store.getPartitionMethod(databaseName, tableName))
+                  .build();
+
             } else {
-              throw new NoPartitionedTableException(databaseName, tableName);
+              return GetPartitionMethodResponse.newBuilder()
+                  .setState(errUndefinedPartitionMethod(tableName))
+                  .build();
             }
           } else {
-            throw new NoSuchTableException(databaseName);
+            return GetPartitionMethodResponse.newBuilder()
+                .setState(errUndefinedTable(tableName))
+                .build();
           }
         } else {
-          throw new NoSuchDatabaseException(databaseName);
+          return GetPartitionMethodResponse.newBuilder()
+              .setState(errUndefinedDatabase(tableName))
+              .build();
         }
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return GetPartitionMethodResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public BoolProto existPartitionMethod(RpcController controller, TableIdentifierProto request)
-        throws ServiceException {
+    public ReturnState existPartitionMethod(RpcController controller, TableIdentifierProto request) {
       String databaseName = request.getDatabaseName();
       String tableName = request.getTableName();
       
       if (metaDictionary.isSystemDatabase(databaseName)) {
-        throw new ServiceException(databaseName + " is a system database. Partition Method does not support yet.");
+        ReturnStateUtil.errFeatureNotSupported("partition feature in virtual tables");
       }
 
       rlock.lock();
@@ -792,171 +902,211 @@ public class CatalogServer extends AbstractService {
           contain = store.existTable(databaseName, tableName);
           if (contain) {
             if (store.existPartitionMethod(databaseName, tableName)) {
-              return ProtoUtil.TRUE;
+              return OK;
             } else {
-              return ProtoUtil.FALSE;
+              return errUndefinedPartitionMethod(tableName);
             }
           } else {
-            throw new NoSuchTableException(databaseName);
+            return errUndefinedTable(tableName);
           }
         } else {
-          throw new NoSuchDatabaseException(databaseName);
+          return errUndefinedDatabase(databaseName);
         }
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public BoolProto dropPartitionMethod(RpcController controller, TableIdentifierProto request)
-        throws ServiceException {
-      return ProtoUtil.TRUE;
+    public ReturnState dropPartitionMethod(RpcController controller, TableIdentifierProto request) {
+      return errFeatureNotSupported("dropPartitionMethod");
     }
 
     @Override
-    public PartitionDescProto getPartitionByPartitionName(RpcController controller, PartitionIdentifierProto request)
+    public GetPartitionDescResponse getPartitionByPartitionName(RpcController controller, PartitionIdentifierProto request)
         throws ServiceException {
-      String databaseName = request.getDatabaseName();
-      String tableName = request.getTableName();
+      String dbName = request.getDatabaseName();
+      String tbName = request.getTableName();
       String partitionName = request.getPartitionName();
 
-      if (metaDictionary.isSystemDatabase(databaseName)) {
-        throw new ServiceException(databaseName + " is a system databsae. It does not contain any partitioned tables.");
+      if (metaDictionary.isSystemDatabase(dbName)) {
+        throw new ServiceException(dbName + " is a system databsae. It does not contain any partitioned tables.");
       }
 
       rlock.lock();
       try {
         boolean contain;
 
-        contain = store.existDatabase(databaseName);
+        contain = store.existDatabase(dbName);
         if (contain) {
-          contain = store.existTable(databaseName, tableName);
+          contain = store.existTable(dbName, tbName);
           if (contain) {
-            if (store.existPartitionMethod(databaseName, tableName)) {
-              PartitionDescProto partitionDesc = store.getPartition(databaseName, tableName, partitionName);
-              if (partitionDesc != null) {
-                return partitionDesc;
-              } else {
-                throw new NoSuchPartitionException(databaseName, tableName, partitionName);
-              }
+
+            if (store.existPartitionMethod(dbName, tbName)) {
+              PartitionDescProto partitionDesc = store.getPartition(dbName, tbName, partitionName);
+
+
+              return GetPartitionDescResponse.newBuilder()
+                  .setState(OK)
+                  .setPartition(partitionDesc)
+                  .build();
+
             } else {
-              throw new NoPartitionedTableException(databaseName, tableName);
+              return GetPartitionDescResponse.newBuilder()
+                  .setState(errUndefinedPartitionMethod(tbName))
+                  .build();
             }
           } else {
-            throw new NoSuchTableException(tableName);
+            return GetPartitionDescResponse.newBuilder()
+                .setState(errUndefinedTable(tbName))
+                .build();
           }
         } else {
-          throw new NoSuchDatabaseException(databaseName);
+          return GetPartitionDescResponse.newBuilder()
+              .setState(errUndefinedDatabase(dbName))
+              .build();
         }
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetPartitionDescResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public PartitionsProto getPartitionsByTableName(RpcController controller, PartitionIdentifierProto request)
+    public GetPartitionsResponse getPartitionsByTableName(RpcController controller, PartitionIdentifierProto request)
       throws ServiceException {
-      String databaseName = request.getDatabaseName();
-      String tableName = request.getTableName();
+      String dbName = request.getDatabaseName();
+      String tbName = request.getTableName();
 
-      if (metaDictionary.isSystemDatabase(databaseName)) {
-        throw new ServiceException(databaseName + " is a system databsae. It does not contain any partitioned tables.");
+      if (metaDictionary.isSystemDatabase(dbName)) {
+        throw new ServiceException(dbName + " is a system databsae. It does not contain any partitioned tables.");
       }
 
       rlock.lock();
       try {
         boolean contain;
 
-        contain = store.existDatabase(databaseName);
+        contain = store.existDatabase(dbName);
         if (contain) {
-          contain = store.existTable(databaseName, tableName);
+          contain = store.existTable(dbName, tbName);
           if (contain) {
-            if (store.existPartitionMethod(databaseName, tableName)) {
-              List<PartitionDescProto> partitions = store.getPartitions(databaseName, tableName);
-              PartitionsProto.Builder builder = PartitionsProto.newBuilder();
+            if (store.existPartitionMethod(dbName, tbName)) {
+              List<PartitionDescProto> partitions = store.getPartitions(dbName, tbName);
+
+              GetPartitionsResponse.Builder builder = GetPartitionsResponse.newBuilder();
               for(PartitionDescProto partition : partitions) {
                 builder.addPartition(partition);
               }
+
+              builder.setState(OK);
               return builder.build();
+
             } else {
-              throw new NoPartitionedTableException(databaseName, tableName);
+              return GetPartitionsResponse.newBuilder()
+                  .setState(errUndefinedPartitionMethod(tbName))
+                  .build();
             }
+
           } else {
-            throw new NoSuchTableException(tableName);
+            return GetPartitionsResponse.newBuilder()
+                .setState(errUndefinedTable(tbName))
+                .build();
           }
         } else {
-          throw new NoSuchDatabaseException(databaseName);
+          return GetPartitionsResponse.newBuilder()
+              .setState(errUndefinedDatabase(dbName))
+              .build();
+
         }
-      } catch (Exception e) {
-        LOG.error(e);
-        throw new ServiceException(e);
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetPartitionsResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public GetTablePartitionsProto getAllPartitions(RpcController controller, NullProto request) throws ServiceException {
+    public GetTablePartitionsResponse getAllPartitions(RpcController controller, NullProto request) throws ServiceException {
       rlock.lock();
+
       try {
-        return GetTablePartitionsProto.newBuilder().addAllPart(store.getAllPartitions()).build();
-      } catch (Exception e) {
-        throw new ServiceException(e);
+        return GetTablePartitionsResponse.newBuilder()
+            .setState(OK)
+            .addAllPart(store.getAllPartitions())
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetTablePartitionsResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public BoolProto createIndex(RpcController controller, IndexDescProto indexDesc)
-        throws ServiceException {
-      String databaseName = indexDesc.getTableIdentifier().getDatabaseName();
+    public ReturnState createIndex(RpcController controller, IndexDescProto indexDesc) {
+      String dbName = indexDesc.getTableIdentifier().getDatabaseName();
       
       rlock.lock();
       try {
         if (store.existIndexByName(
-            databaseName,
+            dbName,
             indexDesc.getIndexName())) {
-          throw new AlreadyExistsIndexException(indexDesc.getIndexName());
+          return errDuplicateTable(indexDesc.getIndexName());
         }
         store.createIndex(indexDesc);
-      } catch (Exception e) {
-        LOG.error("ERROR : cannot add index " + indexDesc.getIndexName(), e);
-        LOG.error(indexDesc);
-        throw new ServiceException(e);
+
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         rlock.unlock();
       }
-
-      return BOOL_TRUE;
     }
 
     @Override
-    public BoolProto existIndexByName(RpcController controller, IndexNameProto request) throws ServiceException {
+    public ReturnState existIndexByName(RpcController controller, IndexNameProto request) {
 
-      String databaseName = request.getDatabaseName();
+      String dbName = request.getDatabaseName();
       String indexName = request.getIndexName();
 
       rlock.lock();
       try {
-        return store.existIndexByName(databaseName, indexName) ? ProtoUtil.TRUE : ProtoUtil.FALSE;
-      } catch (Exception e) {
-        LOG.error(e, e);
-        return BoolProto.newBuilder().setValue(false).build();
+        return store.existIndexByName(dbName, indexName) ? OK : errUndefinedIndexName(indexName);
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public BoolProto existIndexByColumn(RpcController controller, GetIndexByColumnRequest request)
-        throws ServiceException {
+    public ReturnState existIndexByColumn(RpcController controller, GetIndexByColumnRequest request) {
 
       TableIdentifierProto identifier = request.getTableIdentifier();
       String databaseName = identifier.getDatabaseName();
@@ -966,17 +1116,19 @@ public class CatalogServer extends AbstractService {
       rlock.lock();
       try {
         return store.existIndexByColumn(databaseName, tableName, columnName) ?
-            ProtoUtil.TRUE : ProtoUtil.FALSE;
-      } catch (Exception e) {
-        LOG.error(e, e);
-        return BoolProto.newBuilder().setValue(false).build();
+            OK : errUndefinedIndex(tableName, columnName);
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public IndexDescProto getIndexByName(RpcController controller, IndexNameProto request)
+    public GetIndexResponse getIndexByName(RpcController controller, IndexNameProto request)
         throws ServiceException {
 
       String databaseName = request.getDatabaseName();
@@ -984,20 +1136,32 @@ public class CatalogServer extends AbstractService {
 
       rlock.lock();
       try {
+
         if (!store.existIndexByName(databaseName, indexName)) {
-          throw new NoSuchIndexException(databaseName, indexName);
+          return GetIndexResponse.newBuilder()
+              .setState(errUndefinedIndexName(indexName))
+              .build();
         }
-        return store.getIndexByName(databaseName, indexName);
-      } catch (Exception e) {
-        LOG.error("ERROR : cannot get index " + indexName, e);
-        return null;
+
+        return GetIndexResponse.newBuilder()
+            .setState(OK)
+            .setIndex(store.getIndexByName(databaseName, indexName))
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetIndexResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public IndexDescProto getIndexByColumn(RpcController controller, GetIndexByColumnRequest request)
+    public GetIndexResponse getIndexByColumn(RpcController controller, GetIndexByColumnRequest request)
         throws ServiceException {
 
       TableIdentifierProto identifier = request.getTableIdentifier();
@@ -1008,55 +1172,70 @@ public class CatalogServer extends AbstractService {
       rlock.lock();
       try {
         if (!store.existIndexByColumn(databaseName, tableName, columnName)) {
-          throw new NoSuchIndexException(databaseName, columnName);
+          return GetIndexResponse.newBuilder()
+              .setState(errUndefinedIndex(tableName, columnName))
+              .build();
         }
-        return store.getIndexByColumn(databaseName, tableName, columnName);
-      } catch (Exception e) {
-        LOG.error("ERROR : cannot get index for " + tableName + "." + columnName, e);
-        return null;
+
+        return GetIndexResponse.newBuilder()
+            .setState(OK)
+            .setIndex(store.getIndexByColumn(databaseName, tableName, columnName))
+            .build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetIndexResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
     @Override
-    public BoolProto dropIndex(RpcController controller, IndexNameProto request)
-        throws ServiceException {
+    public ReturnState dropIndex(RpcController controller, IndexNameProto request) {
 
-      String databaseName = request.getDatabaseName();
+      String dbName = request.getDatabaseName();
       String indexName = request.getIndexName();
 
       wlock.lock();
       try {
-        if (!store.existIndexByName(databaseName, indexName)) {
-          throw new NoSuchIndexException(indexName);
+        if (!store.existIndexByName(dbName, indexName)) {
+          return errUndefinedIndexName(indexName);
         }
-        store.dropIndex(databaseName, indexName);
-      } catch (Exception e) {
-        LOG.error(e, e);
+        store.dropIndex(dbName, indexName);
+
+        return OK;
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+
       } finally {
         wlock.unlock();
       }
-
-      return BOOL_TRUE;
     }
     
     @Override
-    public GetIndexesProto getAllIndexes(RpcController controller, NullProto request) throws ServiceException {
+    public GetIndexesResponse getAllIndexes(RpcController controller, NullProto request) throws ServiceException {
       rlock.lock();
       try {
-        return GetIndexesProto.newBuilder().addAllIndex(store.getAllIndexes()).build();
-      } catch (Exception e) {
-        throw new ServiceException(e);
+        return GetIndexesResponse.newBuilder().addAllIndex(store.getAllIndexes()).build();
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return GetIndexesResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
+
       } finally {
         rlock.unlock();
       }
     }
 
-    public boolean checkIfBuiltin(FunctionType type) {
-      return type == GENERAL || type == AGGREGATION || type == DISTINCT_AGGREGATION;
-    }
-
     private boolean containFunction(String signature) {
       List<FunctionDescProto> found = findFunction(signature);
       return found != null && found.size() > 0;
@@ -1181,69 +1360,101 @@ public class CatalogServer extends AbstractService {
     }
 
     @Override
-    public BoolProto createFunction(RpcController controller, FunctionDescProto funcDesc)
-        throws ServiceException {
-      FunctionSignature signature = FunctionSignature.create(funcDesc);
+    public ReturnState createFunction(RpcController controller, FunctionDescProto funcDesc) {
 
-      if (functions.containsKey(funcDesc.getSignature())) {
-        FunctionDescProto found = findFunctionStrictType(funcDesc, true);
-        if (found != null) {
-          throw new ServiceException(new AlreadyExistsFunctionException(signature.toString()));
+      try {
+        FunctionSignature signature = FunctionSignature.create(funcDesc);
+
+        if (functions.containsKey(funcDesc.getSignature())) {
+          FunctionDescProto found = findFunctionStrictType(funcDesc, true);
+          if (found != null) {
+            return errDuplicateFunction(signature.toString());
+          }
         }
-      }
 
-      TUtil.putToNestedList(functions, funcDesc.getSignature().getName(), funcDesc);
-      if (LOG.isDebugEnabled()) {
-        LOG.info("Function " + signature + " is registered.");
-      }
+        TUtil.putToNestedList(functions, funcDesc.getSignature().getName(), funcDesc);
+
+        return OK;
 
-      return BOOL_TRUE;
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+      }
     }
 
     @Override
-    public BoolProto dropFunction(RpcController controller, UnregisterFunctionRequest request)
-        throws ServiceException {
+    public ReturnState dropFunction(RpcController controller, UnregisterFunctionRequest request) {
+      try {
+        if (!containFunction(request.getSignature())) {
+          return errUndefinedFunction(request.toString());
+        }
 
-      if (!containFunction(request.getSignature())) {
-        throw new ServiceException(new NoSuchFunctionException(request.getSignature(), new DataType[]{}));
-      }
+        functions.remove(request.getSignature());
 
-      functions.remove(request.getSignature());
-      LOG.info(request.getSignature() + " is dropped.");
+        return OK;
 
-      return BOOL_TRUE;
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
+      }
     }
 
     @Override
-    public FunctionDescProto getFunctionMeta(RpcController controller, GetFunctionMetaRequest request)
-        throws ServiceException {
+    public FunctionResponse getFunctionMeta(RpcController controller, GetFunctionMetaRequest request) {
+
       FunctionDescProto function = null;
-      if (request.hasFunctionType()) {
-        if (containFunction(request.getSignature(), request.getFunctionType(), request.getParameterTypesList())) {
-          function = findFunction(request.getSignature(), request.getFunctionType(), request.getParameterTypesList(),true);
+
+      try {
+        if (request.hasFunctionType()) {
+          if (containFunction(request.getSignature(), request.getFunctionType(), request.getParameterTypesList())) {
+            function = findFunction(request.getSignature(), request.getFunctionType(), request.getParameterTypesList(), true);
+          }
+        } else {
+          function = findFunction(request.getSignature(), request.getParameterTypesList());
         }
-      } else {
-        function = findFunction(request.getSignature(), request.getParameterTypesList());
-      }
 
-      if (function == null) {
-        throw new ServiceException(new NoSuchFunctionException(request.getSignature(), request.getParameterTypesList()));
-      } else {
-        return function;
+        if (function != null) {
+          return FunctionResponse.newBuilder()
+              .setState(OK)
+              .setFunction(function)
+              .build();
+        } else {
+
+          return FunctionResponse.newBuilder()
+              .setState(errUndefinedFunction(
+                  buildSimpleFunctionSignature(request.getSignature(), request.getParameterTypesList())))
+              .build();
+        }
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+
+        return FunctionResponse.newBuilder()
+            .setState(returnError(t))
+            .build();
       }
     }
 
     @Override
-    public BoolProto containFunction(RpcController controller, ContainFunctionRequest request)
-        throws ServiceException {
-      boolean returnValue;
-      if (request.hasFunctionType()) {
-        returnValue = containFunction(request.getSignature(), request.getFunctionType(),
-            request.getParameterTypesList());
-      } else {
-        returnValue = containFunction(request.getSignature(), request.getParameterTypesList());
+    public ReturnState containFunction(RpcController controller, ContainFunctionRequest request) {
+
+      try {
+        boolean returnValue;
+        if (request.hasFunctionType()) {
+          returnValue = containFunction(request.getSignature(), request.getFunctionType(),
+              request.getParameterTypesList());
+        } else {
+          returnValue = containFunction(request.getSignature(), request.getParameterTypesList());
+        }
+
+        return returnValue ?
+            OK :
+            errUndefinedFunction(buildSimpleFunctionSignature(request.getSignature(), request.getParameterTypesList()));
+
+      } catch (Throwable t) {
+        printStackTraceIfError(LOG, t);
+        return returnError(t);
       }
-      return BoolProto.newBuilder().setValue(returnValue).build();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
index 8312e0e..f798c1d 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/dictionary/InfoSchemaMetadataDictionary.java
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.tajo.catalog.exception.NoSuchTableException;
+import org.apache.tajo.catalog.exception.UndefinedTableException;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
 import org.apache.tajo.util.TUtil;
@@ -31,7 +31,7 @@ public class InfoSchemaMetadataDictionary {
   
   private static final String DATABASE_NAME = "information_schema";
   
-  private static enum DEFINED_TABLES {
+  private enum DEFINED_TABLES {
     TABLESPACES,
     DATABASES,
     TABLES,
@@ -43,7 +43,7 @@ public class InfoSchemaMetadataDictionary {
     PARTITION_KEYS,
     CLUSTER,
     SESSION,
-    MAX_TABLE;
+    MAX_TABLE
   }
   
   private List<TableDescriptor> schemaInfoTableDescriptors = new ArrayList<TableDescriptor>(
@@ -95,7 +95,7 @@ public class InfoSchemaMetadataDictionary {
     TableDescriptor tableDescriptor = null;
     
     if (tableName == null || tableName.isEmpty()) {
-      throw new NoSuchTableException(tableName);
+      throw new UndefinedTableException(tableName);
     }
     
     tableName = tableName.toUpperCase();
@@ -115,7 +115,7 @@ public class InfoSchemaMetadataDictionary {
     
     tableDescriptor = getTableDescriptor(tableName);
     if (tableDescriptor == null) {
-      throw new NoSuchTableException(DATABASE_NAME, tableName);
+      throw new UndefinedTableException(DATABASE_NAME, tableName);
     }
     
     return tableDescriptor.getTableDescription();

http://git-wip-us.apache.org/repos/asf/tajo/blob/5d62c409/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
index 043c8bc..c6b7d36 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
@@ -36,7 +36,7 @@ import org.apache.tajo.catalog.proto.CatalogProtos.*;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.common.TajoDataTypes.Type;
 import org.apache.tajo.exception.InternalException;
-import org.apache.tajo.exception.UnimplementedException;
+import org.apache.tajo.exception.TajoInternalError;
 import org.apache.tajo.util.FileUtil;
 import org.apache.tajo.util.Pair;
 import org.apache.tajo.util.TUtil;
@@ -49,6 +49,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.*;
 
+import static org.apache.tajo.catalog.exception.CatalogExceptionUtil.makeCatalogUpgrade;
 import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceCommand;
 import static org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueProto;
 import static org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.KeyValueSetProto;
@@ -128,7 +129,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       Class.forName(getCatalogDriverName()).newInstance();
       LOG.info("Loaded the Catalog driver (" + catalogDriver + ")");
     } catch (Exception e) {
-      throw new CatalogException("Cannot load Catalog driver " + catalogDriver, e);
+      throw new TajoInternalError(e);
     }
 
     try {
@@ -136,8 +137,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       conn = createConnection(conf);
       LOG.info("Connected to database (" + catalogUri + ")");
     } catch (SQLException e) {
-      throw new CatalogException("Cannot connect to database (" + catalogUri
-          + ")", e);
+      throw new MetadataConnectionException(catalogUri , e);
     }
 
     String schemaPath = getCatalogSchemaPath();
@@ -168,7 +168,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         }
      }
     } catch (Exception se) {
-      throw new CatalogException("Cannot initialize the persistent storage of Catalog", se);
+      throw new TajoInternalError(se);
     }
   }
 
@@ -180,7 +180,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     try {
       return FileUtil.readTextFileFromResource("schemas/" + path);
     } catch (IOException e) {
-      throw new CatalogException(e);
+      throw new TajoInternalError(e);
     }
   }
 
@@ -232,7 +232,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         schemaVersion = result.getInt("VERSION");
       }
     } catch (SQLException e) {
-      throw new CatalogException(e.getMessage(), e);
+      throw new TajoInternalError(e);
     } finally {
       CatalogUtil.closeQuietly(pstmt, result);
     }
@@ -256,7 +256,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       LOG.error("| In order to learn how to migration Apache Tajo instance, |");
       LOG.error("| please refer http://tajo.apache.org/docs/current/backup_and_restore/catalog.html |");
       LOG.error("=========================================================================");
-      throw new CatalogException("Migration Needed. Please refer http://s.apache.org/0_8_migration.");
+      throw makeCatalogUpgrade();
     }
 
     LOG.info(String.format("The compatibility of the catalog schema (version: %d) has been verified.",
@@ -267,7 +267,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
    * Insert the version of the current catalog schema
    */
   protected void insertSchemaVersion() throws CatalogException {
-    Connection conn = null;
+    Connection conn;
     PreparedStatement pstmt = null;
     try {
       conn = getConnection();
@@ -275,7 +275,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setInt(1, getDriverVersion());
       pstmt.executeUpdate();
     } catch (SQLException se) {
-      throw new CatalogException("cannot insert catalog schema version", se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -310,7 +310,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
           LOG.error(e, e);
         }
       }
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -336,7 +336,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       res = pstmt.executeQuery();
       exist = res.next();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -374,7 +374,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
           LOG.error(e, e);
         }
       }
-      throw new CatalogException(String.format("Failed to drop tablespace \"%s\"", tableSpaceName), se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -406,7 +406,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         tablespaceNames.add(resultSet.getString(1));
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, resultSet);
     }
@@ -439,7 +439,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       return tablespaces;
 
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(stmt, resultSet);
     }
@@ -459,7 +459,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       resultSet = pstmt.executeQuery();
 
       if (!resultSet.next()) {
-        throw new NoSuchTablespaceException(spaceName);
+        throw new UndefinedTablespaceException(spaceName);
       }
 
       String retrieveSpaceName = resultSet.getString("SPACE_NAME");
@@ -471,7 +471,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       return builder.build();
 
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, resultSet);
     }
@@ -495,7 +495,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
           pstmt.setString(2, alterProto.getSpaceName());
           pstmt.executeUpdate();
         } catch (SQLException se) {
-          throw new CatalogException(se);
+          throw new TajoInternalError(se);
         } finally {
           CatalogUtil.closeQuietly(pstmt);
         }
@@ -534,7 +534,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
           LOG.error(e, e);
         }
       }
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -560,7 +560,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       res = pstmt.executeQuery();
       exist = res.next();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -595,7 +595,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
           LOG.error(e, e);
         }
       }
-      throw new CatalogException(String.format("Failed to drop database \"%s\"", databaseName), se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -627,7 +627,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         databaseNames.add(resultSet.getString(1));
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, resultSet);
     }
@@ -659,7 +659,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         databases.add(builder.build());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(stmt, resultSet);
     }
@@ -703,11 +703,11 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setString(1, spaceName);
       res = pstmt.executeQuery();
       if (!res.next()) {
-        throw new CatalogException("ERROR: there is no SPACE_ID matched to the space name \"" + spaceName + "\"");
+        throw new TajoInternalError("There is no SPACE_ID matched to the space name '" + spaceName + "'");
       }
       return new TableSpaceInternal(res.getInt(1), res.getString(2), res.getString(3));
     } catch (SQLException se) {
-      throw new NoSuchTablespaceException(spaceName);
+      throw new UndefinedTablespaceException(spaceName);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -726,11 +726,11 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setString(2, tableName);
       res = pstmt.executeQuery();
       if (!res.next()) {
-        throw new CatalogException("ERROR: there is no tid matched to " + tableName);
+        throw new TajoInternalError("There is no tid matched to '" + tableName + "'");
       }
       return res.getInt(1);
     } catch (SQLException se) {
-      throw new NoSuchTableException(databaseName, tableName);
+      throw new UndefinedTableException(databaseName, tableName);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -753,8 +753,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
       String[] splitted = CatalogUtil.splitTableName(table.getTableName());
       if (splitted.length == 1) {
-        throw new IllegalArgumentException("createTable() requires a qualified table name, but it is \""
-            + table.getTableName() + "\".");
+        throw new TajoInternalError(
+            "createTable() requires a qualified table name, but it is '" + table.getTableName() + "'");
       }
       String databaseName = splitted[0];
       String tableName = splitted[1];
@@ -789,7 +789,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       res = pstmt.executeQuery();
 
       if (!res.next()) {
-        throw new CatalogException("ERROR: there is no TID matched to " + table.getTableName());
+        throw new TajoInternalError("There is no TID matched to '" + table.getTableName() + '"');
       }
 
       int tableId = res.getInt("TID");
@@ -885,7 +885,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
           LOG.error(e, e);
         }
       }
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -920,7 +920,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       res = pstmt.executeQuery();
 
       if (!res.next()) {
-        throw new CatalogException("ERROR: there is no TID matched to " + statsProto.getTableName());
+        throw new TajoInternalError("There is no TID matched to '" + statsProto.getTableName() + "'");
       }
 
       int tableId = res.getInt("TID");
@@ -953,7 +953,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
           LOG.error(e, e);
         }
       }
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -979,19 +979,19 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       switch (alterTableDescProto.getAlterTableType()) {
         case RENAME_TABLE:
           if (existTable(databaseName,alterTableDescProto.getNewTableName())) {
-            throw new AlreadyExistsTableException(alterTableDescProto.getNewTableName());
+            throw new DuplicateTableException(alterTableDescProto.getNewTableName());
           }
           renameTable(tableId, alterTableDescProto.getNewTableName());
           break;
         case RENAME_COLUMN:
           if (existColumn(tableId, alterTableDescProto.getAlterColumnName().getNewColumnName())) {
-            throw new ColumnNameAlreadyExistException(alterTableDescProto.getAlterColumnName().getNewColumnName());
+            throw new DuplicateColumnException(alterTableDescProto.getAlterColumnName().getNewColumnName());
           }
           renameColumn(tableId, alterTableDescProto.getAlterColumnName());
           break;
         case ADD_COLUMN:
           if (existColumn(tableId, alterTableDescProto.getAddColumn().getName())) {
-            throw new ColumnNameAlreadyExistException(alterTableDescProto.getAddColumn().getName());
+            throw new DuplicateColumnException(alterTableDescProto.getAddColumn().getName());
           }
           addNewColumn(tableId, alterTableDescProto.getAddColumn());
           break;
@@ -999,7 +999,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
           partitionName = alterTableDescProto.getPartitionDesc().getPartitionName();
           partitionDesc = getPartition(databaseName, tableName, partitionName);
           if(partitionDesc != null) {
-            throw new AlreadyExistsPartitionException(databaseName, tableName, partitionName);
+            throw new DuplicatePartitionException(partitionName);
           }
           addPartition(tableId, alterTableDescProto.getPartitionDesc());
           break;
@@ -1007,7 +1007,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
           partitionName = alterTableDescProto.getPartitionDesc().getPartitionName();
           partitionDesc = getPartition(databaseName, tableName, partitionName);
           if(partitionDesc == null) {
-            throw new NoSuchPartitionException(databaseName, tableName, partitionName);
+            throw new UndefinedPartitionException(partitionName);
           }
           dropPartition(tableId, alterTableDescProto.getPartitionDesc().getPartitionName());
           break;
@@ -1017,7 +1017,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         default:
       }
     } catch (SQLException sqlException) {
-      throw new CatalogException(sqlException);
+      throw new TajoInternalError(sqlException);
     }
 
   }
@@ -1040,7 +1040,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         options.put(res.getString("KEY_"), res.getString("VALUE_"));
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -1084,8 +1084,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       }
 
       conn.commit();
-    } catch (SQLException sqlException) {
-      throw new CatalogException(sqlException);
+    } catch (Throwable sqlException) {
+      throw new TajoInternalError(sqlException);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -1110,8 +1110,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setInt(2, tableId);
       pstmt.executeUpdate();
 
-    } catch (SQLException sqlException) {
-      throw new CatalogException(sqlException);
+    } catch (SQLException se) {
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -1161,7 +1161,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         ordinalPosition = resultSet.getInt("ORDINAL_POSITION");
         nestedFieldNum = resultSet.getInt("NESTED_FIELD_NUM");
       } else {
-        throw new NoSuchColumnException(alterColumnProto.getOldColumnName());
+        throw new UndefinedColumnException(alterColumnProto.getOldColumnName());
       }
 
       resultSet.close();
@@ -1189,7 +1189,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
 
     } catch (SQLException sqlException) {
-      throw new CatalogException(sqlException);
+      throw new TajoInternalError(sqlException);
     } finally {
       CatalogUtil.closeQuietly(pstmt,resultSet);
     }
@@ -1237,7 +1237,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.executeUpdate();
 
     } catch (SQLException sqlException) {
-      throw new CatalogException(sqlException);
+      throw new TajoInternalError(sqlException);
     } finally {
       CatalogUtil.closeQuietly(pstmt,resultSet);
     }
@@ -1275,7 +1275,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         pstmt.executeBatch();
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -1305,7 +1305,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         retValue = res.getInt(1);
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -1352,7 +1352,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.executeUpdate();
 
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -1375,7 +1375,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setString(1, databaseName);
       res = pstmt.executeQuery();
       if (!res.next()) {
-        throw new NoSuchDatabaseException(databaseName);
+        throw new UndefinedDatabaseException(databaseName);
       }
 
       return res.getInt("DB_ID");
@@ -1408,7 +1408,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       res = pstmt.executeQuery();
       exist = res.next();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -1548,7 +1548,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setString(1, databaseName);
       res = pstmt.executeQuery();
       if (!res.next()) {
-        throw new NoSuchDatabaseException(databaseName);
+        throw new UndefinedDatabaseException(databaseName);
       }
 
       return new Pair<Integer, String>(res.getInt(1), res.getString(2) + "/" + databaseName);
@@ -1691,10 +1691,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       if (res.next()) {
         tableBuilder.setPartition(resultToPartitionMethodProto(databaseName, tableName, res));
       }
-    } catch (InvalidProtocolBufferException e) {
-      throw new CatalogException(e);
-    } catch (SQLException se) {
-      throw new CatalogException(se);
+    } catch (Throwable se) {
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -1737,7 +1735,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         tables.add(res.getString(COL_TABLES_NAME).trim());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -1785,7 +1783,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         tables.add(builder.build());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(stmt, resultSet);
     }
@@ -1794,7 +1792,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
   }
   
   @Override
-  public List<TableOptionProto> getAllTableOptions() throws CatalogException {
+  public List<TableOptionProto> getAllTableProperties() throws CatalogException {
     Connection conn = null;
     Statement stmt = null;
     ResultSet resultSet = null;
@@ -1820,7 +1818,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         options.add(builder.build());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(stmt, resultSet);
     }
@@ -1852,7 +1850,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         stats.add(builder.build());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(stmt, resultSet);
     }
@@ -1898,7 +1896,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         columns.add(builder.build());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(stmt, resultSet);
     }
@@ -1933,7 +1931,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setBytes(4, proto.getExpressionSchema().toByteArray());
       pstmt.executeUpdate();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -1959,7 +1957,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setInt(1, tableId);
       pstmt.executeUpdate();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -1991,10 +1989,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       if (res.next()) {
         return resultToPartitionMethodProto(databaseName, tableName, res);
       }
-    } catch (InvalidProtocolBufferException e) {
-      throw new CatalogException(e);
-    } catch (SQLException se) {
-      throw new CatalogException(se);
+    } catch (Throwable se) {
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2026,7 +2022,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
       exist = res.next();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2067,7 +2063,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         return null;
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2096,7 +2092,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         partitionDesc.addPartitionKeys(builder);
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2134,7 +2130,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         partitions.add(builder.build());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2167,7 +2163,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         partitions.add(builder.build());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(stmt, resultSet);
     }
@@ -2214,7 +2210,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.executeUpdate();
       conn.commit();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -2239,7 +2235,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setString(2, indexName);
       pstmt.executeUpdate();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt);
     }
@@ -2255,7 +2251,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setInt(1, tableId);
       res = pstmt.executeQuery();
       if (!res.next()) {
-        throw new CatalogException("Cannot get any table name from TID");
+        throw new TajoInternalError("Cannot get any table name from TID");
       }
       return res.getString(1);
     } finally {
@@ -2291,7 +2287,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setString(2, indexName);
       res = pstmt.executeQuery();
       if (!res.next()) {
-        throw new CatalogException("ERROR: there is no index matched to " + indexName);
+        throw new TajoInternalError("There is no index matched to " + indexName);
       }
       IndexDescProto.Builder builder = IndexDescProto.newBuilder();
       resultToIndexDescProtoBuilder(builder, res);
@@ -2299,7 +2295,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       builder.setTableIdentifier(CatalogUtil.buildTableIdentifier(databaseName, tableName));
       proto = builder.build();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2332,14 +2328,14 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.setString(2, columnName);
       res = pstmt.executeQuery();
       if (!res.next()) {
-        throw new CatalogException("ERROR: there is no index matched to " + columnName);
+        throw new TajoInternalError("ERROR: there is no index matched to " + columnName);
       }
       IndexDescProto.Builder builder = IndexDescProto.newBuilder();
       resultToIndexDescProtoBuilder(builder, res);
       builder.setTableIdentifier(CatalogUtil.buildTableIdentifier(databaseName, tableName));
       proto = builder.build();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2372,7 +2368,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       res = pstmt.executeQuery();
       exist = res.next();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2406,7 +2402,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       res = pstmt.executeQuery();
       exist = res.next();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2447,7 +2443,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         protos.add(builder.build());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
@@ -2486,7 +2482,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         indexes.add(builder.build());
       }
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(stmt, resultSet);
     }
@@ -2620,7 +2616,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       res = pstmt.executeQuery();
       exist = res.next();
     } catch (SQLException se) {
-      throw new CatalogException(se);
+      throw new TajoInternalError(se);
     } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }


Mime
View raw message