-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](fe) Guard fragment cleanup until dispatch completes #66767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package org.apache.doris.qe; | ||
|
|
||
| import org.apache.doris.common.Status; | ||
| import org.apache.doris.nereids.trees.plans.distribute.worker.BackendWorker; | ||
| import org.apache.doris.qe.runtime.MultiFragmentsPipelineTask; | ||
| import org.apache.doris.qe.runtime.PipelineExecutionTask; | ||
| import org.apache.doris.qe.runtime.SingleFragmentPipelineTask; | ||
| import org.apache.doris.thrift.TReportExecStatusParams; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Optional; | ||
|
|
||
| class AbstractJobProcessorTest { | ||
| @Test | ||
| void finishBeforeFragmentDispatchDoesNotCancelPreparedFragments() { | ||
| MultiFragmentsPipelineTask fragmentsTask = Mockito.mock(MultiFragmentsPipelineTask.class); | ||
| TestJobProcessor processor = createProcessor(fragmentsTask); | ||
|
|
||
| processor.tryFinishSchedule(); | ||
| Mockito.verifyNoInteractions(fragmentsTask); | ||
|
|
||
| processor.markFragmentDispatchCompleted(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Exercise the production phase-two boundary These tests call |
||
| Mockito.verify(fragmentsTask).cancelExecute(Status.FINISHED); | ||
|
|
||
| processor.tryFinishSchedule(); | ||
| processor.markFragmentDispatchCompleted(); | ||
| Mockito.verifyNoMoreInteractions(fragmentsTask); | ||
| } | ||
|
|
||
| @Test | ||
| void fragmentDispatchBeforeFinishBroadcastsWhenExecutionFinishes() { | ||
| MultiFragmentsPipelineTask fragmentsTask = Mockito.mock(MultiFragmentsPipelineTask.class); | ||
| TestJobProcessor processor = createProcessor(fragmentsTask); | ||
|
|
||
| processor.markFragmentDispatchCompleted(); | ||
| Mockito.verifyNoInteractions(fragmentsTask); | ||
|
|
||
| processor.tryFinishSchedule(); | ||
| Mockito.verify(fragmentsTask).cancelExecute(Status.FINISHED); | ||
| } | ||
|
|
||
| private static TestJobProcessor createProcessor(MultiFragmentsPipelineTask fragmentsTask) { | ||
| BackendWorker worker = Mockito.mock(BackendWorker.class); | ||
| PipelineExecutionTask executionTask = Mockito.mock(PipelineExecutionTask.class); | ||
| Mockito.when(executionTask.getChildrenTasks()).thenReturn(Collections.singletonMap(worker, fragmentsTask)); | ||
|
|
||
| TestJobProcessor processor = new TestJobProcessor(Mockito.mock(CoordinatorContext.class)); | ||
| processor.setExecutionTask(executionTask); | ||
| return processor; | ||
| } | ||
|
|
||
| private static class TestJobProcessor extends AbstractJobProcessor { | ||
| TestJobProcessor(CoordinatorContext coordinatorContext) { | ||
| super(coordinatorContext); | ||
| } | ||
|
|
||
| void setExecutionTask(PipelineExecutionTask executionTask) { | ||
| this.executionTask = Optional.of(executionTask); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doProcessReportExecStatus( | ||
| TReportExecStatusParams params, SingleFragmentPipelineTask fragmentTask) {} | ||
|
|
||
| @Override | ||
| public void cancel(Status cancelReason) {} | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package org.apache.doris.qe.runtime; | ||
|
|
||
| import org.apache.doris.common.Status; | ||
| import org.apache.doris.common.UserException; | ||
| import org.apache.doris.common.jmockit.Deencapsulation; | ||
| import org.apache.doris.nereids.trees.plans.distribute.worker.BackendWorker; | ||
| import org.apache.doris.proto.InternalService.PExecPlanFragmentResult; | ||
| import org.apache.doris.qe.CoordinatorContext; | ||
| import org.apache.doris.rpc.BackendServiceProxy; | ||
| import org.apache.doris.thrift.TQueryOptions; | ||
| import org.apache.doris.thrift.TUniqueId; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.ArgumentMatchers; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.function.Supplier; | ||
|
|
||
| class PipelineExecutionTaskTest { | ||
| @Test | ||
| void expiredDeadlineCancelsAlreadySubmittedFragments() throws Exception { | ||
| CoordinatorContext coordinatorContext = Mockito.mock(CoordinatorContext.class); | ||
| TQueryOptions queryOptions = new TQueryOptions(); | ||
| queryOptions.setExecutionTimeout(1); | ||
| queryOptions.setQueryTimeout(1); | ||
| Deencapsulation.setField(coordinatorContext, "queryOptions", queryOptions); | ||
| Deencapsulation.setField(coordinatorContext, "queryId", new TUniqueId(1, 2)); | ||
| Deencapsulation.setField(coordinatorContext, "timeoutDeadline", (Supplier<Long>) () -> 0L); | ||
| Mockito.when(coordinatorContext.withLock(ArgumentMatchers.<Callable<Object>>any())) | ||
| .thenAnswer(invocation -> invocation.<Callable<Object>>getArgument(0).call()); | ||
| Mockito.when(coordinatorContext.twoPhaseExecution()).thenReturn(false); | ||
|
|
||
| MultiFragmentsPipelineTask fragmentsTask = Mockito.mock(MultiFragmentsPipelineTask.class); | ||
| Mockito.when(fragmentsTask.getChildrenTasks()).thenReturn(Collections.emptyMap()); | ||
| Mockito.when(fragmentsTask.sendPhaseOneRpc(false)) | ||
| .thenReturn(CompletableFuture.completedFuture(PExecPlanFragmentResult.getDefaultInstance())); | ||
| PipelineExecutionTask executionTask = new PipelineExecutionTask( | ||
| coordinatorContext, | ||
| Mockito.mock(BackendServiceProxy.class), | ||
| Collections.singletonMap(Mockito.mock(BackendWorker.class), fragmentsTask)); | ||
|
|
||
| UserException exception = Assertions.assertThrows(UserException.class, executionTask::execute); | ||
|
|
||
| Assertions.assertTrue(exception.getMessage().contains("timeout before waiting send fragments rpc")); | ||
| Mockito.verify(fragmentsTask).sendPhaseOneRpc(false); | ||
| Mockito.verify(coordinatorContext).updateStatusIfOk(ArgumentMatchers.argThat( | ||
| status -> hasDeadlineTimeoutMessage(status))); | ||
| Mockito.verify(coordinatorContext).cancelSchedule(ArgumentMatchers.argThat( | ||
| status -> hasDeadlineTimeoutMessage(status))); | ||
| } | ||
|
|
||
| private static boolean hasDeadlineTimeoutMessage(Status status) { | ||
| return status.getErrorMsg().contains("timeout before waiting send fragments rpc"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Cancel already-launched fragments when dispatch exits early
Both phase helpers launch all RPC futures before
waitPipelineRpcchecksleftTimeMs, but itsleftTimeMs <= 0branch throws without theupdateStatusIfOk/cancelScheduleused by every per-future failure. For a load, a fast top fragment can report completion after one-phase submission or while phase-two starts are in flight; this patch recordsexecutionFinished, but this success-only marker is never reached. Load callers can then unregister or abort without cancelling the coordinator, leaving prepared or running BE query contexts until backend timeout. Please route the expired-deadline exit through the same real-error cancellation path before throwing and cover partial phase-one/phase-two dispatch in a test.