use of org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper.MetaStoreConnectionInfo in project hive by apache.
the class SchemaToolTaskUpgrade method ensureFromVersion.
private void ensureFromVersion() throws HiveMetaException {
MetaStoreConnectionInfo connectionInfo = schemaTool.getConnectionInfo(false);
String dbVersion = null;
try {
dbVersion = schemaTool.getMetaStoreSchemaInfo().getMetaStoreSchemaVersion(connectionInfo);
} catch (HiveMetaException e) {
LOG.info("Exception getting db version:" + e.getMessage());
LOG.info("Try to initialize db schema");
}
if (fromVersion != null) {
if (dbVersion != null && !fromVersion.equals(dbVersion)) {
throw new RuntimeException("The upgradeSchemaFrom version " + fromVersion + " and Metastore schema version " + dbVersion + " are different.");
}
System.out.println("Upgrading from the user input version " + fromVersion);
return;
}
// fromVersion is null
if (dbVersion != null) {
fromVersion = dbVersion;
} else {
// both fromVersion and dbVersion are null
throw new HiveMetaException("Schema version not stored in the metastore. " + "Metastore schema is too old or corrupt. Try specifying the version manually");
}
System.out.println("Upgrading from the version " + fromVersion);
}
use of org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper.MetaStoreConnectionInfo in project hive by apache.
the class SchemaToolTaskValidate method validateSchemaTables.
@VisibleForTesting
boolean validateSchemaTables(Connection conn) throws HiveMetaException {
System.out.println("Validating metastore schema tables");
String version = null;
try {
MetaStoreConnectionInfo connectionInfo = schemaTool.getConnectionInfo(false);
version = schemaTool.getMetaStoreSchemaInfo().getMetaStoreSchemaVersion(connectionInfo);
} catch (HiveMetaException he) {
System.err.println("Failed to determine schema version from Hive Metastore DB. " + he.getMessage());
System.out.println("Failed in schema table validation.");
LOG.debug("Failed to determine schema version from Hive Metastore DB," + he.getMessage(), he);
return false;
}
Connection hmsConn = schemaTool.getConnectionToMetastore(false);
LOG.debug("Validating tables in the schema for version " + version);
List<String> dbTables = new ArrayList<>();
ResultSet rs = null;
try {
String schema = null;
try {
schema = hmsConn.getSchema();
} catch (SQLFeatureNotSupportedException e) {
LOG.debug("schema is not supported");
}
DatabaseMetaData metadata = conn.getMetaData();
rs = metadata.getTables(null, schema, "%", new String[] { "TABLE" });
while (rs.next()) {
String table = rs.getString("TABLE_NAME");
dbTables.add(table.toLowerCase());
LOG.debug("Found table " + table + " in HMS dbstore");
}
} catch (SQLException e) {
throw new HiveMetaException("Failed to retrieve schema tables from Hive Metastore DB," + e.getMessage(), e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
throw new HiveMetaException("Failed to close resultset", e);
}
}
}
// parse the schema file to determine the tables that are expected to exist
// we are using oracle schema because it is simpler to parse, no quotes or backticks etc
List<String> schemaTables = new ArrayList<>();
List<String> subScripts = new ArrayList<>();
String baseDir = new File(schemaTool.getMetaStoreSchemaInfo().getMetaStoreScriptDir()).getParent();
String schemaFile = new File(schemaTool.getMetaStoreSchemaInfo().getMetaStoreScriptDir(), schemaTool.getMetaStoreSchemaInfo().generateInitFileName(version)).getPath();
try {
LOG.debug("Parsing schema script " + schemaFile);
subScripts.addAll(findCreateTable(schemaFile, schemaTables));
while (subScripts.size() > 0) {
schemaFile = baseDir + "/" + schemaTool.getDbType() + "/" + subScripts.remove(0);
LOG.debug("Parsing subscript " + schemaFile);
subScripts.addAll(findCreateTable(schemaFile, schemaTables));
}
} catch (Exception e) {
System.err.println("Exception in parsing schema file. Cause:" + e.getMessage());
System.out.println("Failed in schema table validation.");
return false;
}
LOG.debug("Schema tables:[ " + Arrays.toString(schemaTables.toArray()) + " ]");
LOG.debug("DB tables:[ " + Arrays.toString(dbTables.toArray()) + " ]");
// now diff the lists
schemaTables.removeAll(dbTables);
if (schemaTables.size() > 0) {
Collections.sort(schemaTables);
System.err.println("Table(s) [ " + Arrays.toString(schemaTables.toArray()) + " ] " + "are missing from the metastore database schema.");
System.out.println("[FAIL]\n");
return false;
} else {
System.out.println("[SUCCESS]\n");
return true;
}
}
use of org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper.MetaStoreConnectionInfo in project hive by apache.
the class SchemaToolTaskValidate method validateSchemaVersions.
boolean validateSchemaVersions() throws HiveMetaException {
System.out.println("Validating schema version");
try {
String hiveSchemaVersion = schemaTool.getMetaStoreSchemaInfo().getHiveSchemaVersion();
MetaStoreConnectionInfo connectionInfo = schemaTool.getConnectionInfo(false);
String newSchemaVersion = schemaTool.getMetaStoreSchemaInfo().getMetaStoreSchemaVersion(connectionInfo);
schemaTool.assertCompatibleVersion(hiveSchemaVersion, newSchemaVersion);
} catch (HiveMetaException hme) {
if (hme.getMessage().contains("Metastore schema version is not compatible") || hme.getMessage().contains("Multiple versions were found in metastore") || hme.getMessage().contains("Could not find version info in metastore VERSION table")) {
System.err.println(hme.getMessage());
System.out.println("[FAIL]\n");
return false;
} else {
throw hme;
}
}
System.out.println("[SUCCESS]\n");
return true;
}
use of org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper.MetaStoreConnectionInfo in project hive by apache.
the class SchemaToolTaskInfo method execute.
@Override
void execute() throws HiveMetaException {
String hiveVersion = schemaTool.getMetaStoreSchemaInfo().getHiveSchemaVersion();
MetaStoreConnectionInfo connectionInfo = schemaTool.getConnectionInfo(true);
String dbVersion = schemaTool.getMetaStoreSchemaInfo().getMetaStoreSchemaVersion(connectionInfo);
System.out.println("Hive distribution version:\t " + hiveVersion);
System.out.println("Metastore schema version:\t " + dbVersion);
schemaTool.assertCompatibleVersion(hiveVersion, dbVersion);
}
Aggregations