This is an automated email from the ASF dual-hosted git repository.
ngangam pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 70d4712 HIVE-22739: Schematool should check if upgradeFrom version is
identical to current DB schema version (Alice Fan reviewed by Naveen Gangam)
70d4712 is described below
commit 70d4712cb1137958b45dd2cac00e52dd7e532225
Author: Naveen Gangam <[email protected]>
AuthorDate: Tue Jan 28 02:25:10 2020 -0500
HIVE-22739: Schematool should check if upgradeFrom version is identical to
current DB schema version (Alice Fan reviewed by Naveen Gangam)
---
.../tools/schematool/SchemaToolTaskUpgrade.java | 27 ++++++++++++++++++----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/schematool/SchemaToolTaskUpgrade.java
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/schematool/SchemaToolTaskUpgrade.java
index 0588342..8f615b3 100644
---
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/schematool/SchemaToolTaskUpgrade.java
+++
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/schematool/SchemaToolTaskUpgrade.java
@@ -24,10 +24,13 @@ import java.util.List;
import org.apache.hadoop.hive.metastore.HiveMetaException;
import
org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper.MetaStoreConnectionInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Perform metastore schema upgrade.
*/
class SchemaToolTaskUpgrade extends SchemaToolTask {
+ private static final Logger LOG =
LoggerFactory.getLogger(SchemaToolTaskUpgrade.class);
private String fromVersion;
@Override
@@ -38,14 +41,28 @@ class SchemaToolTaskUpgrade extends SchemaToolTask {
}
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;
}
-
- // If null, then read from the metastore
- MetaStoreConnectionInfo connectionInfo =
schemaTool.getConnectionInfo(false);
- fromVersion =
schemaTool.getMetaStoreSchemaInfo().getMetaStoreSchemaVersion(connectionInfo);
- if (fromVersion == null || fromVersion.isEmpty()) {
+ // 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");
}