private void ensureToVersion() throws HiveMetaException { if (toVersion != null) { return; } // If null then current hive version is used toVersion = schemaTool.getMetaStoreSchemaInfo().getHiveSchemaVersion(); System.out.println("Initializing the schema to: " + toVersion); }
/** * check if the current schema version in metastore matches the Hive version */ @VisibleForTesting void verifySchemaVersion() throws HiveMetaException { // don't check version if its a dry run if (dryRun) { return; } String newSchemaVersion = metaStoreSchemaInfo.getMetaStoreSchemaVersion(getConnectionInfo(false)); // verify that the new version is added to schema assertCompatibleVersion(metaStoreSchemaInfo.getHiveSchemaVersion(), newSchemaVersion); }
@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); } }
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; }
@Override void execute() throws HiveMetaException { ensureFromVersion(); if (schemaTool.getMetaStoreSchemaInfo().getHiveSchemaVersion().equals(fromVersion)) { System.out.println("No schema upgrade required from version " + fromVersion); return; } // Find the list of scripts to execute for this upgrade List<String> upgradeScripts = schemaTool.getMetaStoreSchemaInfo().getUpgradeScripts(fromVersion); schemaTool.testConnectionToMetastore(); System.out.println("Starting upgrade metastore schema from version " + fromVersion + " to " + schemaTool.getMetaStoreSchemaInfo().getHiveSchemaVersion()); String scriptDir = schemaTool.getMetaStoreSchemaInfo().getMetaStoreScriptDir(); try { for (String scriptFile : upgradeScripts) { System.out.println("Upgrade script " + scriptFile); if (!schemaTool.isDryRun()) { runPreUpgrade(scriptDir, scriptFile); schemaTool.execSql(scriptDir, scriptFile); System.out.println("Completed " + scriptFile); } } } catch (IOException e) { throw new HiveMetaException("Upgrade FAILED! Metastore state would be inconsistent !!", e); } // Revalidated the new version after upgrade schemaTool.verifySchemaVersion(); }
String hiveSchemaVer = metastoreSchemaInfo.getHiveSchemaVersion();
if (e.getCause() instanceof MissingTableException) { throw new MetaException("Version table not found. " + "The metastore is not upgraded to " + MetaStoreSchemaInfoFactory.get(getConf()).getHiveSchemaVersion()); } else { throw e;
/** * Test schema initialization */ @Test public void testSchemaInit() throws Exception { IMetaStoreSchemaInfo metastoreSchemaInfo = MetaStoreSchemaInfoFactory.get(conf, System.getProperty("test.tmp.dir", "target/tmp"), "derby"); execute(new SchemaToolTaskInit(), "-initSchemaTo " + metastoreSchemaInfo.getHiveSchemaVersion()); schemaTool.verifySchemaVersion(); }
/*** * Print Hive version and schema version * @throws MetaException */ public void showInfo() throws HiveMetaException { String hiveVersion = metaStoreSchemaInfo.getHiveSchemaVersion(); String dbVersion = metaStoreSchemaInfo.getMetaStoreSchemaVersion(getConnectionInfo(true)); System.out.println("Hive distribution version:\t " + hiveVersion); System.out.println("Metastore schema version:\t " + dbVersion); assertCompatibleVersion(hiveVersion, dbVersion); }
/** * Initialize the metastore schema to current version * * @throws MetaException */ public void doInit() throws HiveMetaException { doInit(metaStoreSchemaInfo.getHiveSchemaVersion()); // Revalidated the new version after upgrade verifySchemaVersion(); }
/** * check if the current schema version in metastore matches the Hive version * @throws MetaException */ public void verifySchemaVersion() throws HiveMetaException { // don't check version if its a dry run if (dryRun) { return; } String newSchemaVersion = metaStoreSchemaInfo.getMetaStoreSchemaVersion(getConnectionInfo(false)); // verify that the new version is added to schema assertCompatibleVersion(metaStoreSchemaInfo.getHiveSchemaVersion(), newSchemaVersion); }
boolean validateSchemaVersions() throws HiveMetaException { System.out.println("Validating schema version"); try { String newSchemaVersion = metaStoreSchemaInfo.getMetaStoreSchemaVersion(getConnectionInfo(false)); assertCompatibleVersion(metaStoreSchemaInfo.getHiveSchemaVersion(), 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("Failed in schema version validation."); return false; } else { throw hme; } } System.out.println("Succeeded in schema version validation."); return true; }
if (metaStoreSchemaInfo.getHiveSchemaVersion().equals(fromSchemaVer)) { System.out.println("No schema upgrade required from version " + fromSchemaVer); return; testConnectionToMetastore(); System.out.println("Starting upgrade metastore schema from version " + fromSchemaVer + " to " + metaStoreSchemaInfo.getHiveSchemaVersion()); String scriptDir = metaStoreSchemaInfo.getMetaStoreScriptDir(); try {
String hiveSchemaVer = metastoreSchemaInfo.getHiveSchemaVersion();
if (e.getCause() instanceof MissingTableException) { throw new MetaException("Version table not found. " + "The metastore is not upgraded to " + MetaStoreSchemaInfoFactory.get(getConf()).getHiveSchemaVersion()); } else { throw e;