Search in sources :

Example 6 with ScheduledQueryPollResponse

use of org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse in project hive by apache.

the class TestMetastoreScheduledQueries method testExclusivePoll.

@Test
public void testExclusivePoll() throws Exception {
    try {
        ObjectStoreTestHook.instance = new ObjectStoreTestHook() {

            @Override
            public void scheduledQueryPoll() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        ScheduledQuery schq = createScheduledQuery(new ScheduledQueryKey("q1", "exclusive"));
        ScheduledQueryMaintenanceRequest r = new ScheduledQueryMaintenanceRequest();
        r.setType(ScheduledQueryMaintenanceRequestType.CREATE);
        r.setScheduledQuery(schq);
        client.scheduledQueryMaintenance(r);
        // wait 1 sec for next execution
        Thread.sleep(1000);
        ExecutorService pool = Executors.newCachedThreadPool();
        Future<ScheduledQueryPollResponse> f1 = pool.submit(new AsyncPollCall("exclusive"));
        Future<ScheduledQueryPollResponse> f2 = pool.submit(new AsyncPollCall("exclusive"));
        ScheduledQueryPollResponse resp1 = f1.get();
        ScheduledQueryPollResponse resp2 = f2.get();
        assertTrue(resp1.isSetQuery() ^ resp2.isSetQuery());
        pool.shutdown();
    } finally {
        ObjectStoreTestHook.instance = null;
    }
}
Also used : ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) ScheduledQueryMaintenanceRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest) ExecutorService(java.util.concurrent.ExecutorService) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ObjectStoreTestHook(org.apache.hadoop.hive.metastore.ObjectStoreTestHook) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Example 7 with ScheduledQueryPollResponse

use of org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse in project hive by apache.

the class ObjectStore method scheduledQueryPoll.

@Override
public ScheduledQueryPollResponse scheduledQueryPoll(ScheduledQueryPollRequest request) throws MetaException {
    ensureScheduledQueriesEnabled();
    boolean commited = false;
    ScheduledQueryPollResponse ret = new ScheduledQueryPollResponse();
    Query q = null;
    try {
        openTransaction();
        q = pm.newQuery(MScheduledQuery.class, "nextExecution <= now && enabled && clusterNamespace == ns && activeExecution == null");
        q.setSerializeRead(true);
        q.declareParameters("java.lang.Integer now, java.lang.String ns");
        q.setOrdering("nextExecution");
        int now = (int) (System.currentTimeMillis() / 1000);
        List<MScheduledQuery> results = (List<MScheduledQuery>) q.execute(now, request.getClusterNamespace());
        if (results == null || results.isEmpty()) {
            return new ScheduledQueryPollResponse();
        }
        MScheduledQuery schq = results.get(0);
        schq.setNextExecution(computeNextExecutionTime(schq.getSchedule()));
        MScheduledExecution execution = new MScheduledExecution();
        execution.setScheduledQuery(schq);
        execution.setState(QueryState.INITED);
        execution.setStartTime(now);
        execution.setLastUpdateTime(now);
        schq.setActiveExecution(execution);
        pm.makePersistent(execution);
        pm.makePersistent(schq);
        ObjectStoreTestHook.onScheduledQueryPoll();
        commited = commitTransaction();
        ret.setScheduleKey(schq.getScheduleKey());
        ret.setQuery("/* schedule: " + schq.getScheduleName() + " */" + schq.getQuery());
        ret.setUser(schq.getUser());
        int executionId = ((IntIdentity) pm.getObjectId(execution)).getKey();
        ret.setExecutionId(executionId);
    } catch (JDOException e) {
        LOG.debug("Caught jdo exception; exclusive", e);
        commited = false;
    } finally {
        rollbackAndCleanup(commited, q);
        return commited ? ret : new ScheduledQueryPollResponse();
    }
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MScheduledExecution(org.apache.hadoop.hive.metastore.model.MScheduledExecution) ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) IntIdentity(javax.jdo.identity.IntIdentity) 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) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) 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) JDOException(javax.jdo.JDOException)

Aggregations

ScheduledQueryPollResponse (org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse)7 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)6 ScheduledQueryKey (org.apache.hadoop.hive.metastore.api.ScheduledQueryKey)5 ScheduledQueryPollRequest (org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest)5 MetastoreUnitTest (org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest)4 ScheduledQueryMaintenanceRequest (org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest)4 MScheduledExecution (org.apache.hadoop.hive.metastore.model.MScheduledExecution)4 Test (org.junit.Test)4 PersistenceManager (javax.jdo.PersistenceManager)3 ObjectStore (org.apache.hadoop.hive.metastore.ObjectStore)2 ScheduledQueryProgressInfo (org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 JDOException (javax.jdo.JDOException)1 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)1 Query (javax.jdo.Query)1 IntIdentity (javax.jdo.identity.IntIdentity)1 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)1