public TaskStateMachine(TaskId taskId, Executor executor) { this.taskId = requireNonNull(taskId, "taskId is null"); taskState = new StateMachine<>("task " + taskId, executor, TaskState.RUNNING, TERMINAL_TASK_STATES); taskState.addStateChangeListener(new StateChangeListener<TaskState>() { @Override public void stateChanged(TaskState newState) { log.debug("Task %s is %s", taskId, newState); } }); }
public LazyOutputBuffer( TaskId taskId, String taskInstanceId, Executor executor, DataSize maxBufferSize, Supplier<LocalMemoryContext> systemMemoryContextSupplier) { requireNonNull(taskId, "taskId is null"); this.taskInstanceId = requireNonNull(taskInstanceId, "taskInstanceId is null"); this.executor = requireNonNull(executor, "executor is null"); state = new StateMachine<>(taskId + "-buffer", executor, OPEN, TERMINAL_BUFFER_STATES); this.maxBufferSize = requireNonNull(maxBufferSize, "maxBufferSize is null"); checkArgument(maxBufferSize.toBytes() > 0, "maxBufferSize must be at least 1"); this.systemMemoryContextSupplier = requireNonNull(systemMemoryContextSupplier, "systemMemoryContextSupplier is null"); }
public StageStateMachine( StageId stageId, URI location, Session session, PlanFragment fragment, ExecutorService executor, SplitSchedulerStats schedulerStats) { this.stageId = requireNonNull(stageId, "stageId is null"); this.location = requireNonNull(location, "location is null"); this.session = requireNonNull(session, "session is null"); this.fragment = requireNonNull(fragment, "fragment is null"); this.scheduledStats = requireNonNull(schedulerStats, "schedulerStats is null"); stageState = new StateMachine<>("stage " + stageId, executor, PLANNED, TERMINAL_STAGE_STATES); stageState.addStateChangeListener(state -> log.debug("Stage %s is %s", stageId, state)); finalStageInfo = new StateMachine<>("final stage " + stageId, executor, Optional.empty()); }
private QueryStateMachine( String query, Session session, URI self, Optional<ResourceGroupId> resourceGroup, TransactionManager transactionManager, Executor executor, Ticker ticker, Metadata metadata, WarningCollector warningCollector) { this.query = requireNonNull(query, "query is null"); this.session = requireNonNull(session, "session is null"); this.queryId = session.getQueryId(); this.self = requireNonNull(self, "self is null"); this.resourceGroup = requireNonNull(resourceGroup, "resourceGroup is null"); this.transactionManager = requireNonNull(transactionManager, "transactionManager is null"); this.queryStateTimer = new QueryStateTimer(ticker); this.metadata = requireNonNull(metadata, "metadata is null"); this.queryState = new StateMachine<>("query " + query, executor, QUEUED, TERMINAL_QUERY_STATES); this.finalQueryInfo = new StateMachine<>("finalQueryInfo-" + queryId, executor, Optional.empty()); this.outputManager = new QueryOutputManager(executor); this.warningCollector = requireNonNull(warningCollector, "warningCollector is null"); }
public ContinuousTaskStatusFetcher( Consumer<Throwable> onFail, TaskStatus initialTaskStatus, Duration refreshMaxWait, JsonCodec<TaskStatus> taskStatusCodec, Executor executor, HttpClient httpClient, Duration maxErrorDuration, ScheduledExecutorService errorScheduledExecutor, RemoteTaskStats stats) { requireNonNull(initialTaskStatus, "initialTaskStatus is null"); this.taskId = initialTaskStatus.getTaskId(); this.onFail = requireNonNull(onFail, "onFail is null"); this.taskStatus = new StateMachine<>("task-" + taskId, executor, initialTaskStatus); this.refreshMaxWait = requireNonNull(refreshMaxWait, "refreshMaxWait is null"); this.taskStatusCodec = requireNonNull(taskStatusCodec, "taskStatusCodec is null"); this.executor = requireNonNull(executor, "executor is null"); this.httpClient = requireNonNull(httpClient, "httpClient is null"); this.errorTracker = new RequestErrorTracker(taskId, initialTaskStatus.getSelf(), maxErrorDuration, errorScheduledExecutor, "getting task status"); this.stats = requireNonNull(stats, "stats is null"); }
public TaskInfoFetcher( Consumer<Throwable> onFail, TaskInfo initialTask, HttpClient httpClient, Duration updateInterval, JsonCodec<TaskInfo> taskInfoCodec, Duration maxErrorDuration, boolean summarizeTaskInfo, Executor executor, ScheduledExecutorService updateScheduledExecutor, ScheduledExecutorService errorScheduledExecutor, RemoteTaskStats stats) { requireNonNull(initialTask, "initialTask is null"); requireNonNull(errorScheduledExecutor, "errorScheduledExecutor is null"); this.taskId = initialTask.getTaskStatus().getTaskId(); this.onFail = requireNonNull(onFail, "onFail is null"); this.taskInfo = new StateMachine<>("task " + taskId, executor, initialTask); this.finalTaskInfo = new StateMachine<>("task-" + taskId, executor, Optional.empty()); this.taskInfoCodec = requireNonNull(taskInfoCodec, "taskInfoCodec is null"); this.updateIntervalMillis = requireNonNull(updateInterval, "updateInterval is null").toMillis(); this.updateScheduledExecutor = requireNonNull(updateScheduledExecutor, "updateScheduledExecutor is null"); this.errorTracker = new RequestErrorTracker(taskId, initialTask.getTaskStatus().getSelf(), maxErrorDuration, errorScheduledExecutor, "getting info for task"); this.summarizeTaskInfo = summarizeTaskInfo; this.executor = requireNonNull(executor, "executor is null"); this.httpClient = requireNonNull(httpClient, "httpClient is null"); this.stats = requireNonNull(stats, "stats is null"); }
private BroadcastOutputBuffer createBroadcastBuffer(OutputBuffers outputBuffers, DataSize dataSize, AggregatedMemoryContext memoryContext, Executor notificationExecutor) { BroadcastOutputBuffer buffer = new BroadcastOutputBuffer( TASK_INSTANCE_ID, new StateMachine<>("bufferState", stateNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), dataSize, () -> memoryContext.newLocalMemoryContext("test"), notificationExecutor); buffer.setOutputBuffers(outputBuffers); return buffer; }
private PartitionedOutputBuffer createPartitionedBuffer(OutputBuffers buffers, DataSize dataSize) { return new PartitionedOutputBuffer( TASK_INSTANCE_ID, new StateMachine<>("bufferState", stateNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), buffers, dataSize, () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), stateNotificationExecutor); }
private PartitionedOutputBuffer createPartitionedBuffer(OutputBuffers buffers, DataSize dataSize) { return new PartitionedOutputBuffer( "task-instance-id", new StateMachine<>("bufferState", SCHEDULER, OPEN, TERMINAL_BUFFER_STATES), buffers, dataSize, () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), SCHEDULER); } }
private ArbitraryOutputBuffer createArbitraryBuffer(OutputBuffers buffers, DataSize dataSize) { ArbitraryOutputBuffer buffer = new ArbitraryOutputBuffer( TASK_INSTANCE_ID, new StateMachine<>("bufferState", stateNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), dataSize, () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), stateNotificationExecutor); buffer.setOutputBuffers(buffers); return buffer; }
private BroadcastOutputBuffer createBroadcastBuffer(OutputBuffers outputBuffers, DataSize dataSize) { BroadcastOutputBuffer buffer = new BroadcastOutputBuffer( TASK_INSTANCE_ID, new StateMachine<>("bufferState", stateNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), dataSize, () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), stateNotificationExecutor); buffer.setOutputBuffers(outputBuffers); return buffer; }
private PartitionedOutputBuffer newTestingOutputBuffer(ScheduledExecutorService taskNotificationExecutor) { return new PartitionedOutputBuffer( "task-id", new StateMachine<>("bufferState", taskNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), createInitialEmptyOutputBuffers(PARTITIONED) .withBuffer(OUTPUT_BUFFER_ID, 0) .withNoMoreBufferIds(), new DataSize(1, MEGABYTE), () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), taskNotificationExecutor); }
@Test public void testSet() throws Exception { StateMachine<State> stateMachine = new StateMachine<>("test", executor, State.BREAKFAST, ImmutableSet.of(State.DINNER)); assertEquals(stateMachine.get(), State.BREAKFAST); assertNoStateChange(stateMachine, () -> assertEquals(stateMachine.set(State.BREAKFAST), State.BREAKFAST)); assertStateChange(stateMachine, () -> assertEquals(stateMachine.set(State.LUNCH), State.BREAKFAST), State.LUNCH); assertStateChange(stateMachine, () -> assertEquals(stateMachine.set(State.BREAKFAST), State.LUNCH), State.BREAKFAST); // transition to a final state assertStateChange(stateMachine, () -> assertEquals(stateMachine.set(State.DINNER), State.BREAKFAST), State.DINNER); // attempt transition from a final state assertNoStateChange(stateMachine, () -> { try { stateMachine.set(State.LUNCH); fail("expected IllegalStateException"); } catch (IllegalStateException expected) { } }); assertNoStateChange(stateMachine, () -> stateMachine.set(State.DINNER)); }
new StateMachine<>("test", executor, null); fail("expected a NullPointerException"); StateMachine<State> stateMachine = new StateMachine<>("test", executor, State.BREAKFAST);
throws Exception StateMachine<State> stateMachine = new StateMachine<>("test", executor, State.BREAKFAST, ImmutableSet.of(State.DINNER)); assertEquals(stateMachine.get(), State.BREAKFAST);
@Test public void testCompareAndSet() throws Exception { StateMachine<State> stateMachine = new StateMachine<>("test", executor, State.BREAKFAST, ImmutableSet.of(State.DINNER)); assertEquals(stateMachine.get(), State.BREAKFAST); // no match with new state assertNoStateChange(stateMachine, () -> stateMachine.compareAndSet(State.DINNER, State.LUNCH)); // match with new state assertStateChange(stateMachine, () -> stateMachine.compareAndSet(State.BREAKFAST, State.LUNCH), State.LUNCH); // no match with same state assertNoStateChange(stateMachine, () -> stateMachine.compareAndSet(State.BREAKFAST, State.LUNCH)); // match with same state assertNoStateChange(stateMachine, () -> stateMachine.compareAndSet(State.LUNCH, State.LUNCH)); // transition to a final state assertStateChange(stateMachine, () -> stateMachine.compareAndSet(State.LUNCH, State.DINNER), State.DINNER); // attempt transition from a final state assertNoStateChange(stateMachine, () -> { try { stateMachine.compareAndSet(State.DINNER, State.LUNCH); fail("expected IllegalStateException"); } catch (IllegalStateException expected) { } }); assertNoStateChange(stateMachine, () -> stateMachine.compareAndSet(State.DINNER, State.DINNER)); }
private QueryStateMachine(QueryId queryId, String query, Session session, URI self, boolean autoCommit, TransactionManager transactionManager, Executor executor) { this.queryId = requireNonNull(queryId, "queryId is null"); this.query = requireNonNull(query, "query is null"); this.session = requireNonNull(session, "session is null"); this.self = requireNonNull(self, "self is null"); this.autoCommit = autoCommit; this.transactionManager = requireNonNull(transactionManager, "transactionManager is null"); this.queryState = new StateMachine<>("query " + query, executor, QUEUED, TERMINAL_QUERY_STATES); }
public TaskStateMachine(TaskId taskId, Executor executor) { this.taskId = requireNonNull(taskId, "taskId is null"); taskState = new StateMachine<>("task " + taskId, executor, TaskState.RUNNING, TERMINAL_TASK_STATES); taskState.addStateChangeListener(new StateChangeListener<TaskState>() { @Override public void stateChanged(TaskState newState) { log.debug("Task %s is %s", TaskStateMachine.this.taskId, newState); } }); }
public StageStateMachine(StageId stageId, URI location, Session session, PlanFragment fragment, ExecutorService executor) { this.stageId = requireNonNull(stageId, "stageId is null"); this.location = requireNonNull(location, "location is null"); this.session = requireNonNull(session, "session is null"); this.fragment = requireNonNull(fragment, "fragment is null"); stageState = new StateMachine<>("stage " + stageId, executor, PLANNED, TERMINAL_STAGE_STATES); stageState.addStateChangeListener(state -> log.debug("Stage %s is %s", stageId, state)); }
public SharedBuffer(TaskId taskId, String taskInstanceId, Executor executor, DataSize maxBufferSize, SystemMemoryUsageListener systemMemoryUsageListener) { requireNonNull(taskId, "taskId is null"); requireNonNull(executor, "executor is null"); this.taskInstanceId = requireNonNull(taskInstanceId, "taskInstanceId is null"); state = new StateMachine<>(taskId + "-buffer", executor, OPEN, TERMINAL_BUFFER_STATES); requireNonNull(maxBufferSize, "maxBufferSize is null"); checkArgument(maxBufferSize.toBytes() > 0, "maxBufferSize must be at least 1"); requireNonNull(systemMemoryUsageListener, "systemMemoryUsageListener is null"); this.memoryManager = new SharedBufferMemoryManager(maxBufferSize.toBytes(), systemMemoryUsageListener); }