Make IndexReader.CacheKey serializable
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
### Description
As of now, lucene LRU query cache and other OpenSearch caches uses [CacheKey](https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/index/IndexReader.java#L132) as a primary key for their caches as it helps to determine any changes during segment merges etc. Then it uses IdentityHashMap and object equality for the comparison.
I was looking for some ways to serialize this CacheKey and store cache data on offheap/disk etc. But seems like I can't do it. I can't really extend it as it is declared as final, it doesn't implement Serializable, or even after serialization/deserialization process the actual object will change making it useless in the end. Using java hashcode is again not safe to use.
I was thinking for simplicity sake whether we could assign some unique id to this class during initialization which can be used instead of the object itself.
Something like
```
public static final class CacheKey {
private final UUID uniqueId;
CacheKey() {
uniqueId = UUID.randomUUID();
}
public String getUniqueId() {
return uniqueId.toString();
}
}
````
Let me know what you folks think as this seems like a harmless change.
Contributor guide
Research direction
Review IndexReader.CacheKey in the linked Lucene source and how the LRU query cache and other OpenSearch caches use it. Clarify the required identity and serialization behavior, including whether an identifier remains valid after deserialization. Done means an agreed, tested design that supports the intended off-heap or disk cache use without breaking identity-based comparisons.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, search
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100