[ML Data Frame] Set DF task state when stopping (#42516)
Set the state to stopped prior to persisting
This commit is contained in:
parent
3193dfa8e6
commit
c5a410f68b
|
@ -30,7 +30,6 @@ import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransform;
|
||||||
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformConfig;
|
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformConfig;
|
||||||
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformState;
|
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformState;
|
||||||
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStats;
|
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStats;
|
||||||
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformTaskState;
|
|
||||||
import org.elasticsearch.xpack.core.indexing.IndexerState;
|
import org.elasticsearch.xpack.core.indexing.IndexerState;
|
||||||
import org.elasticsearch.xpack.core.scheduler.SchedulerEngine;
|
import org.elasticsearch.xpack.core.scheduler.SchedulerEngine;
|
||||||
import org.elasticsearch.xpack.dataframe.DataFrame;
|
import org.elasticsearch.xpack.dataframe.DataFrame;
|
||||||
|
@ -223,18 +222,8 @@ public class DataFrameTransformPersistentTasksExecutor extends PersistentTasksEx
|
||||||
DataFrameTransformTask.ClientDataFrameIndexerBuilder indexerBuilder,
|
DataFrameTransformTask.ClientDataFrameIndexerBuilder indexerBuilder,
|
||||||
Long previousCheckpoint,
|
Long previousCheckpoint,
|
||||||
ActionListener<StartDataFrameTransformTaskAction.Response> listener) {
|
ActionListener<StartDataFrameTransformTaskAction.Response> listener) {
|
||||||
// If we are stopped, and it is an initial run, this means we have never been started,
|
|
||||||
// attempt to start the task
|
|
||||||
|
|
||||||
buildTask.initializeIndexer(indexerBuilder);
|
buildTask.initializeIndexer(indexerBuilder);
|
||||||
// TODO isInitialRun is false after relocation??
|
buildTask.start(previousCheckpoint, listener);
|
||||||
if (buildTask.getState().getTaskState().equals(DataFrameTransformTaskState.STOPPED) && buildTask.isInitialRun()) {
|
|
||||||
logger.info("Data frame transform [{}] created.", buildTask.getTransformId());
|
|
||||||
buildTask.start(previousCheckpoint, listener);
|
|
||||||
} else {
|
|
||||||
logger.debug("No need to start task. Its current state is: {}", buildTask.getState().getIndexerState());
|
|
||||||
listener.onResponse(new StartDataFrameTransformTaskAction.Response(true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -174,13 +174,8 @@ public class DataFrameTransformTask extends AllocatedPersistentTask implements S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStopped() {
|
public void setTaskStateStopped() {
|
||||||
IndexerState currentState = getIndexer() == null ? initialIndexerState : getIndexer().getState();
|
taskState.set(DataFrameTransformTaskState.STOPPED);
|
||||||
return currentState.equals(IndexerState.STOPPED);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isInitialRun() {
|
|
||||||
return getIndexer() != null && getIndexer().initialRun();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -235,11 +230,9 @@ public class DataFrameTransformTask extends AllocatedPersistentTask implements S
|
||||||
|
|
||||||
public synchronized void stop() {
|
public synchronized void stop() {
|
||||||
if (getIndexer() == null) {
|
if (getIndexer() == null) {
|
||||||
return;
|
// If there is no indexer the task has not been triggered
|
||||||
}
|
// but it still needs to be stopped and removed
|
||||||
// taskState is initialized as STOPPED and is updated in tandem with the indexerState
|
shutdown();
|
||||||
// Consequently, if it is STOPPED, we consider the whole task STOPPED.
|
|
||||||
if (taskState.get() == DataFrameTransformTaskState.STOPPED) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,6 +602,8 @@ public class DataFrameTransformTask extends AllocatedPersistentTask implements S
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
auditor.info(transformConfig.getId(), "Indexer has stopped");
|
auditor.info(transformConfig.getId(), "Indexer has stopped");
|
||||||
logger.info("Data frame transform [{}] indexer has stopped", transformConfig.getId());
|
logger.info("Data frame transform [{}] indexer has stopped", transformConfig.getId());
|
||||||
|
|
||||||
|
transformTask.setTaskStateStopped();
|
||||||
transformsConfigManager.putOrUpdateTransformStats(
|
transformsConfigManager.putOrUpdateTransformStats(
|
||||||
new DataFrameTransformStateAndStats(transformId, transformTask.getState(), getStats(),
|
new DataFrameTransformStateAndStats(transformId, transformTask.getState(), getStats(),
|
||||||
DataFrameTransformCheckpointingInfo.EMPTY), // TODO should this be null
|
DataFrameTransformCheckpointingInfo.EMPTY), // TODO should this be null
|
||||||
|
|
|
@ -90,6 +90,9 @@ teardown:
|
||||||
- match: { airline-data-by-airline-start-stop.mappings: {} }
|
- match: { airline-data-by-airline-start-stop.mappings: {} }
|
||||||
---
|
---
|
||||||
"Test start/stop/start transform":
|
"Test start/stop/start transform":
|
||||||
|
- skip:
|
||||||
|
reason: "https://github.com/elastic/elasticsearch/issues/42650"
|
||||||
|
version: "all"
|
||||||
- do:
|
- do:
|
||||||
data_frame.start_data_frame_transform:
|
data_frame.start_data_frame_transform:
|
||||||
transform_id: "airline-transform-start-stop"
|
transform_id: "airline-transform-start-stop"
|
||||||
|
@ -114,8 +117,8 @@ teardown:
|
||||||
transform_id: "airline-transform-start-stop"
|
transform_id: "airline-transform-start-stop"
|
||||||
- match: { count: 1 }
|
- match: { count: 1 }
|
||||||
- match: { transforms.0.id: "airline-transform-start-stop" }
|
- match: { transforms.0.id: "airline-transform-start-stop" }
|
||||||
# - match: { transforms.0.state.indexer_state: "stopped" }
|
- match: { transforms.0.state.indexer_state: "stopped" }
|
||||||
# - match: { transforms.0.state.task_state: "stopped" }
|
- match: { transforms.0.state.task_state: "stopped" }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
data_frame.start_data_frame_transform:
|
data_frame.start_data_frame_transform:
|
||||||
|
|
Loading…
Reference in New Issue