List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:com.facebook.presto.execution.QueryTracker.java
License:Apache License
private boolean isAbandoned(T query) { DateTime oldestAllowedHeartbeat = DateTime.now().minus(clientTimeout.toMillis()); DateTime lastHeartbeat = query.getLastHeartbeat(); return lastHeartbeat != null && lastHeartbeat.isBefore(oldestAllowedHeartbeat); }
From source file:com.facebook.presto.execution.SqlQueryManager.java
License:Apache License
/** * Remove completed queries after a waiting period *//* w w w.j av a 2 s . c o m*/ public void removeExpiredQueries() { List<QueryExecution> sortedQueries = IterableTransformer.on(queries.values()) .select(compose(not(isNull()), endTimeGetter())) .orderBy(Ordering.natural().onResultOf(endTimeGetter())).list(); int toRemove = Math.max(sortedQueries.size() - maxQueryHistory, 0); DateTime oldestAllowedQuery = DateTime.now().minus(maxQueryAge.toMillis()); for (QueryExecution queryExecution : sortedQueries) { try { DateTime endTime = queryExecution.getQueryInfo().getQueryStats().getEndTime(); if ((endTime.isBefore(oldestAllowedQuery) || toRemove > 0) && isAbandoned(queryExecution)) { removeQuery(queryExecution.getQueryInfo().getQueryId()); --toRemove; } } catch (RuntimeException e) { log.warn(e, "Error while inspecting age of query %s", queryExecution.getQueryInfo().getQueryId()); } } }
From source file:com.facebook.presto.execution.SqlQueryManager.java
License:Apache License
public void failAbandonedQueries() { for (QueryExecution queryExecution : queries.values()) { try {// ww w . j av a2s . co m QueryInfo queryInfo = queryExecution.getQueryInfo(); if (queryInfo.getState().isDone()) { continue; } if (isAbandoned(queryExecution)) { log.info("Failing abandoned query %s", queryExecution.getQueryInfo().getQueryId()); queryExecution.fail(new AbandonedException("Query " + queryInfo.getQueryId(), queryInfo.getQueryStats().getLastHeartbeat(), DateTime.now())); } } catch (RuntimeException e) { log.warn(e, "Error while inspecting age of query %s", queryExecution.getQueryInfo().getQueryId()); } } }
From source file:com.facebook.presto.execution.SqlQueryManager.java
License:Apache License
private boolean isAbandoned(QueryExecution query) { DateTime oldestAllowedHeartbeat = DateTime.now().minus(clientTimeout.toMillis()); DateTime lastHeartbeat = query.getQueryInfo().getQueryStats().getLastHeartbeat(); return lastHeartbeat != null && lastHeartbeat.isBefore(oldestAllowedHeartbeat); }
From source file:com.facebook.presto.execution.SqlStageExecution.java
License:Apache License
private void startTasks() { try (SetThreadName setThreadName = new SetThreadName("Stage-%s", stageId)) { try {//from w ww . j av a 2 s. c o m checkState(!Thread.holdsLock(this), "Can not start while holding a lock on this"); // transition to scheduling synchronized (this) { if (!stageState.compareAndSet(StageState.PLANNED, StageState.SCHEDULING)) { // stage has already been started, has been canceled or has no tasks due to partition pruning return; } } // schedule tasks if (fragment.getDistribution() == PlanDistribution.NONE) { scheduleFixedNodeCount(1); } else if (fragment.getDistribution() == PlanDistribution.FIXED) { scheduleFixedNodeCount(initialHashPartitions); } else if (fragment.getDistribution() == PlanDistribution.SOURCE) { scheduleSourcePartitionedNodes(); } else if (fragment.getDistribution() == PlanDistribution.COORDINATOR_ONLY) { scheduleOnCurrentNode(); } else { throw new IllegalStateException("Unsupported partitioning: " + fragment.getDistribution()); } schedulingComplete.set(DateTime.now()); stageState.set(StageState.SCHEDULED); // add the missing exchanges output buffers updateNewExchangesAndBuffers(true); } catch (Throwable e) { // some exceptions can occur when the query finishes early if (!getState().isDone()) { synchronized (this) { failureCauses.add(e); stageState.set(StageState.FAILED); } log.error(e, "Error while starting stage %s", stageId); cancel(true); if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } throw Throwables.propagate(e); } Throwables.propagateIfInstanceOf(e, Error.class); log.debug(e, "Error while starting stage in done query %s", stageId); } finally { doUpdateState(); } } }
From source file:com.facebook.presto.execution.SqlTask.java
License:Apache License
public void recordHeartbeat() { lastHeartbeat.set(DateTime.now()); }
From source file:com.facebook.presto.execution.SqlTask.java
License:Apache License
private TaskStats getTaskStats(TaskHolder taskHolder) { TaskInfo finalTaskInfo = taskHolder.getFinalTaskInfo(); if (finalTaskInfo != null) { return finalTaskInfo.getStats(); }/*from w ww.ja v a 2s . com*/ SqlTaskExecution taskExecution = taskHolder.getTaskExecution(); if (taskExecution != null) { return taskExecution.getTaskContext().getTaskStats(); } // if the task completed without creation, set end time DateTime endTime = taskStateMachine.getState().isDone() ? DateTime.now() : null; return new TaskStats(taskStateMachine.getCreatedTime(), endTime); }
From source file:com.facebook.presto.execution.SqlTaskExecution.java
License:Apache License
@Override public void recordHeartbeat() { this.lastHeartbeat.set(DateTime.now()); }
From source file:com.facebook.presto.execution.SqlTaskManager.java
License:Apache License
@Override public TaskInfo cancelTask(TaskId taskId) { checkNotNull(taskId, "taskId is null"); TaskExecution taskExecution = tasks.get(taskId); if (taskExecution == null) { TaskInfo taskInfo = taskInfos.get(taskId); if (taskInfo == null) { // task does not exist yet, mark the task as canceled, so later if a late request // comes in to create the task, the task remains canceled TaskContext taskContext = new TaskContext(new TaskStateMachine(taskId, taskNotificationExecutor), taskManagementExecutor, null, maxTaskMemoryUsage, operatorPreAllocatedMemory, cpuTimerEnabled);/*from w w w . j av a2s . c om*/ taskInfo = new TaskInfo(taskId, Long.MAX_VALUE, TaskState.CANCELED, URI.create("unknown"), DateTime.now(), new SharedBufferInfo(QueueState.FINISHED, 0, 0, ImmutableList.<BufferInfo>of()), ImmutableSet.<PlanNodeId>of(), taskContext.getTaskStats(), ImmutableList.<ExecutionFailureInfo>of()); TaskInfo existingTaskInfo = taskInfos.putIfAbsent(taskId, taskInfo); if (existingTaskInfo != null) { taskInfo = existingTaskInfo; } } return taskInfo; } // make sure task is finished taskExecution.cancel(); return getTaskInfo(taskExecution); }
From source file:com.facebook.presto.execution.SqlTaskManager.java
License:Apache License
public void removeOldTasks() { DateTime oldestAllowedTask = DateTime.now().minus(infoCacheTime.toMillis()); for (TaskInfo taskInfo : taskInfos.values()) { try {//from w ww . ja v a 2 s .com DateTime endTime = taskInfo.getStats().getEndTime(); if (endTime != null && endTime.isBefore(oldestAllowedTask)) { taskInfos.remove(taskInfo.getTaskId()); } } catch (RuntimeException e) { log.warn(e, "Error while inspecting age of complete task %s", taskInfo.getTaskId()); } } }