Search in sources :

Example 1 with MNotificationLog

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

the class ObjectStore method doCleanNotificationEvents.

private int doCleanNotificationEvents(final int ageSec, final Optional<Integer> batchSize) {
    final Transaction tx = pm.currentTransaction();
    int eventsCount = 0;
    try {
        tx.begin();
        try (Query query = pm.newQuery(MNotificationLog.class, "eventTime <= tooOld")) {
            query.declareParameters("java.lang.Integer tooOld");
            query.setOrdering("eventId ascending");
            if (batchSize.isPresent()) {
                query.setRange(0, batchSize.get());
            }
            List<MNotificationLog> events = (List) query.execute(ageSec);
            if (CollectionUtils.isNotEmpty(events)) {
                eventsCount = events.size();
                if (LOG.isDebugEnabled()) {
                    int minEventTime, maxEventTime;
                    long minEventId, maxEventId;
                    Iterator<MNotificationLog> iter = events.iterator();
                    MNotificationLog firstNotification = iter.next();
                    minEventTime = maxEventTime = firstNotification.getEventTime();
                    minEventId = maxEventId = firstNotification.getEventId();
                    while (iter.hasNext()) {
                        MNotificationLog notification = iter.next();
                        minEventTime = Math.min(minEventTime, notification.getEventTime());
                        maxEventTime = Math.max(maxEventTime, notification.getEventTime());
                        minEventId = Math.min(minEventId, notification.getEventId());
                        maxEventId = Math.max(maxEventId, notification.getEventId());
                    }
                    LOG.debug("Remove notification batch of {} events with eventTime < {}, min eventId {}, max eventId {}, min eventTime {}, max eventTime {}", eventsCount, ageSec, minEventId, maxEventId, minEventTime, maxEventTime);
                }
                pm.deletePersistentAll(events);
            }
        }
        tx.commit();
    } catch (Exception e) {
        LOG.error("Unable to delete batch of notification events", e);
        eventsCount = 0;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
    }
    return eventsCount;
}
Also used : Transaction(javax.jdo.Transaction) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MNotificationLog(org.apache.hadoop.hive.metastore.model.MNotificationLog) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) ReplicationMetricList(org.apache.hadoop.hive.metastore.api.ReplicationMetricList) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) ValidReaderWriteIdList(org.apache.hadoop.hive.common.ValidReaderWriteIdList) List(java.util.List) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) 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) 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)

Example 2 with MNotificationLog

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

the class ObjectStore method translateThriftToDb.

private MNotificationLog translateThriftToDb(NotificationEvent entry) {
    MNotificationLog dbEntry = new MNotificationLog();
    dbEntry.setEventId(entry.getEventId());
    dbEntry.setEventTime(entry.getEventTime());
    dbEntry.setEventType(entry.getEventType());
    dbEntry.setCatalogName(entry.isSetCatName() ? entry.getCatName() : getDefaultCatalog(conf));
    dbEntry.setDbName(entry.getDbName());
    dbEntry.setTableName(entry.getTableName());
    dbEntry.setMessage(entry.getMessage());
    dbEntry.setMessageFormat(entry.getMessageFormat());
    return dbEntry;
}
Also used : MNotificationLog(org.apache.hadoop.hive.metastore.model.MNotificationLog)

Example 3 with MNotificationLog

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

the class ObjectStore method getNextNotification.

@Override
public NotificationEventResponse getNextNotification(NotificationEventRequest rqst) {
    boolean commited = false;
    Query query = null;
    NotificationEventResponse result = new NotificationEventResponse();
    result.setEvents(new ArrayList<>());
    try {
        openTransaction();
        long lastEvent = rqst.getLastEvent();
        List<Object> parameterVals = new ArrayList<>();
        parameterVals.add(lastEvent);
        StringBuilder filterBuilder = new StringBuilder("eventId > para" + parameterVals.size());
        StringBuilder parameterBuilder = new StringBuilder("java.lang.Long para" + parameterVals.size());
        if (rqst.isSetEventTypeSkipList()) {
            for (String eventType : rqst.getEventTypeSkipList()) {
                parameterVals.add(eventType);
                parameterBuilder.append(", java.lang.String para" + parameterVals.size());
                filterBuilder.append(" && eventType != para" + parameterVals.size());
            }
        }
        query = pm.newQuery(MNotificationLog.class, filterBuilder.toString());
        query.declareParameters(parameterBuilder.toString());
        query.setOrdering("eventId ascending");
        int maxEventResponse = MetastoreConf.getIntVar(conf, ConfVars.METASTORE_MAX_EVENT_RESPONSE);
        int maxEvents = (rqst.getMaxEvents() < maxEventResponse && rqst.getMaxEvents() > 0) ? rqst.getMaxEvents() : maxEventResponse;
        query.setRange(0, maxEvents);
        Collection<MNotificationLog> events = (Collection) query.executeWithArray(parameterVals.toArray(new Object[0]));
        commited = commitTransaction();
        if (events == null) {
            return result;
        }
        Iterator<MNotificationLog> i = events.iterator();
        while (i.hasNext()) {
            result.addToEvents(translateDbToThrift(i.next()));
        }
        return result;
    } 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) ArrayList(java.util.ArrayList) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) NotificationEventResponse(org.apache.hadoop.hive.metastore.api.NotificationEventResponse) Collection(java.util.Collection) MNotificationLog(org.apache.hadoop.hive.metastore.model.MNotificationLog)

Aggregations

MNotificationLog (org.apache.hadoop.hive.metastore.model.MNotificationLog)3 ArrayList (java.util.ArrayList)2 Query (javax.jdo.Query)2 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)2 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)2 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)2 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)2 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)2 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)2 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 JDODataStoreException (javax.jdo.JDODataStoreException)1 JDOException (javax.jdo.JDOException)1 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)1 Transaction (javax.jdo.Transaction)1