Search in sources :

Example 1 with MVersionTable

use of org.apache.hadoop.hive.metastore.model.MVersionTable in project hive by apache.

the class ObjectStore method setMetaStoreSchemaVersion.

@Override
public void setMetaStoreSchemaVersion(String schemaVersion, String comment) throws MetaException {
    MVersionTable mSchemaVer;
    boolean commited = false;
    boolean recordVersion = HiveConf.getBoolVar(getConf(), HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION_RECORD_VERSION);
    if (!recordVersion) {
        LOG.warn("setMetaStoreSchemaVersion called but recording version is disabled: " + "version = " + schemaVersion + ", comment = " + comment);
        return;
    }
    LOG.warn("Setting metastore schema version in db to " + schemaVersion);
    try {
        mSchemaVer = getMSchemaVersion();
    } catch (NoSuchObjectException e) {
        // if the version doesn't exist, then create it
        mSchemaVer = new MVersionTable();
    }
    mSchemaVer.setSchemaVersion(schemaVersion);
    mSchemaVer.setVersionComment(comment);
    try {
        openTransaction();
        pm.makePersistent(mSchemaVer);
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
}
Also used : MVersionTable(org.apache.hadoop.hive.metastore.model.MVersionTable) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 2 with MVersionTable

use of org.apache.hadoop.hive.metastore.model.MVersionTable in project hive by apache.

the class ObjectStore method getMSchemaVersion.

@SuppressWarnings("unchecked")
private MVersionTable getMSchemaVersion() throws NoSuchObjectException, MetaException {
    boolean committed = false;
    Query query = null;
    List<MVersionTable> mVerTables = new ArrayList<MVersionTable>();
    try {
        openTransaction();
        query = pm.newQuery(MVersionTable.class);
        try {
            mVerTables = (List<MVersionTable>) query.execute();
            pm.retrieveAll(mVerTables);
        } catch (JDODataStoreException e) {
            if (e.getCause() instanceof MissingTableException) {
                throw new MetaException("Version table not found. " + "The metastore is not upgraded to " + MetaStoreSchemaInfo.getHiveSchemaVersion());
            } else {
                throw e;
            }
        }
        committed = commitTransaction();
        if (mVerTables.isEmpty()) {
            throw new NoSuchObjectException("No matching version found");
        }
        if (mVerTables.size() > 1) {
            String msg = "Metastore contains multiple versions (" + mVerTables.size() + ") ";
            for (MVersionTable version : mVerTables) {
                msg += "[ version = " + version.getSchemaVersion() + ", comment = " + version.getVersionComment() + " ] ";
            }
            throw new MetaException(msg.trim());
        }
        return mVerTables.get(0);
    } finally {
        if (!committed) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
}
Also used : Query(javax.jdo.Query) MVersionTable(org.apache.hadoop.hive.metastore.model.MVersionTable) ArrayList(java.util.ArrayList) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) JDODataStoreException(javax.jdo.JDODataStoreException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)2 MVersionTable (org.apache.hadoop.hive.metastore.model.MVersionTable)2 ArrayList (java.util.ArrayList)1 JDODataStoreException (javax.jdo.JDODataStoreException)1 Query (javax.jdo.Query)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 MissingTableException (org.datanucleus.store.rdbms.exceptions.MissingTableException)1