/** * Perform sentry store schema upgrade * * @param fromSchemaVer Existing version of the sentry store. If null, then read from the sentry * store * @throws SentryUserException */ public void doUpgrade(String fromSchemaVer) throws SentryUserException { if (SentryStoreSchemaInfo.getSentrySchemaVersion().equals(fromSchemaVer)) { System.out.println("No schema upgrade required from version " + fromSchemaVer); return; } // Find the list of scripts to execute for this upgrade List<String> upgradeScripts = SentryStoreSchemaInfo.getUpgradeScripts(fromSchemaVer); testConnectionToMetastore(); System.out.println( "Starting upgrade sentry store schema from version " + fromSchemaVer + " to " + SentryStoreSchemaInfo.getSentrySchemaVersion()); String scriptDir = SentryStoreSchemaInfo.getSentryStoreScriptDir(); try { for (String scriptFile : upgradeScripts) { System.out.println("Upgrade script " + scriptFile); if (!dryRun) { runBeeLine(scriptDir, scriptFile); System.out.println("Completed " + scriptFile); } } } catch (IOException eIO) { throw new SentryUserException( "Upgrade FAILED! Metastore state would be inconsistent !!", eIO); } // Revalidated the new version after upgrade verifySchemaVersion(); }
/** * check if the current schema version in sentry store matches the Hive version * * @throws SentryUserException */ public void verifySchemaVersion() throws SentryUserException { // don't check version if its a dry run if (dryRun) { return; } String newSchemaVersion = getMetaStoreSchemaVersion(getConnectionToMetastore(false)); // verify that the new version is added to schema if (!SentryStoreSchemaInfo.getSentrySchemaVersion().equalsIgnoreCase(newSchemaVersion)) { throw new SentryUserException("Found unexpected schema version " + newSchemaVersion); } }
/** * Initialize the sentry store schema to current version * * @throws SentryUserException */ public void doInit() throws SentryUserException { doInit(SentryStoreSchemaInfo.getSentrySchemaVersion()); // Revalidated the new version after upgrade verifySchemaVersion(); }