Expiry Policy on Off Heap entries not working as expected in Ignite
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Apache Ignite is a distributed database and computing platform that enables the caching and processing of large volumes of data in a highly available and scalable manner. One of the features provided by Ignite is the ability to store data either in heap or off-heap memory, which facilitates control over memory consumption and provides better performance by avoiding Java's Garbage Collection (GC) overhead. However, one common issue users face when employing Ignite’s Off-Heap storage is related to the Expiry Policy not behaving as expected. This article delves into this issue, exploring its technical nuances, potential pitfalls, and solutions.
Understanding Off-Heap Storage
Off-heap storage allows data to be stored outside the Java heap space. It is managed directly by Ignite through native memory allocation, thereby avoiding Java GC. This is particularly beneficial for managing large caches that could potentially lead to long GC pause times if stored on-heap.
Expiry Policy in Ignite
An Expiry Policy in Ignite defines the criteria for how long cache entries should live before they are considered invalid or stale and are hence removed. Ignite supports three types of expiry durations:
- Create: The duration since the entry was created.
- Update: The duration since the entry was updated.
- Access: The duration since the entry was accessed.
Expiry Policies can be configured globally or on a per-cache basis, allowing fine-grained control over how cache data expires.
Issue with Expiry Policies on Off-Heap Entries
The typical issue observed with off-heap entries is that expiry policies may not function as intended. Users have noted scenarios where entries that should have been expired, according to the defined policies, persist in the cache. Several factors contribute to this behavior:
1. Asynchronous Expiry Policy Processing
Ignite processes expiry asynchronously to avoid blocking cache operations. As a result, there can be a delay between when an entry meets the expiry condition and when it is actually removed from the cache.
2. Off-Heap and On-Heap Sync
With entries stored off-heap, there is an additional overhead in syncing the state of the entry between the off-heap and on-heap representations. In some cases, this might result in expiry not being checked consistently across different memory storages.
3. Low-level Native Memory Management
Managing native memory differs significantly from managed Java memory. Discrepancies in how expiration metadata is handled in off-heap storage can lead to unexpected behavior.
Examples Demonstrating the Issue
Assuming a cache configuration with an expiry policy of 5 minutes for both create and access:
Troubleshooting and Solutions
- Force Sync: Manually trigger a synchronization between the off-heap and on-heap storage or explicitly check for expiry when performing critical operations.
- Monitoring and Alerts: Implement monitoring for the sizes of the caches and configure alerts for anomalies that could indicate issues with data not expiring as expected.
- Configuration Review: Review and ensure that the expiry policies are correctly configured, including any programmatic vs. declarative discrepancies.
Summary Table
| Feature | Description | Issues | Solutions |
| Off-Heap Storage | Stores data outside the Java heap to manage large caches efficiently | Expiry policies might not trigger as expected due to delayed or inconsistent syncs | Force sync, monitor cache sizes, review configurations |
| Expiry Policy | Defines rules for when cache entries expire | Delays in processing expiry | Manual checks, synchronization improvements |
| Asynchronous Processing | Enhances performance by non-blocking operations | Can lead to delays in expiry processing | Monitoring and synchronization checks |
Conclusion
Expiry policies in Ignite when using off-heap storage can occasionally lead to unexpected results, primarily due to the complexities involved in managing native memory and synchronizing it with on-heap data. Proper understanding, configuration, and monitoring are vital to ensure that the data integrity and cache performance are maintained according to expectations.

