use of org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog in project hive by apache.
the class TestGetAllWriteEventInfo method insertTxnWriteNotificationLog.
private MTxnWriteNotificationLog insertTxnWriteNotificationLog(long txnId, long writeId, String dbName, String tableName) {
// We use objectStore to insert record directly into DB so that we don't need DbNotificationListener,
// which will introduce cyclic dependency.
PersistenceManager pm = objectStore.getPersistenceManager();
MTxnWriteNotificationLog log = new MTxnWriteNotificationLog(txnId, writeId, 1, dbName, tableName, "", "", "", "");
return pm.makePersistent(log);
}
use of org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog in project hive by apache.
the class ObjectStore method getAllWriteEventInfo.
@Override
public List<WriteEventInfo> getAllWriteEventInfo(long txnId, String dbName, String tableName) throws MetaException {
List<WriteEventInfo> writeEventInfoList = null;
boolean commited = false;
Query query = null;
try {
openTransaction();
List<String> parameterVals = new ArrayList<>();
StringBuilder filterBuilder = new StringBuilder(" txnId == " + Long.toString(txnId));
if (dbName != null && !"*".equals(dbName)) {
// * means get all database, so no need to add filter
appendSimpleCondition(filterBuilder, "database", new String[] { dbName }, parameterVals);
}
if (tableName != null && !"*".equals(tableName)) {
appendSimpleCondition(filterBuilder, "table", new String[] { tableName }, parameterVals);
}
query = pm.newQuery(MTxnWriteNotificationLog.class, filterBuilder.toString());
query.setOrdering("database,table ascending");
List<MTxnWriteNotificationLog> mplans = (List<MTxnWriteNotificationLog>) query.executeWithArray(parameterVals.toArray(new String[0]));
pm.retrieveAll(mplans);
commited = commitTransaction();
if (mplans != null && mplans.size() > 0) {
writeEventInfoList = Lists.newArrayList();
for (MTxnWriteNotificationLog mplan : mplans) {
WriteEventInfo writeEventInfo = new WriteEventInfo(mplan.getWriteId(), mplan.getDatabase(), mplan.getTable(), mplan.getFiles());
writeEventInfo.setPartition(mplan.getPartition());
writeEventInfo.setPartitionObj(mplan.getPartObject());
writeEventInfo.setTableObj(mplan.getTableObject());
writeEventInfoList.add(writeEventInfo);
}
}
} finally {
rollbackAndCleanup(commited, query);
}
return writeEventInfoList;
}
use of org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog in project hive by apache.
the class ObjectStore method cleanWriteNotificationEvents.
@Override
public void cleanWriteNotificationEvents(int olderThan) {
boolean commited = false;
Query query = null;
try {
openTransaction();
long tmp = System.currentTimeMillis() / 1000 - olderThan;
int tooOld = (tmp > Integer.MAX_VALUE) ? 0 : (int) tmp;
query = pm.newQuery(MTxnWriteNotificationLog.class, "eventTime < tooOld");
query.declareParameters("java.lang.Integer tooOld");
int max_events = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS);
max_events = max_events > 0 ? max_events : Integer.MAX_VALUE;
query.setRange(0, max_events);
query.setOrdering("txnId ascending");
List<MTxnWriteNotificationLog> toBeRemoved = (List) query.execute(tooOld);
int iteration = 0;
int eventCount = 0;
long minTxnId = 0;
long minEventTime = 0;
long maxTxnId = 0;
long maxEventTime = 0;
while (CollectionUtils.isNotEmpty(toBeRemoved)) {
int listSize = toBeRemoved.size();
if (iteration == 0) {
MTxnWriteNotificationLog firstNotification = toBeRemoved.get(0);
minTxnId = firstNotification.getTxnId();
minEventTime = firstNotification.getEventTime();
}
MTxnWriteNotificationLog lastNotification = toBeRemoved.get(listSize - 1);
maxTxnId = lastNotification.getTxnId();
maxEventTime = lastNotification.getEventTime();
pm.deletePersistentAll(toBeRemoved);
eventCount += listSize;
iteration++;
toBeRemoved = (List) query.execute(tooOld);
}
if (iteration == 0) {
LOG.info("No WriteNotification events found to be cleaned with eventTime < {}.", tooOld);
} else {
LOG.info("WriteNotification Cleaned {} events with eventTime < {} in {} iteration, " + "minimum txnId {} (with eventTime {}) and maximum txnId {} (with eventTime {})", eventCount, tooOld, iteration, minTxnId, minEventTime, maxTxnId, maxEventTime);
}
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
}
Aggregations