Search in sources :

Example 1 with MNotificationNextId

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

the class ObjectStore method getCurrentNotificationEventId.

@Override
public CurrentNotificationEventId getCurrentNotificationEventId() {
    boolean commited = false;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MNotificationNextId.class);
        Collection<MNotificationNextId> ids = (Collection) query.execute();
        long id = 0;
        if (CollectionUtils.isNotEmpty(ids)) {
            id = ids.iterator().next().getNextEventId() - 1;
        }
        commited = commitTransaction();
        return new CurrentNotificationEventId(id);
    } finally {
        rollbackAndCleanup(commited, query);
    }
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MNotificationNextId(org.apache.hadoop.hive.metastore.model.MNotificationNextId) Collection(java.util.Collection) CurrentNotificationEventId(org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId)

Example 2 with MNotificationNextId

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

the class ObjectStore method addNotificationEvent.

@Override
public void addNotificationEvent(NotificationEvent entry) throws MetaException {
    boolean commited = false;
    Query query = null;
    try {
        pm.flush();
        openTransaction();
        lockNotificationSequenceForUpdate();
        query = pm.newQuery(MNotificationNextId.class);
        Collection<MNotificationNextId> ids = (Collection) query.execute();
        MNotificationNextId mNotificationNextId = null;
        boolean needToPersistId;
        if (CollectionUtils.isEmpty(ids)) {
            mNotificationNextId = new MNotificationNextId(1L);
            needToPersistId = true;
        } else {
            mNotificationNextId = ids.iterator().next();
            needToPersistId = false;
        }
        entry.setEventId(mNotificationNextId.getNextEventId());
        mNotificationNextId.incrementEventId();
        if (needToPersistId) {
            pm.makePersistent(mNotificationNextId);
        }
        pm.makePersistent(translateThriftToDb(entry));
        commited = commitTransaction();
    } catch (MetaException e) {
        LOG.error("Couldn't get lock for update", e);
        throw e;
    } finally {
        rollbackAndCleanup(commited, query);
    }
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MNotificationNextId(org.apache.hadoop.hive.metastore.model.MNotificationNextId) Collection(java.util.Collection) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

Collection (java.util.Collection)2 Query (javax.jdo.Query)2 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)2 MNotificationNextId (org.apache.hadoop.hive.metastore.model.MNotificationNextId)2 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)2 CurrentNotificationEventId (org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1