Skip to content

Commit a6a4135

Browse files
committed
Use a cached task state rather than rebuilding it
1 parent faf0b5f commit a6a4135

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public final class DatabaseNodeService implements IpDatabaseProvider {
104104
private final ClusterService clusterService;
105105
private IngestService ingestService;
106106

107+
// this reference is set and updated in checkDatabases below
108+
private volatile GeoIpTaskState taskState = GeoIpTaskState.EMPTY;
109+
107110
private final ConcurrentMap<String, DatabaseReaderLazyLoader> databases = new ConcurrentHashMap<>();
108111

109112
DatabaseNodeService(
@@ -185,12 +188,13 @@ public Boolean isValid(String databaseFile) {
185188
ClusterState currentState = clusterService.state();
186189
assert currentState != null;
187190

188-
GeoIpTaskState state = getGeoIpTaskState(currentState);
189-
if (state == null) {
191+
if (taskState == null) {
190192
return true;
191193
}
192194

193-
GeoIpTaskState.Metadata metadata = state.getDatabases().get(databaseFile);
195+
// use the cached taskState reference to figure out if this database is valid
196+
GeoIpTaskState.Metadata metadata = taskState.getDatabases().get(databaseFile);
197+
194198
// we never remove metadata from cluster state, if metadata is null we deal with built-in database, which is always valid
195199
if (metadata == null) {
196200
return true;
@@ -298,6 +302,9 @@ void checkDatabases(ClusterState state) {
298302
// Note: an empty state will purge stale entries in databases map
299303
taskState = GeoIpTaskState.EMPTY;
300304
}
305+
// update the cached taskState reference to reflect this current information for future isValid checks
306+
this.taskState = taskState;
307+
301308
validMetadatas.addAll(
302309
taskState.getDatabases()
303310
.entrySet()

0 commit comments

Comments
 (0)