Skip to content

Commit 375fd80

Browse files
authored
Mark GeoIpDownloaderTask as completed after cancellation #84028 (#85014)
Persistent task framework requires tasks to be marked either completed or failed after cancellation. This was missing in GeoIpDownloader.
1 parent 6e3a6ea commit 375fd80

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

docs/changelog/85014.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pr: 85014
2+
summary: "Backport mark `GeoIpDownloaderTask` as completed after cancellation #84028"
3+
area: Ingest
4+
type: bug
5+
issues:
6+
- 84028
7+
- 84652
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.ingest.geoip;
10+
11+
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
12+
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
13+
import org.elasticsearch.common.settings.Settings;
14+
import org.elasticsearch.persistent.PersistentTaskParams;
15+
import org.elasticsearch.persistent.PersistentTasksCustomMetadata;
16+
import org.elasticsearch.plugins.Plugin;
17+
import org.elasticsearch.reindex.ReindexPlugin;
18+
import org.junit.After;
19+
20+
import java.util.Arrays;
21+
import java.util.Collection;
22+
23+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
24+
25+
public class GeoIpDownloaderTaskIT extends AbstractGeoIpIT {
26+
27+
protected static final String ENDPOINT = System.getProperty("geoip_endpoint");
28+
29+
@Override
30+
protected Collection<Class<? extends Plugin>> nodePlugins() {
31+
return Arrays.asList(ReindexPlugin.class, IngestGeoIpPlugin.class, IngestGeoIpSettingsPlugin.class);
32+
}
33+
34+
@Override
35+
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
36+
return Settings.builder()
37+
.put(super.nodeSettings(nodeOrdinal, otherSettings))
38+
.put(GeoIpDownloader.ENDPOINT_SETTING.getKey(), "http://invalid-endpoint")
39+
.build();
40+
}
41+
42+
@After
43+
public void cleanUp() throws Exception {
44+
assertAcked(
45+
client().admin()
46+
.cluster()
47+
.prepareUpdateSettings()
48+
.setPersistentSettings(
49+
Settings.builder()
50+
.putNull(GeoIpDownloaderTaskExecutor.ENABLED_SETTING.getKey())
51+
.putNull(GeoIpDownloader.POLL_INTERVAL_SETTING.getKey())
52+
.putNull("ingest.geoip.database_validity")
53+
)
54+
.get()
55+
);
56+
}
57+
58+
public void testTaskRemovedAfterCancellation() throws Exception {
59+
assertAcked(
60+
client().admin()
61+
.cluster()
62+
.prepareUpdateSettings()
63+
.setPersistentSettings(Settings.builder().put(GeoIpDownloaderTaskExecutor.ENABLED_SETTING.getKey(), true))
64+
.get()
65+
);
66+
assertBusy(() -> {
67+
PersistentTasksCustomMetadata.PersistentTask<PersistentTaskParams> task = getTask();
68+
assertNotNull(task);
69+
assertTrue(task.isAssigned());
70+
});
71+
assertBusy(() -> {
72+
ListTasksResponse tasks = client().admin()
73+
.cluster()
74+
.listTasks(new ListTasksRequest().setActions("geoip-downloader[c]"))
75+
.actionGet();
76+
assertEquals(1, tasks.getTasks().size());
77+
});
78+
assertAcked(
79+
client().admin()
80+
.cluster()
81+
.prepareUpdateSettings()
82+
.setPersistentSettings(Settings.builder().put(GeoIpDownloaderTaskExecutor.ENABLED_SETTING.getKey(), false))
83+
.get()
84+
);
85+
assertBusy(() -> {
86+
ListTasksResponse tasks2 = client().admin()
87+
.cluster()
88+
.listTasks(new ListTasksRequest().setActions("geoip-downloader[c]"))
89+
.actionGet();
90+
assertEquals(0, tasks2.getTasks().size());
91+
});
92+
}
93+
94+
private PersistentTasksCustomMetadata.PersistentTask<PersistentTaskParams> getTask() {
95+
return PersistentTasksCustomMetadata.getTaskWithId(clusterService().state(), GeoIpDownloader.GEOIP_DOWNLOADER);
96+
}
97+
}

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ protected void onCancelled() {
299299
if (scheduled != null) {
300300
scheduled.cancel();
301301
}
302+
markAsCompleted();
302303
}
303304

304305
@Override

0 commit comments

Comments
 (0)