Package org.infinispan.container.offheap
Class OffHeapDataContainer
- java.lang.Object
-
- org.infinispan.container.offheap.OffHeapDataContainer
-
- All Implemented Interfaces:
Iterable<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>>
,DataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Direct Known Subclasses:
BoundedOffHeapDataContainer
public class OffHeapDataContainer extends Object implements DataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
Data Container implementation that stores entries in native memory (off-heap).- Since:
- 9.0
- Author:
- wburns
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.container.DataContainer
DataContainer.ComputeAction<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description protected ActivationManager
activator
protected OffHeapMemoryAllocator
allocator
protected EvictionManager
evictionManager
protected InternalEntryFactory
internalEntryFactory
protected int
lockCount
protected StripedLock
locks
protected int
memoryAddressCount
protected MemoryAddressHash
memoryLookup
protected OffHeapEntryFactory
offHeapEntryFactory
protected PassivationManager
passivator
protected AtomicLong
size
protected TimeService
timeService
protected boolean
trace
-
Constructor Summary
Constructors Constructor Description OffHeapDataContainer(int desiredSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkDeallocation()
void
clear()
Removes all entries in the containerInternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
compute(org.infinispan.commons.marshall.WrappedBytes key, DataContainer.ComputeAction<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> action)
Computes the new value for the key.boolean
containsKey(Object k)
Tests whether an entry exists in the containerprotected void
entryCreated(long newAddress)
Invoked when an entry is about to be created.protected void
entryRemoved(long removedAddress)
Invoked when an entry is about to be removed.protected void
entryReplaced(long newAddress, long oldAddress)
Invoked when an entry is about to be replaced with a new one.protected void
entryRetrieved(long entryAddress)
Invoked when an entry is successfully retrieved.Set<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>>
entrySet()
Returns a mutable set of immutable cache entries exposed as immutable Map.Entry instances.void
evict(org.infinispan.commons.marshall.WrappedBytes key)
Atomically, it removes the key fromDataContainer
and passivates it to persistence.long
evictionSize()
Returns how large the eviction size is currently.void
executeTask(KeyFilter<? super org.infinispan.commons.marshall.WrappedBytes> filter, BiConsumer<? super org.infinispan.commons.marshall.WrappedBytes,InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> action)
Executes task specified by the given action on the container key/values filtered using the specified key filter.void
executeTask(KeyValueFilter<? super org.infinispan.commons.marshall.WrappedBytes,? super org.infinispan.commons.marshall.WrappedBytes> filter, BiConsumer<? super org.infinispan.commons.marshall.WrappedBytes,InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> action)
Executes task specified by the given action on the container key/values filtered using the specified keyvalue filter.InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
get(Object k)
Retrieves a cached entrystatic int
getActualAddressCount(int desiredSize)
Log
getLog()
Iterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>>
iterator()
Iterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>>
iteratorIncludingExpired()
Same asDataContainer.iterator()
except that is also returns expired entries.Set<org.infinispan.commons.marshall.WrappedBytes>
keySet()
Returns a set of keys in the container.InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
peek(Object k)
Retrieves a cache entry in the same way asDataContainer.get(Object)
} except that it does not update or reorder any of the internal constructs.protected void
performClear()
protected long
performGet(long bucketHeadAddress, Object k, boolean returnExpired)
Gets the actual address for the given key in the given bucket or 0 if it isn't present or expiredprotected boolean
performPut(long bucketHeadAddress, long actualAddress, long newAddress, org.infinispan.commons.marshall.WrappedBytes key)
Performs the actual put operation putting the new address into the memory lookups.protected InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
performRemove(long bucketHeadAddress, long actualAddress, Object key, boolean requireReturn)
Performs the actual remove operation removing the new address from the memory lookups.void
put(org.infinispan.commons.marshall.WrappedBytes key, org.infinispan.commons.marshall.WrappedBytes value, Metadata metadata)
Puts an entry in the cache along with metadata adding information such lifespan of entry, max idle time, version information...etc.InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
remove(Object key)
Removes an entry from the cacheint
size()
int
sizeIncludingExpired()
void
start()
void
stop()
Clears the memory lookups and cache data.Collection<org.infinispan.commons.marshall.WrappedBytes>
values()
This returns all values in the container including expired entries.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.container.DataContainer
capacity, resize, spliterator, spliteratorIncludingExpired
-
-
-
-
Field Detail
-
trace
protected final boolean trace
-
size
protected final AtomicLong size
-
lockCount
protected final int lockCount
-
memoryAddressCount
protected final int memoryAddressCount
-
locks
protected final StripedLock locks
-
allocator
protected OffHeapMemoryAllocator allocator
-
offHeapEntryFactory
protected OffHeapEntryFactory offHeapEntryFactory
-
internalEntryFactory
protected InternalEntryFactory internalEntryFactory
-
timeService
protected TimeService timeService
-
evictionManager
protected EvictionManager evictionManager
-
activator
protected ActivationManager activator
-
passivator
protected PassivationManager passivator
-
memoryLookup
protected MemoryAddressHash memoryLookup
-
-
Method Detail
-
getActualAddressCount
public static int getActualAddressCount(int desiredSize)
-
start
public void start()
-
stop
public void stop()
Clears the memory lookups and cache data.
-
checkDeallocation
protected void checkDeallocation()
-
get
public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> get(Object k)
Description copied from interface:DataContainer
Retrieves a cached entry- Specified by:
get
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Parameters:
k
- key under which entry is stored- Returns:
- entry, if it exists and has not expired, or null if not
-
peek
public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> peek(Object k)
Description copied from interface:DataContainer
Retrieves a cache entry in the same way asDataContainer.get(Object)
} except that it does not update or reorder any of the internal constructs. I.e., expiration does not happen, and in the case of the LRU container, the entry is not moved to the end of the chain. This method should be used instead ofDataContainer.get(Object)
} when called while iterating through the data container using methods likeDataContainer.iterator()
to avoid changing the underlying collection's order.- Specified by:
peek
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Parameters:
k
- key under which entry is stored- Returns:
- entry, if it exists, or null if not
-
performGet
protected long performGet(long bucketHeadAddress, Object k, boolean returnExpired)
Gets the actual address for the given key in the given bucket or 0 if it isn't present or expired- Parameters:
bucketHeadAddress
- the starting address of the address hashk
- the key to retrieve the address for it if matches- Returns:
- the address matching the key or 0
-
put
public void put(org.infinispan.commons.marshall.WrappedBytes key, org.infinispan.commons.marshall.WrappedBytes value, Metadata metadata)
Description copied from interface:DataContainer
Puts an entry in the cache along with metadata adding information such lifespan of entry, max idle time, version information...etc. Thekey
must be activate by invokingActivationManager.onUpdate(Object, boolean)
.- Specified by:
put
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Parameters:
key
- key under which to store entryvalue
- value to storemetadata
- metadata of the entry
-
performPut
protected boolean performPut(long bucketHeadAddress, long actualAddress, long newAddress, org.infinispan.commons.marshall.WrappedBytes key)
Performs the actual put operation putting the new address into the memory lookups. The write lock for the given key must be held before calling this method.- Parameters:
bucketHeadAddress
- the entry address of the first element in the lookupactualAddress
- the actual address if it is known or 0. By passing this != 0 equality checks can be bypassed. If a value of 0 is provided this will use key equality.newAddress
- the address of the new entrykey
- the key of the entry- Returns:
true
if the entry doesn't exists in memory and was newly create,false
otherwise
-
entryCreated
protected void entryCreated(long newAddress)
Invoked when an entry is about to be created. The new address is fully addressable, The write lock will already be acquired for the given segment the key mapped to.- Parameters:
newAddress
- the address just created that will be the new entry
-
entryReplaced
protected void entryReplaced(long newAddress, long oldAddress)
Invoked when an entry is about to be replaced with a new one. The old and new address are both addressable, however oldAddress may be freed after this method returns. The write lock will already be acquired for the given segment the key mapped to.- Parameters:
newAddress
- the address just created that will be the new entryoldAddress
- the old address for this entry that will be soon removed
-
entryRemoved
protected void entryRemoved(long removedAddress)
Invoked when an entry is about to be removed. You can read values from this but after this method is completed this memory address may be freed. The write lock will already be acquired for the given segment the key mapped to.- Parameters:
removedAddress
- the address about to be removed
-
containsKey
public boolean containsKey(Object k)
Description copied from interface:DataContainer
Tests whether an entry exists in the container- Specified by:
containsKey
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Parameters:
k
- key to test- Returns:
- true if entry exists and has not expired; false otherwise
-
entryRetrieved
protected void entryRetrieved(long entryAddress)
Invoked when an entry is successfully retrieved. The read lock will already be acquired for the given segment the key mapped to.- Parameters:
entryAddress
-
-
remove
public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> remove(Object key)
Description copied from interface:DataContainer
Removes an entry from the cache Thekey
must be activate by invokingActivationManager.onRemove(Object, boolean)
.- Specified by:
remove
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Parameters:
key
- key to remove- Returns:
- entry removed, or null if it didn't exist or had expired
-
performRemove
protected InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> performRemove(long bucketHeadAddress, long actualAddress, Object key, boolean requireReturn)
Performs the actual remove operation removing the new address from the memory lookups. The write lock for the given key must be held before calling this method.- Parameters:
bucketHeadAddress
- the starting address of the address hashactualAddress
- the actual address if it is known or 0. By passing this != 0 equality checks can be bypassed. If a value of 0 is provided this will use key equality.key
- the key of the entryrequireReturn
- whether this method is forced to return the entry removed (optimizations can be done if the entry is not needed)
-
size
public int size()
- Specified by:
size
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Returns:
- count of the number of entries in the container excluding expired entries
-
sizeIncludingExpired
public int sizeIncludingExpired()
- Specified by:
sizeIncludingExpired
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Returns:
- count of the number of entries in the container including expired entries
-
clear
public void clear()
Description copied from interface:DataContainer
Removes all entries in the container- Specified by:
clear
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
-
performClear
protected void performClear()
-
keySet
public Set<org.infinispan.commons.marshall.WrappedBytes> keySet()
Description copied from interface:DataContainer
Returns a set of keys in the container. When iterating through the container using this method, clients should never callDataContainer.get(Object)
method but insteadDataContainer.peek(Object)
, in order to avoid changing the order of the underlying collection as a side of effect of iterating through it.This set of keys will include expired entries. If you wish to only retrieve non expired keys please use the
DataContainer.iterator()
method and retrieve keys from there.- Specified by:
keySet
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Returns:
- a set of keys
-
values
public Collection<org.infinispan.commons.marshall.WrappedBytes> values()
Description copied from interface:DataContainer
This returns all values in the container including expired entries. If you wish to only receive values that are not expired it is recommended to useDataContainer.entrySet()
and pull values from there directly.- Specified by:
values
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Returns:
- a set of values contained in the container
-
entrySet
public Set<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> entrySet()
Description copied from interface:DataContainer
Returns a mutable set of immutable cache entries exposed as immutable Map.Entry instances. Clients of this method such as Cache.entrySet() operation implementors are free to convert the set into an immutable set if needed, which is the most common use case. If a client needs to iterate through a mutable set of mutable cache entries, it should iterate the container itself rather than iterating through the return of entrySet().This set is a read only backed view of the entries underneath. This set will only show non expired entries when invoked. The size method of the set will count expired entries for the purpose of having a O(1) time cost compared to O(N) if it is to not count expired entries.
- Specified by:
entrySet
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Returns:
- a set of immutable cache entries
-
evict
public void evict(org.infinispan.commons.marshall.WrappedBytes key)
Description copied from interface:DataContainer
Atomically, it removes the key fromDataContainer
and passivates it to persistence. The passivation must be done by invoking the methodPassivationManager.passivate(org.infinispan.container.entries.InternalCacheEntry)
.- Specified by:
evict
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Parameters:
key
- The key to evict.
-
compute
public InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> compute(org.infinispan.commons.marshall.WrappedBytes key, DataContainer.ComputeAction<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes> action)
Description copied from interface:DataContainer
Computes the new value for the key. SeeDataContainer.ComputeAction.compute(Object, org.infinispan.container.entries.InternalCacheEntry, InternalEntryFactory)
. Thekey
must be activate by invokingActivationManager.onRemove(Object, boolean)
orActivationManager.onUpdate(Object, boolean)
depending if the value returned by theDataContainer.ComputeAction
is null or not respectively.Note the entry provided to
DataContainer.ComputeAction
may be expired as these entries are not filtered as many other methods do.- Specified by:
compute
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Parameters:
key
- The key.action
- The action that will compute the new value.- Returns:
- The
InternalCacheEntry
associated to the key.
-
executeTask
public void executeTask(KeyFilter<? super org.infinispan.commons.marshall.WrappedBytes> filter, BiConsumer<? super org.infinispan.commons.marshall.WrappedBytes,InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> action) throws InterruptedException
Description copied from interface:DataContainer
Executes task specified by the given action on the container key/values filtered using the specified key filter.- Specified by:
executeTask
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Parameters:
filter
- the filter for the container keysaction
- the specified action to execute on filtered key/values- Throws:
InterruptedException
-
executeTask
public void executeTask(KeyValueFilter<? super org.infinispan.commons.marshall.WrappedBytes,? super org.infinispan.commons.marshall.WrappedBytes> filter, BiConsumer<? super org.infinispan.commons.marshall.WrappedBytes,InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> action) throws InterruptedException
Description copied from interface:DataContainer
Executes task specified by the given action on the container key/values filtered using the specified keyvalue filter.- Specified by:
executeTask
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Parameters:
filter
- the filter for the container key/valuesaction
- the specified action to execute on filtered key/values- Throws:
InterruptedException
-
iterator
public Iterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> iterator()
Description copied from interface:DataContainer
This iterator only returns entries that are not expired, however it will not remove them while doing so.
- Specified by:
iterator
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Specified by:
iterator
in interfaceIterable<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>>
- Returns:
- iterator that doesn't produce expired entries
-
iteratorIncludingExpired
public Iterator<InternalCacheEntry<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>> iteratorIncludingExpired()
Description copied from interface:DataContainer
Same asDataContainer.iterator()
except that is also returns expired entries.- Specified by:
iteratorIncludingExpired
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Returns:
- iterator that returns all entries including expired ones
-
evictionSize
public long evictionSize()
Description copied from interface:DataContainer
Returns how large the eviction size is currently. This is only supported if the container is bounded. AnUnsupportedOperationException
is thrown otherwise. This value will always be lower than the value returned fromDataContainer.capacity()
- Specified by:
evictionSize
in interfaceDataContainer<org.infinispan.commons.marshall.WrappedBytes,org.infinispan.commons.marshall.WrappedBytes>
- Returns:
- how large the counted eviction is
-
getLog
public Log getLog()
-
-