|
22 | 22 | import org.elasticsearch.persistent.PersistentTaskState;
|
23 | 23 | import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
|
24 | 24 | import org.elasticsearch.persistent.PersistentTasksExecutor;
|
25 |
| -import org.elasticsearch.persistent.PersistentTasksService; |
26 | 25 | import org.elasticsearch.tasks.TaskId;
|
27 |
| -import org.elasticsearch.tasks.TaskManager; |
28 | 26 | import org.elasticsearch.threadpool.ThreadPool;
|
29 | 27 | import org.elasticsearch.xpack.core.ClientHelper;
|
30 | 28 | import org.elasticsearch.xpack.core.indexing.IndexerState;
|
@@ -152,59 +150,44 @@ protected void onAbort() {
|
152 | 150 | private final RollupJob job;
|
153 | 151 | private final SchedulerEngine schedulerEngine;
|
154 | 152 | private final ThreadPool threadPool;
|
155 |
| - private final Client client; |
156 |
| - private final IndexerState initialIndexerState; |
157 |
| - private final Map<String, Object> initialPosition; |
158 |
| - private RollupIndexer indexer; |
| 153 | + private final RollupIndexer indexer; |
159 | 154 |
|
160 | 155 | RollupJobTask(long id, String type, String action, TaskId parentTask, RollupJob job, RollupJobStatus state,
|
161 | 156 | Client client, SchedulerEngine schedulerEngine, ThreadPool threadPool, Map<String, String> headers) {
|
162 | 157 | super(id, type, action, RollupField.NAME + "_" + job.getConfig().getId(), parentTask, headers);
|
163 | 158 | this.job = job;
|
164 | 159 | this.schedulerEngine = schedulerEngine;
|
165 | 160 | this.threadPool = threadPool;
|
166 |
| - this.client = client; |
167 |
| - if (state == null) { |
168 |
| - this.initialIndexerState = null; |
169 |
| - this.initialPosition = null; |
170 |
| - } else { |
171 |
| - this.initialIndexerState = state.getIndexerState(); |
172 |
| - this.initialPosition = state.getPosition(); |
173 |
| - } |
174 |
| - |
175 |
| - } |
176 | 161 |
|
177 |
| - @Override |
178 |
| - protected void init(PersistentTasksService persistentTasksService, TaskManager taskManager, |
179 |
| - String persistentTaskId, long allocationId) { |
180 |
| - super.init(persistentTasksService, taskManager, persistentTaskId, allocationId); |
181 |
| - |
182 |
| - // If initial position is not null, we are resuming rather than starting fresh. |
183 |
| - IndexerState indexerState = IndexerState.STOPPED; |
184 |
| - if (initialPosition != null) { |
185 |
| - logger.debug("We have existing state, setting state to [" + initialIndexerState + "] " + |
186 |
| - "and current position to [" + initialPosition + "] for job [" + job.getConfig().getId() + "]"); |
187 |
| - if (initialIndexerState.equals(IndexerState.INDEXING)) { |
| 162 | + // If status is not null, we are resuming rather than starting fresh. |
| 163 | + Map<String, Object> initialPosition = null; |
| 164 | + IndexerState initialState = IndexerState.STOPPED; |
| 165 | + if (state != null) { |
| 166 | + final IndexerState existingState = state.getIndexerState(); |
| 167 | + logger.debug("We have existing state, setting state to [" + existingState + "] " + |
| 168 | + "and current position to [" + state.getPosition() + "] for job [" + job.getConfig().getId() + "]"); |
| 169 | + if (existingState.equals(IndexerState.INDEXING)) { |
188 | 170 | /*
|
189 | 171 | * If we were indexing, we have to reset back to STARTED otherwise the indexer will be "stuck" thinking
|
190 | 172 | * it is indexing but without the actual indexing thread running.
|
191 | 173 | */
|
192 |
| - indexerState = IndexerState.STARTED; |
| 174 | + initialState = IndexerState.STARTED; |
193 | 175 |
|
194 |
| - } else if (initialIndexerState.equals(IndexerState.ABORTING) || initialIndexerState.equals(IndexerState.STOPPING)) { |
| 176 | + } else if (existingState.equals(IndexerState.ABORTING) || existingState.equals(IndexerState.STOPPING)) { |
195 | 177 | // It shouldn't be possible to persist ABORTING, but if for some reason it does,
|
196 | 178 | // play it safe and restore the job as STOPPED. An admin will have to clean it up,
|
197 | 179 | // but it won't be running, and won't delete itself either. Safest option.
|
198 | 180 | // If we were STOPPING, that means it persisted but was killed before finally stopped... so ok
|
199 | 181 | // to restore as STOPPED
|
200 |
| - indexerState = IndexerState.STOPPED; |
| 182 | + initialState = IndexerState.STOPPED; |
201 | 183 | } else {
|
202 |
| - indexerState = initialIndexerState; |
| 184 | + initialState = existingState; |
203 | 185 | }
|
| 186 | + initialPosition = state.getPosition(); |
204 | 187 |
|
205 | 188 | }
|
206 |
| - this.indexer = new ClientRollupPageManager(job, indexerState, initialPosition, |
207 |
| - new ParentTaskAssigningClient(client, getParentTaskId())); |
| 189 | + this.indexer = new ClientRollupPageManager(job, initialState, initialPosition, |
| 190 | + new ParentTaskAssigningClient(client, new TaskId(getPersistentTaskId()))); |
208 | 191 | }
|
209 | 192 |
|
210 | 193 | @Override
|
|
0 commit comments