Skip to content

Commit 64642e4

Browse files
authored
RollupStart endpoint should return OK if job already started (#41502)
If a job is started or indexing, RollupStart should always return a success (200 OK) response since the job is, in fact, started
1 parent 43a1dee commit 64642e4

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

docs/reference/migration/migrate_8_0.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ coming[8.0.0]
1515
* <<breaking_80_discovery_changes>>
1616
* <<breaking_80_mappings_changes>>
1717
* <<breaking_80_packaging_changes>>
18+
* <<breaking_80_rollup_changes>>
1819
* <<breaking_80_snapshots_changes>>
1920
* <<breaking_80_security_changes>>
2021
* <<breaking_80_ilm_changes>>
@@ -52,6 +53,7 @@ include::migrate_8_0/analysis.asciidoc[]
5253
include::migrate_8_0/discovery.asciidoc[]
5354
include::migrate_8_0/mappings.asciidoc[]
5455
include::migrate_8_0/packaging.asciidoc[]
56+
include::migrate_8_0/rollup.asciidoc[]
5557
include::migrate_8_0/snapshots.asciidoc[]
5658
include::migrate_8_0/security.asciidoc[]
5759
include::migrate_8_0/ilm.asciidoc[]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[float]
2+
[[breaking_80_rollup_changes]]
3+
=== Rollup changes
4+
5+
//NOTE: The notable-breaking-changes tagged regions are re-used in the
6+
//Installation and Upgrade Guide
7+
8+
//tag::notable-breaking-changes[]
9+
10+
// end::notable-breaking-changes[]
11+
12+
[float]
13+
==== StartRollupJob endpoint returns success if job already started
14+
15+
Previously, attempting to start an already-started rollup job would
16+
result in a `500 InternalServerError: Cannot start task for Rollup Job
17+
[job] because state was [STARTED]` exception.
18+
19+
Now, attempting to start a job that is already started will just
20+
return a successful `200 OK: started` response.

x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupJobTask.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ public RollupJobConfig getConfig() {
211211
}
212212

213213
/**
214-
* Attempt to start the indexer. If the state is anything other than STOPPED, this will fail.
215-
* Otherwise, the persistent task's status will be updated to reflect the change.
214+
* Attempt to start the indexer.
215+
* - If the indexer is started/indexing, returns OK
216+
* - If the indexer is stopped, starts task, updates persistent task's status, returns ok
217+
* - Anything else returns error
216218
*
217219
* Note that while the job is started, the indexer will not necessarily run immediately. That
218220
* will only occur when the scheduler triggers it based on the cron
@@ -221,8 +223,14 @@ public RollupJobConfig getConfig() {
221223
*/
222224
public synchronized void start(ActionListener<StartRollupJobAction.Response> listener) {
223225
final IndexerState prevState = indexer.getState();
224-
if (prevState != IndexerState.STOPPED) {
225-
// fails if the task is not STOPPED
226+
227+
if (prevState == IndexerState.STARTED || prevState == IndexerState.INDEXING) {
228+
// We're already running so just return acknowledgement
229+
logger.debug("Indexer already running (State: [" + prevState + "]), acknowledging start without change.");
230+
listener.onResponse(new StartRollupJobAction.Response(true));
231+
return;
232+
} else if (prevState != IndexerState.STOPPED) {
233+
// if we're not already started/indexing, we must be STOPPED to get started
226234
listener.onFailure(new ElasticsearchException("Cannot start task for Rollup Job [" + job.getConfig().getId() + "] because"
227235
+ " state was [" + prevState + "]"));
228236
return;
@@ -231,11 +239,10 @@ public synchronized void start(ActionListener<StartRollupJobAction.Response> lis
231239
final IndexerState newState = indexer.start();
232240
if (newState != IndexerState.STARTED) {
233241
listener.onFailure(new ElasticsearchException("Cannot start task for Rollup Job [" + job.getConfig().getId() + "] because"
234-
+ " state was [" + newState + "]"));
242+
+ " new state was [" + newState + "]"));
235243
return;
236244
}
237245

238-
239246
final RollupJobStatus state = new RollupJobStatus(IndexerState.STARTED, indexer.getPosition());
240247
logger.debug("Updating state for rollup job [" + job.getConfig().getId() + "] to [" + state.getIndexerState() + "][" +
241248
state.getPosition() + "]");

x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupJobTaskTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,16 @@ public void testStartWhenStarted() throws InterruptedException {
163163
assertTrue(((RollupJobStatus)task.getStatus()).getPosition().containsKey("foo"));
164164

165165
CountDownLatch latch = new CountDownLatch(1);
166-
task.start(new ActionListener<StartRollupJobAction.Response>() {
166+
task.start(new ActionListener<>() {
167167
@Override
168168
public void onResponse(StartRollupJobAction.Response response) {
169-
fail("Should not have entered onResponse.");
169+
assertTrue(response.isStarted());
170+
latch.countDown();
170171
}
171172

172173
@Override
173174
public void onFailure(Exception e) {
174-
assertThat(e.getMessage(), equalTo("Cannot start task for Rollup Job ["
175-
+ job.getConfig().getId() + "] because state was [STARTED]"));
176-
latch.countDown();
175+
fail("Should not have throw exception: " + e.getMessage());
177176
}
178177
});
179178
latch.await(3, TimeUnit.SECONDS);

x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/start_job.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ setup:
5959
- is_true: started
6060

6161
- do:
62-
catch: /Cannot start task for Rollup Job \[foo\] because state was/
6362
headers:
6463
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
6564
rollup.start_job:
6665
id: foo
66+
- is_true: started
67+
6768

0 commit comments

Comments
 (0)