Skip to content

Commit efb99d3

Browse files
committed
Revert GeoIp search to reduce size of change
1 parent 45d982e commit efb99d3

13 files changed

+296
-434
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ final class ConfigDatabases implements Closeable {
3939
private final GeoIpCache cache;
4040
private final Path geoipConfigDir;
4141

42-
// private final ConcurrentMap<ProjectId, ConcurrentMap<String, DatabaseReaderLazyLoader>> configDatabasesByProject;
4342
private final ConcurrentMap<String, DatabaseReaderLazyLoader> configDatabases;
4443

4544
ConfigDatabases(Environment environment, GeoIpCache cache) {

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

Lines changed: 190 additions & 265 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ public final String getDatabaseType() throws IOException {
8888
return databaseType.get();
8989
}
9090

91-
/**
92-
* Prepares the database for lookup by incrementing the usage count.
93-
* If the usage count is already negative, it indicates that the database is being closed,
94-
* and this method will return false to indicate that no lookup should be performed.
95-
*
96-
* @return true if the database is ready for lookup, false if it is being closed
97-
*/
9891
boolean preLookup() {
9992
return currentUsages.updateAndGet(current -> current < 0 ? current : current + 1) > 0;
10093
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ public void writeTo(StreamOutput out) throws IOException {
146146
* @return the geoip downloader's task state or null if there is not a state to read
147147
*/
148148
@Nullable
149-
@Deprecated(forRemoval = true)
150149
static EnterpriseGeoIpTaskState getEnterpriseGeoIpTaskState(ClusterState state) {
151150
PersistentTasksCustomMetadata.PersistentTask<?> task = getTaskWithId(state, EnterpriseGeoIpTask.ENTERPRISE_GEOIP_DOWNLOADER);
152151
return (task == null) ? null : (EnterpriseGeoIpTaskState) task.getState();

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import java.util.Objects;
5454
import java.util.Set;
5555
import java.util.concurrent.ConcurrentHashMap;
56-
import java.util.concurrent.ConcurrentMap;
5756
import java.util.concurrent.atomic.AtomicBoolean;
5857
import java.util.concurrent.atomic.AtomicReference;
5958

@@ -107,9 +106,9 @@ public final class GeoIpDownloaderTaskExecutor extends PersistentTasksExecutor<G
107106
private volatile TimeValue pollInterval;
108107
private volatile boolean eagerDownload;
109108

110-
private final ConcurrentMap<ProjectId, AtomicBoolean> atLeastOneGeoipProcessorByProject = new ConcurrentHashMap<>();
111-
private final ConcurrentMap<ProjectId, AtomicBoolean> taskIsBootstrappedByProject = new ConcurrentHashMap<>();
112-
private final ConcurrentMap<ProjectId, AtomicReference<GeoIpDownloader>> tasks = new ConcurrentHashMap<>();
109+
private final ConcurrentHashMap<ProjectId, AtomicBoolean> atLeastOneGeoipProcessorByProject = new ConcurrentHashMap<>();
110+
private final ConcurrentHashMap<ProjectId, AtomicBoolean> taskIsBootstrappedByProject = new ConcurrentHashMap<>();
111+
private final ConcurrentHashMap<ProjectId, AtomicReference<GeoIpDownloader>> tasks = new ConcurrentHashMap<>();
113112
private final ProjectResolver projectResolver;
114113

115114
GeoIpDownloaderTaskExecutor(
@@ -410,7 +409,7 @@ private static boolean isForeachProcessorWithGeoipProcessor(Map<String, Object>
410409
private void startTask(Runnable onFailure) {
411410
assert projectResolver.getProjectId() != null : "projectId must be set before starting geoIp download task";
412411
persistentTasksService.sendStartRequest(
413-
getTaskId(projectResolver.getProjectId(), projectResolver.supportsMultipleProjects()),
412+
getTaskId(projectResolver.getProjectId()),
414413
GEOIP_DOWNLOADER,
415414
new GeoIpTaskParams(),
416415
MasterNodeRequest.INFINITE_MASTER_NODE_TIMEOUT,
@@ -439,7 +438,7 @@ private void stopTask(Runnable onFailure) {
439438
}
440439
);
441440
persistentTasksService.sendRemoveRequest(
442-
getTaskId(projectId, projectResolver.supportsMultipleProjects()),
441+
getTaskId(projectId),
443442
MasterNodeRequest.INFINITE_MASTER_NODE_TIMEOUT,
444443
ActionListener.runAfter(listener, () -> {
445444
IndexAbstraction databasesAbstraction = clusterService.state()
@@ -472,7 +471,7 @@ public GeoIpDownloader getTask(ProjectId projectId) {
472471
return null;
473472
}
474473

475-
public static String getTaskId(ProjectId projectId, boolean supportsMultipleProjects) {
476-
return supportsMultipleProjects ? projectId + "/" + GEOIP_DOWNLOADER : GEOIP_DOWNLOADER;
474+
private String getTaskId(ProjectId projectId) {
475+
return projectResolver.supportsMultipleProjects() ? projectId + "/" + GEOIP_DOWNLOADER : GEOIP_DOWNLOADER;
477476
}
478477
}

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,16 @@ public static final class DatabaseVerifyingSupplier implements CheckedSupplier<I
180180
private final IpDatabaseProvider ipDatabaseProvider;
181181
private final String databaseFile;
182182
private final String databaseType;
183-
private final ProjectId projectId;
184-
185-
public DatabaseVerifyingSupplier(
186-
IpDatabaseProvider ipDatabaseProvider,
187-
String databaseFile,
188-
String databaseType,
189-
ProjectId projectId
190-
) {
183+
184+
public DatabaseVerifyingSupplier(IpDatabaseProvider ipDatabaseProvider, String databaseFile, String databaseType) {
191185
this.ipDatabaseProvider = ipDatabaseProvider;
192186
this.databaseFile = databaseFile;
193187
this.databaseType = databaseType;
194-
this.projectId = projectId;
195188
}
196189

197190
@Override
198191
public IpDatabase get() throws IOException {
199-
IpDatabase loader = ipDatabaseProvider.getDatabase(projectId, databaseFile);
192+
IpDatabase loader = ipDatabaseProvider.getDatabase(databaseFile);
200193
if (loader == null) {
201194
return null;
202195
}
@@ -249,7 +242,7 @@ public Processor create(
249242
readBooleanProperty(type, processorTag, config, "download_database_on_pipeline_creation", true);
250243

251244
final String databaseType;
252-
try (IpDatabase ipDatabase = ipDatabaseProvider.getDatabase(projectId, databaseFile)) {
245+
try (IpDatabase ipDatabase = ipDatabaseProvider.getDatabase(databaseFile)) {
253246
if (ipDatabase == null) {
254247
// It's possible that the database could be downloaded via the GeoipDownloader process and could become available
255248
// at a later moment, so a processor impl is returned that tags documents instead. If a database cannot be sourced
@@ -309,8 +302,8 @@ public Processor create(
309302
processorTag,
310303
description,
311304
ipField,
312-
new DatabaseVerifyingSupplier(ipDatabaseProvider, databaseFile, databaseType, projectId),
313-
() -> ipDatabaseProvider.isValid(projectId, databaseFile),
305+
new DatabaseVerifyingSupplier(ipDatabaseProvider, databaseFile, databaseType),
306+
() -> ipDatabaseProvider.isValid(databaseFile),
314307
targetField,
315308
ipDataLookup,
316309
ignoreMissing,

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import org.elasticsearch.TransportVersion;
1313
import org.elasticsearch.TransportVersions;
14-
import org.elasticsearch.cluster.metadata.ProjectMetadata;
14+
import org.elasticsearch.cluster.ClusterState;
1515
import org.elasticsearch.common.io.stream.StreamInput;
1616
import org.elasticsearch.common.io.stream.StreamOutput;
1717
import org.elasticsearch.common.io.stream.VersionedNamedWriteable;
@@ -252,31 +252,16 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
252252
}
253253
}
254254

255-
// /**
256-
// * Retrieves the geoip downloader's task state from the cluster state. This may return null in some circumstances,
257-
// * for example if the geoip downloader task hasn't been created yet (which it wouldn't be if it's disabled).
258-
// *
259-
// * @param state the cluster state to read the task state from
260-
// * @return the geoip downloader's task state or null if there is not a state to read
261-
// */
262-
// @Nullable
263-
// @Deprecated(forRemoval = true)
264-
// static GeoIpTaskState getGeoIpTaskState(ClusterState state) {
265-
// PersistentTasksCustomMetadata.PersistentTask<?> task = getTaskWithId(state, GeoIpDownloader.GEOIP_DOWNLOADER);
266-
// return (task == null) ? null : (GeoIpTaskState) task.getState();
267-
// }
268-
269255
/**
270-
* Retrieves the geoip downloader's task state from the project metadata. This may return null in some circumstances,
256+
* Retrieves the geoip downloader's task state from the cluster state. This may return null in some circumstances,
271257
* for example if the geoip downloader task hasn't been created yet (which it wouldn't be if it's disabled).
272258
*
273-
* @param projectMetadata the project metatdata to read the task state from.
274-
* @param taskId the task ID of the geoip downloader task to read the state for.
259+
* @param state the cluster state to read the task state from
275260
* @return the geoip downloader's task state or null if there is not a state to read
276261
*/
277262
@Nullable
278-
static GeoIpTaskState getGeoIpTaskState(ProjectMetadata projectMetadata, String taskId) {
279-
PersistentTasksCustomMetadata.PersistentTask<?> task = getTaskWithId(projectMetadata, taskId);
263+
static GeoIpTaskState getGeoIpTaskState(ClusterState state) {
264+
PersistentTasksCustomMetadata.PersistentTask<?> task = getTaskWithId(state, GeoIpDownloader.GEOIP_DOWNLOADER);
280265
return (task == null) ? null : (GeoIpTaskState) task.getState();
281266
}
282267

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public Map<String, Processor.Factory> getProcessors(Processor.Parameters paramet
139139
public Collection<?> createComponents(PluginServices services) {
140140
try {
141141
String nodeId = services.nodeEnvironment().nodeId();
142-
databaseRegistry.get().initialize(nodeId, services.resourceWatcherService(), ingestService.get(), services.projectResolver());
142+
databaseRegistry.get().initialize(nodeId, services.resourceWatcherService(), ingestService.get());
143143
} catch (IOException e) {
144144
throw new UncheckedIOException(e);
145145
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
package org.elasticsearch.ingest.geoip;
1111

12-
import org.elasticsearch.cluster.metadata.ProjectId;
13-
1412
/**
1513
* Provides construction and initialization logic for {@link IpDatabase} instances.
1614
*/
@@ -22,17 +20,15 @@ public interface IpDatabaseProvider {
2220
* Verifying database expiration is left to each provider implementation to determine. A return value of <code>false</code> does not
2321
* preclude the possibility of a provider returning <code>true</code> in the future.
2422
*
25-
* @param projectId projectId to look for database.
2623
* @param name the name of the database to provide.
2724
* @return <code>false</code> IFF the requested database file is expired,
2825
* <code>true</code> for all other cases (including unknown file name, file missing, wrong database type, etc).
2926
*/
30-
Boolean isValid(ProjectId projectId, String name);
27+
Boolean isValid(String name);
3128

3229
/**
33-
* @param projectId projectId to look for database.
3430
* @param name the name of the database to provide.
3531
* @return a ready-to-use database instance, or <code>null</code> if no database could be loaded.
3632
*/
37-
IpDatabase getDatabase(ProjectId projectId, String name);
33+
IpDatabase getDatabase(String name);
3834
}

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/stats/GeoIpStatsTransportAction.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.action.FailedNodeException;
1313
import org.elasticsearch.action.support.ActionFilters;
1414
import org.elasticsearch.action.support.nodes.TransportNodesAction;
15-
import org.elasticsearch.cluster.metadata.ProjectId;
1615
import org.elasticsearch.cluster.node.DiscoveryNode;
1716
import org.elasticsearch.cluster.project.ProjectResolver;
1817
import org.elasticsearch.cluster.service.ClusterService;
@@ -78,16 +77,15 @@ protected NodeResponse newNodeResponse(StreamInput in, DiscoveryNode node) throw
7877

7978
@Override
8079
protected NodeResponse nodeOperation(NodeRequest request, Task task) {
81-
ProjectId projectId = projectResolver.getProjectId();
82-
GeoIpDownloader geoIpTask = geoIpDownloaderTaskExecutor.getTask(projectId);
80+
GeoIpDownloader geoIpTask = geoIpDownloaderTaskExecutor.getTask(projectResolver.getProjectId());
8381
GeoIpDownloaderStats downloaderStats = geoIpTask == null || geoIpTask.getStatus() == null ? null : geoIpTask.getStatus();
8482
CacheStats cacheStats = registry.getCacheStats();
8583
return new NodeResponse(
8684
transportService.getLocalNode(),
8785
downloaderStats,
8886
cacheStats,
89-
registry.getAvailableDatabases(projectId),
90-
registry.getFilesInTemp(projectId),
87+
registry.getAvailableDatabases(),
88+
registry.getFilesInTemp(),
9189
registry.getConfigDatabases()
9290
);
9391
}

0 commit comments

Comments
 (0)