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;
}
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;
}
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);
}
}
Aggregations