Repository: tajo
Updated Branches:
  refs/heads/branch-0.10.2 9accd2e49 -> 75e6dceee


TAJO-1642: CatalogServer need to check meta table first. (jaehwa)


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/75e6dcee
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/75e6dcee
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/75e6dcee

Branch: refs/heads/branch-0.10.2
Commit: 75e6dceeebef77a3c7b26ef3dfb08754b2c8151c
Parents: 9accd2e
Author: JaeHwa Jung <[email protected]>
Authored: Wed Jun 24 11:08:25 2015 +0900
Committer: JaeHwa Jung <[email protected]>
Committed: Wed Jun 24 11:08:25 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |  2 ++
 .../tajo/catalog/store/AbstractDBStore.java     | 33 +++++++++++++-------
 .../catalog/store/XMLCatalogSchemaManager.java  | 29 +++++++++++++++++
 3 files changed, 52 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/75e6dcee/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index e13413a..0046ad4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,8 @@ Release 0.10.2 - Released
 
   BUG FIXES
 
+    TAJO-1642: CatalogServer need to check meta table first. (jaehwa)
+
   TASKS
 
 Release 0.10.1 - Released

http://git-wip-us.apache.org/repos/asf/tajo/blob/75e6dcee/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 5c78f82..59f3c82 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
@@ -81,6 +81,10 @@ public abstract class AbstractDBStore extends 
CatalogConstants implements Catalo
     return catalogSchemaManager.isInitialized(getConnection());
   }
 
+  protected boolean catalogAlreadyExists() throws CatalogException {
+    return catalogSchemaManager.catalogAlreadyExists(getConnection());
+  }
+
   protected void createBaseTable() throws CatalogException {
     createDatabaseDependants();
     
@@ -141,22 +145,27 @@ public abstract class AbstractDBStore extends 
CatalogConstants implements Catalo
     if (schemaPath != null && !schemaPath.isEmpty()) {
       this.catalogSchemaManager = new XMLCatalogSchemaManager(schemaPath);
     }
-    
+
     try {
-      if (isInitialized()) {
-        LOG.info("The base tables of CatalogServer already is initialized.");
+      if (catalogAlreadyExists()) {
+        LOG.info("The meta table of CatalogServer already is created.");
         verifySchemaVersion();
       } else {
-        try {
-          createBaseTable();
-          LOG.info("The base tables of CatalogServer are created.");
-        } catch (CatalogException ce) {
+        if (isInitialized()) {
+          LOG.info("The base tables of CatalogServer already is initialized.");
+          verifySchemaVersion();
+        } else {
           try {
-            dropBaseTable();
-          } catch (Throwable t) {
-            LOG.error(t, t);
+            createBaseTable();
+            LOG.info("The base tables of CatalogServer are created.");
+          } catch (CatalogException ce) {
+            try {
+              dropBaseTable();
+            } catch (Throwable t) {
+              LOG.error(t, t);
+            }
+            throw ce;
           }
-          throw ce;
         }
       }
     } catch (Exception se) {
@@ -246,7 +255,7 @@ public abstract class AbstractDBStore extends 
CatalogConstants implements Catalo
       LOG.error("| You might downgrade or upgrade Apache Tajo. Downgrading or 
upgrading |");
       LOG.error("| Tajo without migration process is only available in some 
versions. |");
       LOG.error("| In order to learn how to migration Apache Tajo instance, 
|");
-      LOG.error("| please refer http://s.apache.org/0_8_migration. |");
+      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.";);
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/75e6dcee/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
----------------------------------------------------------------------
diff --git 
a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
 
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
index 1ea812c..387e91d 100644
--- 
a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
+++ 
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/XMLCatalogSchemaManager.java
@@ -51,9 +51,11 @@ import javax.xml.stream.XMLStreamReader;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.tajo.catalog.CatalogConstants;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.exception.CatalogException;
 import org.apache.tajo.catalog.store.object.*;
+import org.apache.tajo.util.TUtil;
 
 public class XMLCatalogSchemaManager {
   protected final Log LOG = LogFactory.getLog(getClass());
@@ -344,6 +346,33 @@ public class XMLCatalogSchemaManager {
     CatalogUtil.closeQuietly(stmt);
   }
 
+  public boolean catalogAlreadyExists(Connection conn) throws CatalogException 
{
+    boolean result = false;
+    try {
+      List<String> constants = TUtil.newList();
+      constants.add(CatalogConstants.TB_META);
+      constants.add(CatalogConstants.TB_SPACES);
+      constants.add(CatalogConstants.TB_DATABASES);
+      constants.add(CatalogConstants.TB_TABLES);
+      constants.add(CatalogConstants.TB_COLUMNS);
+      constants.add(CatalogConstants.TB_OPTIONS);
+      constants.add(CatalogConstants.TB_INDEXES);
+      constants.add(CatalogConstants.TB_STATISTICS);
+      constants.add(CatalogConstants.TB_PARTITION_METHODS);
+      constants.add(CatalogConstants.TB_PARTTIONS);
+
+      for (String constant : constants) {
+        if (checkExistence(conn, DatabaseObjectType.TABLE, constant)) {
+          return true;
+        }
+      }
+
+    } catch (SQLException e) {
+      throw new CatalogException(e.getMessage(), e);
+    }
+    return result;
+  }
+
   public boolean isInitialized(Connection conn) throws CatalogException {
     if (!isLoaded()) {
       throw new CatalogException("Database schema files are not loaded.");

Reply via email to