ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [36/55] [abbrv] ambari git commit: AMBARI-18951. Force InnoDB usage for MySQL. (mpapirkovskyy)
Date Tue, 29 Nov 2016 17:56:43 GMT
AMBARI-18951. Force InnoDB usage for MySQL. (mpapirkovskyy)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/255725df
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/255725df
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/255725df

Branch: refs/heads/branch-feature-AMBARI-18634
Commit: 255725dfc07a4a4fd7fc8b3f6cdbd7cced1c375a
Parents: abf9882
Author: Myroslav Papirkovskyi <mpapyrkovskyy@hortonworks.com>
Authored: Mon Nov 28 18:25:07 2016 +0200
Committer: Myroslav Papirkovskyi <mpapyrkovskyy@hortonworks.com>
Committed: Mon Nov 28 18:46:01 2016 +0200

----------------------------------------------------------------------
 .../server/orm/helpers/dbms/MySqlHelper.java    | 18 ++++++++++
 .../server/upgrade/SchemaUpgradeHelper.java     | 35 +++++++++++++++++++-
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  1 +
 3 files changed, 53 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/255725df/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
index 38fe062..8a83c90 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
@@ -19,8 +19,13 @@
 package org.apache.ambari.server.orm.helpers.dbms;
 
 import org.apache.ambari.server.orm.DBAccessor;
+import org.eclipse.persistence.exceptions.ValidationException;
 import org.eclipse.persistence.platform.database.DatabasePlatform;
 
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
 public class MySqlHelper extends GenericDbmsHelper {
   public MySqlHelper(DatabasePlatform databasePlatform) {
     super(databasePlatform);
@@ -75,4 +80,17 @@ public class MySqlHelper extends GenericDbmsHelper {
                                     .append("AND constraints.TABLE_NAME = \"").append(tableName).append("\"");
     return statement.toString();
   }
+
+  @Override
+  public Writer writeCreateTableStatement(Writer writer, String tableName,
+                                          List<DBAccessor.DBColumnInfo> columns,
+                                          List<String> primaryKeyColumns) {
+    Writer defaultWriter = super.writeCreateTableStatement(writer, tableName, columns, primaryKeyColumns);
+    try {
+      defaultWriter.write(" ENGINE=INNODB");
+    } catch (IOException e) {
+      throw ValidationException.fileError(e);
+    }
+    return defaultWriter;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/255725df/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
index 5bf7f21..33ec732 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
@@ -45,6 +45,7 @@ import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.multibindings.Multibinder;
 import com.google.inject.persist.PersistService;
+import org.springframework.jdbc.support.JdbcUtils;
 
 public class SchemaUpgradeHelper {
   private static final Logger LOG = LoggerFactory.getLogger
@@ -331,7 +332,7 @@ public class SchemaUpgradeHelper {
   /**
    * Checks if source version meets minimal requirements for upgrade
    *
-   * @param minUpgradeVersion min allowed version for the upgrade, could be obtained via
{@link SchemaUpgradeHelper.getMinimalUpgradeCatalogVersion}
+   * @param minUpgradeVersion min allowed version for the upgrade, could be obtained via
{@link #getMinimalUpgradeCatalogVersion()}
    * @param sourceVersion current version of the Database, which need to be upgraded
    *
    * @return  true if upgrade is allowed or false if not
@@ -344,6 +345,29 @@ public class SchemaUpgradeHelper {
     return VersionUtils.compareVersions(sourceVersion, minUpgradeVersion) >= 0;
   }
 
+  private List<String> getMyISAMTables() throws SQLException {
+    if (!configuration.getDatabaseType().equals(Configuration.DatabaseType.MYSQL)) {
+      return Collections.emptyList();
+    }
+    List<String> myISAMTables = new ArrayList<>();
+    String query = String.format("SELECT table_name FROM information_schema.tables WHERE
table_schema = '%s' " +
+      "AND engine = 'MyISAM' AND table_type = 'BASE TABLE'", configuration.getServerDBName());
+    Statement statement = null;
+    ResultSet rs = null;
+    try {
+      statement = dbAccessor.getConnection().createStatement();
+      rs = statement.executeQuery(query);
+      if (rs != null) {
+        while (rs.next()) {
+          myISAMTables.add(rs.getString("table_name"));
+        }
+      }
+    } finally {
+      JdbcUtils.closeResultSet(rs);
+      JdbcUtils.closeStatement(statement);
+    }
+    return myISAMTables;
+  }
 
   /**
    * Upgrade Ambari DB schema to the target version passed in as the only
@@ -364,6 +388,15 @@ public class SchemaUpgradeHelper {
       Injector injector = Guice.createInjector(new UpgradeHelperModule(), new AuditLoggerModule());
       SchemaUpgradeHelper schemaUpgradeHelper = injector.getInstance(SchemaUpgradeHelper.class);
 
+      //Fail if MySQL database has tables with MyISAM engine
+      List<String> myISAMTables = schemaUpgradeHelper.getMyISAMTables();
+      if (!myISAMTables.isEmpty()) {
+        String errorMessage = String.format("Unsupported MyISAM table %s detected. " +
+            "For correct upgrade database should be migrated to InnoDB engine.", myISAMTables.get(0));
+        LOG.error(errorMessage);
+        throw new AmbariException(errorMessage);
+      }
+
       String targetVersion = schemaUpgradeHelper.getAmbariServerVersion();
       LOG.info("Upgrading schema to target version = " + targetVersion);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/255725df/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 09042b5..b01ed2f 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -26,6 +26,7 @@ delimiter ;
 
 # USE @schema;
 
+SET default_storage_engine=INNODB;
 
 CREATE TABLE stack(
   stack_id BIGINT NOT NULL,


Mime
View raw message