Eviction redesign
brian.stansberry Aug 1, 2008 10:28 AMDiscussion re: any redesign of eviction for JBC 3.
Somewhat quoting myself from a tangent on another thread:
Looking at the eviction system in JBC, it seems nicely set up to work a la carte:
1) An interceptor that generates events and passes them to the region, which queues them. (This is somewhat coupled to #2 via the EvictionPolicy.canIgnoreEvent() call the interceptor makes.)
2) The EvictionPolicy/Algorithm which can process the region's queue of events and determine what to evict, and then evict it.
3) The evict() API on the cache, which is used by EvictionPolicy/Algorithm but also allows self-managed eviction.
4) A thread-management system that kicks off #2.
So, main thing is I think JBC should support these combos from the a la carte menu:
#1 + #2 + #3 + #4 (of course)
#3
#1 + #2 + #3.
The last can be achieved by setting the wakeupIntervalSeconds to 0, which effectively disables #4. An application can then manage eviction itself by:
a) getting the EvictionPolicy associated with the region (which is part of the public API of Region)
b) get the EvictionAlgorithm from that (which is part of the public EvictionPolicy API) c) process() on that (which is part of the public EvictionAlgorithm API).
So, to provide a la carte eviction the main thing is to keep logical equivalents to those 3 API calls I described above available.
I don't see any point in JBC trying to support #1 + #3 (i.e. add a way to bypass the EvictionInterceptor call to EvictionPolicy.canIgnoreEvent()). If someone wants that they can just implement a CacheListener to get events.
The area where things are a bit clunky is the API of EvictionPolicy/EvictionAlgorithm. Currently those are a bit of a mix of API and SPI, with an implementation detail (delegate to EvictionAlgorithm) mixed in. Some initial thoughts on improving this:
1) No one should need to call EvictionAlgorithm except an EvictionPolicy impl. That is, that's an internal implementation detail.
2) Perhaps the EvictionPolicy interface should just be a client interface. That is, just expose what's needed by a thread that wants to run eviction: process()
3) Then add an EvictionPolicySPI interface. That includes methods needed to integrate the policy impl into the cache, plus those needed by the event tracking mechanism (e.g. canIgnoreEvent()).
Separating the SPI from EvictionPolicy is kind of just being anal, but if it doesn't introduce problems I think anal is good. :-) Doing #1 will change the EvictionPolicy interface anyway, so not existing impls will break anyway.