Search in sources :

Example 1 with MMetastoreDBProperties

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

the class ObjectStore method createDbGuidAndPersist.

private String createDbGuidAndPersist() throws MetaException {
    boolean success = false;
    Query query = null;
    try {
        openTransaction();
        MMetastoreDBProperties prop = new MMetastoreDBProperties();
        prop.setPropertykey("guid");
        final String guid = UUID.randomUUID().toString();
        LOG.debug("Attempting to add a guid {} for the metastore db", guid);
        prop.setPropertyValue(guid);
        prop.setDescription("Metastore DB GUID generated on " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")));
        pm.makePersistent(prop);
        success = commitTransaction();
        if (success) {
            LOG.info("Metastore db guid {} created successfully", guid);
            return guid;
        }
    } catch (Exception e) {
        LOG.warn("Metastore db guid creation failed", e);
    } finally {
        rollbackAndCleanup(success, query);
    }
    // it possible that some other HMS instance could have created the guid
    // at the same time due which this instance could not create a guid above
    // in such case return the guid already generated
    final String guid = getGuidFromDB();
    if (guid == null) {
        throw new MetaException("Unable to create or fetch the metastore database uuid");
    }
    return guid;
}
Also used : Query(javax.jdo.Query) MMetastoreDBProperties(org.apache.hadoop.hive.metastore.model.MMetastoreDBProperties) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOCanRetryException(javax.jdo.JDOCanRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) JDOException(javax.jdo.JDOException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 2 with MMetastoreDBProperties

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

the class ObjectStore method getGuidFromDB.

private String getGuidFromDB() throws MetaException {
    boolean success = false;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MMetastoreDBProperties.class, "this.propertyKey == key");
        query.declareParameters("java.lang.String key");
        Collection<MMetastoreDBProperties> names = (Collection<MMetastoreDBProperties>) query.execute("guid");
        List<String> uuids = new ArrayList<>();
        for (Iterator<MMetastoreDBProperties> i = names.iterator(); i.hasNext(); ) {
            String uuid = i.next().getPropertyValue();
            LOG.debug("Found guid {}", uuid);
            uuids.add(uuid);
        }
        success = commitTransaction();
        if (uuids.size() > 1) {
            throw new MetaException("Multiple uuids found");
        }
        if (!uuids.isEmpty()) {
            LOG.debug("Returning guid of metastore db : {}", uuids.get(0));
            return uuids.get(0);
        }
    } finally {
        rollbackAndCleanup(success, query);
    }
    LOG.warn("Guid for metastore db not found");
    return null;
}
Also used : Query(javax.jdo.Query) MMetastoreDBProperties(org.apache.hadoop.hive.metastore.model.MMetastoreDBProperties) ArrayList(java.util.ArrayList) Collection(java.util.Collection) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

Query (javax.jdo.Query)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 MMetastoreDBProperties (org.apache.hadoop.hive.metastore.model.MMetastoreDBProperties)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 JDOCanRetryException (javax.jdo.JDOCanRetryException)1 JDODataStoreException (javax.jdo.JDODataStoreException)1 JDOException (javax.jdo.JDOException)1 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)1 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)1 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)1 InvalidPartitionException (org.apache.hadoop.hive.metastore.api.InvalidPartitionException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)1 UnknownPartitionException (org.apache.hadoop.hive.metastore.api.UnknownPartitionException)1