Skip to content

Commit 899110c

Browse files
[7.14] Fix GeoIpProcessor when there's no updated db (#74944) (#74947)
* Fix GeoIpProcessor when there's no updated db (#74944) This change fixes problem with GeoIpProcessor when there's GeoIpTaskState present in the cluster state but there's no database matching the one used by the processor. It can happen when there are some but not all databases already updated. * fix compilation Co-authored-by: Przemko Robakowski <[email protected]>
1 parent ff2ed38 commit 899110c

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,9 @@ public GeoIpProcessor create(
436436
return true;
437437
}
438438
GeoIpTaskState state = (GeoIpTaskState) task.getState();
439-
return state.getDatabases().get(databaseFile).isValid(currentState.metadata().settings());
439+
GeoIpTaskState.Metadata metadata = state.getDatabases().get(databaseFile);
440+
// we never remove metadata from cluster state, if metadata is null we deal with built-in database, which is always valid
441+
return metadata == null || metadata.isValid(currentState.metadata().settings());
440442
};
441443
return new GeoIpProcessor(processorTag, description, ipField, supplier, isValid, targetField, properties, ignoreMissing,
442444
firstOnly);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
6666
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
67+
import static org.elasticsearch.ingest.IngestService.INGEST_ORIGIN;
6768
import static org.elasticsearch.ingest.geoip.GeoIpDownloader.DATABASES_INDEX;
6869
import static org.elasticsearch.ingest.geoip.GeoIpDownloader.GEOIP_DOWNLOADER;
6970

@@ -169,7 +170,7 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
169170
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
170171
.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1")
171172
.build())
172-
.setOrigin("geoip")
173+
.setOrigin(INGEST_ORIGIN)
173174
.setVersionMetaKey("version")
174175
.setPrimaryIndex(DATABASES_INDEX)
175176
.setNetNew()

modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpProcessorFactoryTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@
99
package org.elasticsearch.ingest.geoip;
1010

1111
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
12+
1213
import org.elasticsearch.ElasticsearchParseException;
1314
import org.elasticsearch.ResourceNotFoundException;
1415
import org.elasticsearch.client.Client;
1516
import org.elasticsearch.cluster.ClusterState;
17+
import org.elasticsearch.cluster.metadata.Metadata;
1618
import org.elasticsearch.cluster.service.ClusterService;
1719
import org.elasticsearch.common.Randomness;
1820
import org.elasticsearch.common.settings.Settings;
1921
import org.elasticsearch.index.VersionType;
2022
import org.elasticsearch.ingest.IngestDocument;
2123
import org.elasticsearch.ingest.IngestService;
2224
import org.elasticsearch.ingest.RandomDocumentPicks;
25+
import org.elasticsearch.persistent.PersistentTasksCustomMetadata;
2326
import org.elasticsearch.test.ESTestCase;
2427
import org.elasticsearch.test.StreamsUtils;
2528
import org.elasticsearch.threadpool.TestThreadPool;
@@ -367,6 +370,26 @@ public void testFallbackUsingDefaultDatabases() throws Exception {
367370
}
368371
}
369372

373+
public void testDefaultDatabaseWithTaskPresent() throws Exception {
374+
PersistentTasksCustomMetadata tasks = PersistentTasksCustomMetadata.builder()
375+
.addTask(GeoIpDownloader.GEOIP_DOWNLOADER, GeoIpDownloader.GEOIP_DOWNLOADER, null, null)
376+
.updateTaskState(GeoIpDownloader.GEOIP_DOWNLOADER, GeoIpTaskState.EMPTY)
377+
.build();
378+
ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
379+
.metadata(Metadata.builder().putCustom(PersistentTasksCustomMetadata.TYPE, tasks))
380+
.build();
381+
when(clusterService.state()).thenReturn(clusterState);
382+
GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseRegistry, clusterService);
383+
384+
Map<String, Object> config = new HashMap<>();
385+
config.put("field", "_field");
386+
String processorTag = randomAlphaOfLength(10);
387+
388+
GeoIpProcessor processor = factory.create(null, processorTag, null, config);
389+
390+
processor.execute(RandomDocumentPicks.randomIngestDocument(random(), org.elasticsearch.core.Map.of("_field", "89.160.20.128")));
391+
}
392+
370393
public void testFallbackUsingDefaultDatabasesWhileIngesting() throws Exception {
371394
copyDatabaseFile(geoipTmpDir, "GeoLite2-City-Test.mmdb");
372395
GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseRegistry, clusterService);

0 commit comments

Comments
 (0)