Skip to content

Commit 2b935e1

Browse files
committed
Revert "Revert GeoIp search to reduce size of change"
This reverts commit efb99d3.
1 parent a54d56b commit 2b935e1

File tree

12 files changed

+426
-289
lines changed

12 files changed

+426
-289
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ 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;
4243
private final ConcurrentMap<String, DatabaseReaderLazyLoader> configDatabases;
4344

4445
ConfigDatabases(Environment environment, GeoIpCache cache) {

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

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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ 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+
*/
9198
boolean preLookup() {
9299
return currentUsages.updateAndGet(current -> current < 0 ? current : current + 1) > 0;
93100
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ 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)
149150
static EnterpriseGeoIpTaskState getEnterpriseGeoIpTaskState(ClusterState state) {
150151
PersistentTasksCustomMetadata.PersistentTask<?> task = getTaskWithId(state, EnterpriseGeoIpTask.ENTERPRISE_GEOIP_DOWNLOADER);
151152
return (task == null) ? null : (EnterpriseGeoIpTaskState) task.getState();

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

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

190197
@Override
191198
public IpDatabase get() throws IOException {
192-
IpDatabase loader = ipDatabaseProvider.getDatabase(databaseFile);
199+
IpDatabase loader = ipDatabaseProvider.getDatabase(projectId, databaseFile);
193200
if (loader == null) {
194201
return null;
195202
}
@@ -242,7 +249,7 @@ public Processor create(
242249
readBooleanProperty(type, processorTag, config, "download_database_on_pipeline_creation", true);
243250

244251
final String databaseType;
245-
try (IpDatabase ipDatabase = ipDatabaseProvider.getDatabase(databaseFile)) {
252+
try (IpDatabase ipDatabase = ipDatabaseProvider.getDatabase(projectId, databaseFile)) {
246253
if (ipDatabase == null) {
247254
// It's possible that the database could be downloaded via the GeoipDownloader process and could become available
248255
// at a later moment, so a processor impl is returned that tags documents instead. If a database cannot be sourced
@@ -302,8 +309,8 @@ public Processor create(
302309
processorTag,
303310
description,
304311
ipField,
305-
new DatabaseVerifyingSupplier(ipDatabaseProvider, databaseFile, databaseType),
306-
() -> ipDatabaseProvider.isValid(databaseFile),
312+
new DatabaseVerifyingSupplier(ipDatabaseProvider, databaseFile, databaseType, projectId),
313+
() -> ipDatabaseProvider.isValid(projectId, databaseFile),
307314
targetField,
308315
ipDataLookup,
309316
ignoreMissing,

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

Lines changed: 20 additions & 5 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.ClusterState;
14+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
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,16 +252,31 @@ 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+
255269
/**
256-
* Retrieves the geoip downloader's task state from the cluster state. This may return null in some circumstances,
270+
* Retrieves the geoip downloader's task state from the project metadata. This may return null in some circumstances,
257271
* for example if the geoip downloader task hasn't been created yet (which it wouldn't be if it's disabled).
258272
*
259-
* @param state the cluster state to read the task state from
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.
260275
* @return the geoip downloader's task state or null if there is not a state to read
261276
*/
262277
@Nullable
263-
static GeoIpTaskState getGeoIpTaskState(ClusterState state) {
264-
PersistentTasksCustomMetadata.PersistentTask<?> task = getTaskWithId(state, GeoIpDownloader.GEOIP_DOWNLOADER);
278+
static GeoIpTaskState getGeoIpTaskState(ProjectMetadata projectMetadata, String taskId) {
279+
PersistentTasksCustomMetadata.PersistentTask<?> task = getTaskWithId(projectMetadata, taskId);
265280
return (task == null) ? null : (GeoIpTaskState) task.getState();
266281
}
267282

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());
142+
databaseRegistry.get().initialize(nodeId, services.resourceWatcherService(), ingestService.get(), services.projectResolver());
143143
} catch (IOException e) {
144144
throw new UncheckedIOException(e);
145145
}

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

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

1010
package org.elasticsearch.ingest.geoip;
1111

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

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

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
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;
1516
import org.elasticsearch.cluster.node.DiscoveryNode;
1617
import org.elasticsearch.cluster.project.ProjectResolver;
1718
import org.elasticsearch.cluster.service.ClusterService;
@@ -77,15 +78,16 @@ protected NodeResponse newNodeResponse(StreamInput in, DiscoveryNode node) throw
7778

7879
@Override
7980
protected NodeResponse nodeOperation(NodeRequest request, Task task) {
80-
GeoIpDownloader geoIpTask = geoIpDownloaderTaskExecutor.getTask(projectResolver.getProjectId());
81+
ProjectId projectId = projectResolver.getProjectId();
82+
GeoIpDownloader geoIpTask = geoIpDownloaderTaskExecutor.getTask(projectId);
8183
GeoIpDownloaderStats downloaderStats = geoIpTask == null || geoIpTask.getStatus() == null ? null : geoIpTask.getStatus();
8284
CacheStats cacheStats = registry.getCacheStats();
8385
return new NodeResponse(
8486
transportService.getLocalNode(),
8587
downloaderStats,
8688
cacheStats,
87-
registry.getAvailableDatabases(),
88-
registry.getFilesInTemp(),
89+
registry.getAvailableDatabases(projectId),
90+
registry.getFilesInTemp(projectId),
8991
registry.getConfigDatabases()
9092
);
9193
}

0 commit comments

Comments
 (0)