use of org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo in project hive by apache.
the class TestMetastoreScheduledQueries method testDisabledProgress.
// (expected = MetaException.class)
@Test
public void testDisabledProgress() throws MetaException, TException {
try {
MetastoreConf.setBoolVar(metaStore.getConf(), ConfVars.SCHEDULED_QUERIES_ENABLED, false);
ObjectStore objStore = new ObjectStore();
objStore.setConf(metaStore.getConf());
thrown.expect(MetaException.class);
thrown.expectMessage(Matchers.contains(ConfVars.SCHEDULED_QUERIES_ENABLED.getVarname()));
objStore.scheduledQueryProgress(new ScheduledQueryProgressInfo());
} finally {
MetastoreConf.setBoolVar(metaStore.getConf(), ConfVars.SCHEDULED_QUERIES_ENABLED, true);
}
}
use of org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo in project hive by apache.
the class TestMetastoreScheduledQueries method testPoll.
@Test
public void testPoll() throws Exception {
ScheduledQuery schq = createScheduledQuery(new ScheduledQueryKey("q1", "polltest"));
ScheduledQueryMaintenanceRequest r = new ScheduledQueryMaintenanceRequest();
r.setType(ScheduledQueryMaintenanceRequestType.CREATE);
r.setScheduledQuery(schq);
client.scheduledQueryMaintenance(r);
schq.setScheduleKey(new ScheduledQueryKey("q1", "polltestOther"));
client.scheduledQueryMaintenance(r);
// disabled queries are not considered
schq.setScheduleKey(new ScheduledQueryKey("q2disabled", "polltest"));
schq.setEnabled(false);
client.scheduledQueryMaintenance(r);
// do some poll requests; and wait for q1's execution
ScheduledQueryPollRequest request = new ScheduledQueryPollRequest();
request.setClusterNamespace("polltest");
ScheduledQueryPollResponse pollResult = null;
// wait for poll to hit
for (int i = 0; i < 30; i++) {
pollResult = client.scheduledQueryPoll(request);
if (pollResult.isSetQuery()) {
break;
}
Thread.sleep(100);
}
assertTrue(pollResult.isSetQuery());
assertTrue(pollResult.isSetScheduleKey());
assertTrue(pollResult.isSetExecutionId());
// after reading the only scheduled query; there are no more queries to run (for 1 sec)
ScheduledQueryPollResponse pollResult2 = client.scheduledQueryPoll(request);
assertTrue(!pollResult2.isSetQuery());
try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
MScheduledExecution q = pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
assertNotNull(q);
assertEquals(QueryState.INITED, q.getState());
assertTrue(q.getStartTime() <= getEpochSeconds());
assertTrue(q.getStartTime() >= getEpochSeconds() - 1);
assertTrue(q.getEndTime() == null);
assertTrue(q.getLastUpdateTime() <= getEpochSeconds());
assertTrue(q.getLastUpdateTime() >= getEpochSeconds() - 1);
}
// wait 1 sec
Thread.sleep(1000);
ScheduledQueryProgressInfo info;
info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.EXECUTING, "executor-query-id");
client.scheduledQueryProgress(info);
try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
MScheduledExecution q = pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
assertEquals(QueryState.EXECUTING, q.getState());
assertEquals("executor-query-id", q.getExecutorQueryId());
assertTrue(q.getLastUpdateTime() <= getEpochSeconds());
assertTrue(q.getLastUpdateTime() >= getEpochSeconds() - 1);
}
// wait 1 sec
Thread.sleep(1000);
info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.FAILED, "executor-query-id");
info.setErrorMessage(generateLongErrorMessage());
// info.set
client.scheduledQueryProgress(info);
try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
MScheduledExecution q = pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
assertEquals(QueryState.FAILED, q.getState());
assertEquals("executor-query-id", q.getExecutorQueryId());
assertNull(q.getLastUpdateTime());
assertTrue(q.getEndTime() <= getEpochSeconds());
assertTrue(q.getEndTime() >= getEpochSeconds() - 1);
assertTrue(q.getErrorMessage().length() < 2000);
assertFalse(q.getErrorMessage().contains("x"));
}
// clustername is taken into account; this should be empty
request.setClusterNamespace("polltestSomethingElse");
pollResult = client.scheduledQueryPoll(request);
assertFalse(pollResult.isSetQuery());
}
use of org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo in project hive by apache.
the class TestMetastoreScheduledQueries method testDisableInternal.
/**
* Simulates some schq failure scenario.
*
* Q1 is executed correctly 1 time; but every further executions are end with failures
* Q2 should be executed without without issues even thru Q1 will be disabled at some point
*/
public void testDisableInternal(int q1NumberOfExecutions, int seconds, String testNamespace) throws Exception {
int q2NumberOfExecutions = seconds - 1;
ScheduledQueryKey schqKey1 = new ScheduledQueryKey("q1", testNamespace);
ScheduledQueryKey schqKey2 = new ScheduledQueryKey("q2", testNamespace);
createEverySecondSchq(schqKey1);
createEverySecondSchq(schqKey2);
// do some polls and report failure each time
ScheduledQueryPollRequest request = new ScheduledQueryPollRequest();
request.setClusterNamespace(testNamespace);
ScheduledQueryPollResponse pollResult = null;
int idx1 = 0;
int idx2 = 0;
for (int i = 0; i < seconds * 10 + 9; i++) {
pollResult = client.scheduledQueryPoll(request);
if (pollResult.isSetQuery()) {
if (pollResult.getScheduleKey().equals(schqKey1)) {
idx1++;
if (idx1 == 1) {
ScheduledQueryProgressInfo info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.FINISHED, "executor-query-id");
client.scheduledQueryProgress(info);
} else {
ScheduledQueryProgressInfo info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.FAILED, "executor-query-id");
info.setErrorMessage("some issue happened");
client.scheduledQueryProgress(info);
}
ScheduledQuery schq = client.getScheduledQuery(pollResult.getScheduleKey());
if (idx1 > q1NumberOfExecutions) {
fail("unexpected execution of q1 happened");
}
if (idx1 == q1NumberOfExecutions) {
assertFalse("Scheduled query q1 must be disabled at this point", schq.isEnabled());
} else {
assertTrue("Scheduled query q1 must be enabled at this point", schq.isEnabled());
}
}
if (pollResult.getScheduleKey().equals(schqKey2)) {
idx2++;
ScheduledQueryProgressInfo info = new ScheduledQueryProgressInfo(pollResult.getExecutionId(), QueryState.FINISHED, "executor-query-id");
client.scheduledQueryProgress(info);
ScheduledQuery schq = client.getScheduledQuery(pollResult.getScheduleKey());
assertTrue("Scheduled query q2 must be enabled", schq.isEnabled());
}
}
Thread.sleep(100);
}
if (idx1 != q1NumberOfExecutions) {
fail("expected " + q1NumberOfExecutions + " execution of q1; only " + idx1 + " happened");
}
if (idx2 < q2NumberOfExecutions) {
fail("at least " + q2NumberOfExecutions + " expected for q2");
}
}
use of org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo in project hive by apache.
the class ObjectStore method markScheduledExecutionsTimedOut.
@Override
public int markScheduledExecutionsTimedOut(int timeoutSecs) throws InvalidOperationException, MetaException {
if (timeoutSecs < 0) {
LOG.debug("scheduled executions - time_out mark is disabled");
return 0;
}
boolean committed = false;
Query q = null;
try {
openTransaction();
int maxLastUpdateTime = (int) (System.currentTimeMillis() / 1000) - timeoutSecs;
q = pm.newQuery(MScheduledExecution.class);
q.setFilter("lastUpdateTime <= maxLastUpdateTime && (state == 'INITED' || state == 'EXECUTING')");
q.declareParameters("int maxLastUpdateTime");
List<MScheduledExecution> results = (List<MScheduledExecution>) q.execute(maxLastUpdateTime);
for (MScheduledExecution e : results) {
ScheduledQueryProgressInfo info = new ScheduledQueryProgressInfo();
info.setScheduledExecutionId(e.getScheduledExecutionId());
info.setState(QueryState.TIMED_OUT);
info.setErrorMessage("Query stuck in: " + e.getState() + " state for >" + timeoutSecs + " seconds. Execution timed out.");
// info.set
scheduledQueryProgress(info);
}
recoverInvalidScheduledQueryState(timeoutSecs);
committed = commitTransaction();
return results.size();
} finally {
rollbackAndCleanup(committed, q);
}
}
Aggregations