Search in sources :

Example 1 with MTxnWriteNotificationLog

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);
}
Also used : PersistenceManager(javax.jdo.PersistenceManager) MTxnWriteNotificationLog(org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog)

Example 2 with MTxnWriteNotificationLog

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;
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) WriteEventInfo(org.apache.hadoop.hive.metastore.api.WriteEventInfo) ArrayList(java.util.ArrayList) 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) MTxnWriteNotificationLog(org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog)

Example 3 with MTxnWriteNotificationLog

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);
    }
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) 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) MTxnWriteNotificationLog(org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog)

Aggregations

MTxnWriteNotificationLog (org.apache.hadoop.hive.metastore.model.MTxnWriteNotificationLog)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Query (javax.jdo.Query)2 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)2 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)2 ReplicationMetricList (org.apache.hadoop.hive.metastore.api.ReplicationMetricList)2 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)2 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)2 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)2 PersistenceManager (javax.jdo.PersistenceManager)1 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)1 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)1 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)1 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)1 WriteEventInfo (org.apache.hadoop.hive.metastore.api.WriteEventInfo)1 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)1