Пример #1
0
  /**
   * 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();
  }
Пример #2
0
 /**
  * * Print Hive version and schema version
  *
  * @throws SentryUserException
  */
 public void showInfo() throws SentryUserException {
   Connection sentryStoreConn = getConnectionToMetastore(true);
   System.out.println(
       "Sentry distribution version:\t " + SentryStoreSchemaInfo.getSentryVersion());
   System.out.println(
       "SentryStore schema version:\t " + getMetaStoreSchemaVersion(sentryStoreConn));
 }
Пример #3
0
  /**
   * Initialize the sentry store schema
   *
   * @param toVersion If null then current hive version is used
   * @throws SentryUserException
   */
  public void doInit(String toVersion) throws SentryUserException {
    testConnectionToMetastore();
    System.out.println("Starting sentry store schema initialization to " + toVersion);

    String initScriptDir = SentryStoreSchemaInfo.getSentryStoreScriptDir();
    String initScriptFile = SentryStoreSchemaInfo.generateInitFileName(toVersion);

    try {
      System.out.println("Initialization script " + initScriptFile);
      if (!dryRun) {
        runBeeLine(initScriptDir, initScriptFile);
        System.out.println("Initialization script completed");
      }
    } catch (IOException e) {
      throw new SentryUserException(
          "Schema initialization FAILED!" + " Metastore state would be inconsistent !!", e);
    }
  }
Пример #4
0
 /**
  * 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);
   }
 }
Пример #5
0
  /**
   * 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();
  }