Class ClusterExpirationManager<K,V>
- java.lang.Object
-
- org.infinispan.expiration.impl.ExpirationManagerImpl<K,V>
-
- org.infinispan.expiration.impl.ClusterExpirationManager<K,V>
-
- Type Parameters:
K
-V
-
- All Implemented Interfaces:
ExpirationManager<K,V>
,InternalExpirationManager<K,V>
- Direct Known Subclasses:
TxClusterExpirationManager
@ThreadSafe public class ClusterExpirationManager<K,V> extends ExpirationManagerImpl<K,V>
Allows for cluster based expirations to occur. This provides guarantees that when an entry is expired that it will expire that entry across the entire cluster at once. This requires obtaining the lock for said entry before expiration is performed. Since expiration can occur without holding onto the lock it is possible for an expiration to occur immediately after a value has been updated. This can cause a premature expiration to occur. Attempts are made to prevent this by using the expired entry's value and lifespan to limit this expiration so it only happens in a smaller amount of cases.Cache stores however do not supply the value or metadata information which means if an entry is purged from the cache store that it will forcibly remove the value even if a concurrent write updated it just before. This will be addressed by future SPI changes to the cache store.
-
-
Field Summary
Fields Modifier and Type Field Description protected ComponentRef<AdvancedCache<K,V>>
cacheRef
protected ComponentRef<CommandsFactory>
cf
protected DistributionManager
distributionManager
protected RpcManager
rpcManager
-
Fields inherited from class org.infinispan.expiration.impl.ExpirationManagerImpl
cacheName, cacheNotifier, configuration, dataContainer, enabled, executor, expirationTask, expiring, keyPartitioner, persistenceManager, timeService
-
-
Constructor Summary
Constructors Constructor Description ClusterExpirationManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Boolean>
entryExpiredInMemory(InternalCacheEntry<K,V> entry, long currentTime, boolean hasLock)
This should be invoked passing in an entry that is now expired.CompletableFuture<Boolean>
entryExpiredInMemoryFromIteration(InternalCacheEntry<K,V> entry, long currentTime)
This method is very similar toInternalExpirationManager.entryExpiredInMemory(InternalCacheEntry, long, boolean)
except that it does the bare minimum when an entry expired to guarantee if the entry is valid or not.void
handleInStoreExpiration(K key)
This is to be invoked when a store entry expires.void
handleInStoreExpiration(MarshalledEntry<K,V> marshalledEntry)
This is to be invoked when a store entry expires and the value and/or metadata is available to be used.void
processExpiration()
Processes the expiration event queue.CompletableFuture<Long>
retrieveLastAccess(Object key, Object value, int segment)
Retrieves the last access time for the given key in the data container if it is using max idle.void
start()
-
Methods inherited from class org.infinispan.expiration.impl.ExpirationManagerImpl
handleInMemoryExpiration, isEnabled, localLastAccess, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.expiration.ExpirationManager
registerWriteIncoming, unregisterWrite
-
-
-
-
Field Detail
-
cacheRef
protected ComponentRef<AdvancedCache<K,V>> cacheRef
-
cf
protected ComponentRef<CommandsFactory> cf
-
rpcManager
protected RpcManager rpcManager
-
distributionManager
protected DistributionManager distributionManager
-
-
Method Detail
-
start
public void start()
- Overrides:
start
in classExpirationManagerImpl<K,V>
-
processExpiration
public void processExpiration()
Description copied from interface:ExpirationManager
Processes the expiration event queue.- Specified by:
processExpiration
in interfaceExpirationManager<K,V>
- Overrides:
processExpiration
in classExpirationManagerImpl<K,V>
-
entryExpiredInMemory
public CompletableFuture<Boolean> entryExpiredInMemory(InternalCacheEntry<K,V> entry, long currentTime, boolean hasLock)
Description copied from interface:InternalExpirationManager
This should be invoked passing in an entry that is now expired. This method may attempt to lock this key to preserve atomicity. This method should be invoked when an entry was read via get but found to be expired.This method returns true if the entry was removed due to expiration or false if the entry was not removed due to expiration
If hasLock is true, this method assumes that the caller has the lock for the key and it must allow the expiration to occur, ie. returned CompletableFuture has completed, before the lock is released. Failure to do so may cause inconsistency in data.
- Specified by:
entryExpiredInMemory
in interfaceInternalExpirationManager<K,V>
- Overrides:
entryExpiredInMemory
in classExpirationManagerImpl<K,V>
- Parameters:
entry
- the entry that has expiredcurrentTime
- the current time when it expiredhasLock
- if the expiration was found during a write operation- Returns:
- if this entry actually expired or not
-
entryExpiredInMemoryFromIteration
public CompletableFuture<Boolean> entryExpiredInMemoryFromIteration(InternalCacheEntry<K,V> entry, long currentTime)
Description copied from interface:InternalExpirationManager
This method is very similar toInternalExpirationManager.entryExpiredInMemory(InternalCacheEntry, long, boolean)
except that it does the bare minimum when an entry expired to guarantee if the entry is valid or not. This is important to reduce time spent per entry when iterating. This method may not actually remove the entry and may just return immediately if it is safe to do so.- Specified by:
entryExpiredInMemoryFromIteration
in interfaceInternalExpirationManager<K,V>
- Overrides:
entryExpiredInMemoryFromIteration
in classExpirationManagerImpl<K,V>
- Parameters:
entry
- the entry that has expiredcurrentTime
- the current time when it expired- Returns:
- if this entry actually expired or not
-
handleInStoreExpiration
public void handleInStoreExpiration(K key)
Description copied from interface:InternalExpirationManager
This is to be invoked when a store entry expires. This method may attempt to lock this key to preserve atomicity.Note this method doesn't currently take a
InternalCacheEntry
and this is due to a limitation in the cache store API. This may cause some values to be removed if they were updated at the same time.- Specified by:
handleInStoreExpiration
in interfaceExpirationManager<K,V>
- Specified by:
handleInStoreExpiration
in interfaceInternalExpirationManager<K,V>
- Overrides:
handleInStoreExpiration
in classExpirationManagerImpl<K,V>
- Parameters:
key
- the key of the expired entry
-
handleInStoreExpiration
public void handleInStoreExpiration(MarshalledEntry<K,V> marshalledEntry)
Description copied from interface:InternalExpirationManager
This is to be invoked when a store entry expires and the value and/or metadata is available to be used. This method is preferred overExpirationManager.handleInStoreExpiration(Object)
as it allows for more specific expiration to possibly occur.- Specified by:
handleInStoreExpiration
in interfaceExpirationManager<K,V>
- Specified by:
handleInStoreExpiration
in interfaceInternalExpirationManager<K,V>
- Overrides:
handleInStoreExpiration
in classExpirationManagerImpl<K,V>
- Parameters:
marshalledEntry
- the entry that can be unmarshalled as needed
-
retrieveLastAccess
public CompletableFuture<Long> retrieveLastAccess(Object key, Object value, int segment)
Description copied from interface:InternalExpirationManager
Retrieves the last access time for the given key in the data container if it is using max idle. If the entry is not in the container or it is expired it will return null. If the entry is present but cannot expire via max idle, it will return -1 If the entry is present and can expire via max idle but hasn't it will return a number > 0- Specified by:
retrieveLastAccess
in interfaceExpirationManager<K,V>
- Specified by:
retrieveLastAccess
in interfaceInternalExpirationManager<K,V>
- Overrides:
retrieveLastAccess
in classExpirationManagerImpl<K,V>
- Parameters:
key
- the key to retrieve the access time forvalue
- the value to match if desired (this can be null)segment
- the segment for the given key- Returns:
- the last access time if available
-
-