Skip to content

Commit 68161e8

Browse files
committed
Add some explanatory comments
1 parent 25605eb commit 68161e8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ public LifecyclePolicyMetadata read(StreamInput in, String key) {
165165
}
166166
}
167167

168+
/**
169+
* Remove the entry for an index from the index->step cache.
170+
*
171+
* We clear the map entirely when the master of the cluster changes, and when any
172+
* policy changes, but in a long-lived cluster that doesn't happen to experience
173+
* either of those events (and where indices are removed regularly) we still want
174+
* the cache to trim deleted indices.
175+
*/
168176
public void delete(Index deleted) {
169177
cachedSteps.remove(deleted);
170178
}
@@ -294,6 +302,9 @@ private List<Step> parseStepsFromPhase(String policy, String currentPhase, Strin
294302
@Nullable
295303
public Step getStep(final IndexMetadata indexMetadata, final Step.StepKey stepKey) {
296304
final Tuple<IndexMetadata, Step> cachedStep = cachedSteps.get(indexMetadata.getIndex());
305+
// n.b. we're using instance equality here for the IndexMetadata rather than object equality because it's fast,
306+
// this means that we're erring on the side of cache misses (if the IndexMetadata changed in any way, it'll be
307+
// a new instance, so we'll miss-and-repopulate the cache for the index in question)
297308
if (cachedStep != null && cachedStep.v1() == indexMetadata && cachedStep.v2().getKey().equals(stepKey)) {
298309
return cachedStep.v2();
299310
}

0 commit comments

Comments
 (0)