Class GridUnsafePartitionedMap
- java.lang.Object
-
- org.apache.ignite.internal.util.offheap.unsafe.GridUnsafePartitionedMap
-
- All Implemented Interfaces:
GridOffHeapPartitionedMap
public class GridUnsafePartitionedMap extends Object implements GridOffHeapPartitionedMap
Off-heap map based onUnsafeimplementation.
-
-
Constructor Summary
Constructors Constructor Description GridUnsafePartitionedMap(int parts, int concurrency, float load, long initCap, long totalMem, short lruStripes, @Nullable GridOffHeapEvictListener evictLsnr)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longallocatedSize()Gets size of a memory allocated for map entries so far.intconcurrency()Gets concurrency level for this map.booleancontains(int part, int hash, byte[] keyBytes)Checks if given key is contained in the map.voiddestruct()Destructs this map and deallocates all memory.voidenableEviction(int p, int hash, byte[] keyBytes)Enables eviction for entry.booleaneventListener(GridOffHeapEventListener evtLsnr)Adds off-heap event listener.booleanevictListener(GridOffHeapEvictListener evictLsnr)Sets callback for when entries are evicted due to memory constraints.longfreeSize()Gets available memory.byte[]get(int p, int hash, byte[] keyBytes)Gets value bytes for given key.voidinsert(int p, int hash, byte[] keyBytes, byte[] valBytes)Inserts new entry into the map without comparing if there is a mapping for given key already stored in map.GridCloseableIterator<IgniteBiTuple<byte[],byte[]>>iterator()Gets iterator over the whole map.GridCloseableIterator<IgniteBiTuple<byte[],byte[]>>iterator(int p)Gets iterator over certain partition.<T> GridCloseableIterator<T>iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c)Gets iterator over the whole map.<T> GridCloseableIterator<T>iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c, int part)Gets iterator over the partition.floatloadFactor()Gets load factor of this map.longlruMemorySize()Gets memory size occupied by LRU queue.longlruSize()Gets number of elements in LRU queue.shortlruStripes()Gets number of LRU stripes.longmemorySize()Gets total available memory size.intpartitions()Gets number of partitions.booleanput(int p, int hash, byte[] keyBytes, byte[] valBytes)Puts key and value bytes into the map potentially replacing existing entry.byte[]remove(int p, int hash, byte[] keyBytes)Removes value from off-heap map.booleanremovex(int p, int hash, byte[] keyBytes)Removes value from off-heap map without returning it.booleanremovex(int part, int hash, byte[] keyBytes, IgniteBiPredicate<Long,Integer> p)Removes value from off-heap map without returning it.longsize()Gets number of elements in the map.longsize(Set<Integer> parts)Gets number of elements in the map.longsystemAllocatedSize()Gets memory allocated for map internal structure so far.IgniteBiTuple<Long,Integer>valuePointer(int p, int hash, byte[] keyBytes)Gets value pointer for given key.
-
-
-
Constructor Detail
-
GridUnsafePartitionedMap
public GridUnsafePartitionedMap(int parts, int concurrency, float load, long initCap, long totalMem, short lruStripes, @Nullable @Nullable GridOffHeapEvictListener evictLsnr)- Parameters:
parts- Partitions.concurrency- Concurrency.load- Load factor.initCap- Initial capacity.totalMem- Total memory.lruStripes- LRU stripes.evictLsnr- Eviction callback.
-
-
Method Detail
-
loadFactor
public float loadFactor()
Gets load factor of this map.- Specified by:
loadFactorin interfaceGridOffHeapPartitionedMap- Returns:
- Load factor.
-
concurrency
public int concurrency()
Gets concurrency level for this map.- Specified by:
concurrencyin interfaceGridOffHeapPartitionedMap- Returns:
- Concurrency level.
-
partitions
public int partitions()
Gets number of partitions.- Specified by:
partitionsin interfaceGridOffHeapPartitionedMap- Returns:
- Number of partitions.
-
contains
public boolean contains(int part, int hash, byte[] keyBytes)Checks if given key is contained in the map.- Specified by:
containsin interfaceGridOffHeapPartitionedMap- Parameters:
part- Partition.hash- Hash.keyBytes- Key bytes.- Returns:
Trueif key is contained in the map.
-
get
public byte[] get(int p, int hash, byte[] keyBytes)Gets value bytes for given key.- Specified by:
getin interfaceGridOffHeapPartitionedMap- Parameters:
p- Partition.hash- Hash.keyBytes- Key bytes.- Returns:
- Value bytes.
-
valuePointer
public IgniteBiTuple<Long,Integer> valuePointer(int p, int hash, byte[] keyBytes)
Gets value pointer for given key. While pointer is in use eviction is disabled for corresponding entry. Eviction for entry is enabled whenGridOffHeapPartitionedMap.put(int, int, byte[], byte[])orGridOffHeapPartitionedMap.enableEviction(int, int, byte[])is called.- Specified by:
valuePointerin interfaceGridOffHeapPartitionedMap- Parameters:
p- Partition.hash- Hash.keyBytes- Key bytes.- Returns:
- Value pointer.
-
enableEviction
public void enableEviction(int p, int hash, byte[] keyBytes)Enables eviction for entry.- Specified by:
enableEvictionin interfaceGridOffHeapPartitionedMap- Parameters:
p- Partition.hash- Hash.keyBytes- Key bytes.
-
remove
public byte[] remove(int p, int hash, byte[] keyBytes)Removes value from off-heap map.- Specified by:
removein interfaceGridOffHeapPartitionedMap- Parameters:
p- Partition.hash- Hash.keyBytes- Key bytes.- Returns:
- Removed value bytes.
-
removex
public boolean removex(int p, int hash, byte[] keyBytes)Removes value from off-heap map without returning it.- Specified by:
removexin interfaceGridOffHeapPartitionedMap- Parameters:
p- Partition.hash- Hash.keyBytes- Key bytes.- Returns:
Trueif value was removed.
-
removex
public boolean removex(int part, int hash, byte[] keyBytes, IgniteBiPredicate<Long,Integer> p)Removes value from off-heap map without returning it.- Specified by:
removexin interfaceGridOffHeapPartitionedMap- Parameters:
part- Partition.hash- Hash.keyBytes- Key bytes.p- Value predicate (arguments are value address and value length).- Returns:
Trueif value was removed.
-
put
public boolean put(int p, int hash, byte[] keyBytes, byte[] valBytes)Puts key and value bytes into the map potentially replacing existing entry.- Specified by:
putin interfaceGridOffHeapPartitionedMap- Parameters:
p- Partition.hash- Hash.keyBytes- Key bytes.valBytes- Value bytes.- Returns:
Trueif new entry was created,falseif existing value was updated.
-
insert
public void insert(int p, int hash, byte[] keyBytes, byte[] valBytes)Inserts new entry into the map without comparing if there is a mapping for given key already stored in map.Use with caution whenever certain that inserting a new value without current mapping.
- Specified by:
insertin interfaceGridOffHeapPartitionedMap- Parameters:
p- Partition.hash- Hash.keyBytes- Key bytes.valBytes- Value bytes.
-
size
public long size()
Gets number of elements in the map.- Specified by:
sizein interfaceGridOffHeapPartitionedMap- Returns:
- Number of elements in the map.
-
size
public long size(Set<Integer> parts)
Gets number of elements in the map.- Specified by:
sizein interfaceGridOffHeapPartitionedMap- Parameters:
parts- Partitions.- Returns:
- Number of elements in the map.
-
memorySize
public long memorySize()
Gets total available memory size.- Specified by:
memorySizein interfaceGridOffHeapPartitionedMap- Returns:
- Memory size.
-
allocatedSize
public long allocatedSize()
Gets size of a memory allocated for map entries so far.- Specified by:
allocatedSizein interfaceGridOffHeapPartitionedMap- Returns:
- Allocated memory size.
-
systemAllocatedSize
public long systemAllocatedSize()
Gets memory allocated for map internal structure so far.- Specified by:
systemAllocatedSizein interfaceGridOffHeapPartitionedMap- Returns:
- Allocated memory.
-
freeSize
public long freeSize()
Gets available memory.- Specified by:
freeSizein interfaceGridOffHeapPartitionedMap- Returns:
- Available memory.
-
eventListener
public boolean eventListener(GridOffHeapEventListener evtLsnr)
Adds off-heap event listener.- Specified by:
eventListenerin interfaceGridOffHeapPartitionedMap- Parameters:
evtLsnr- Listener.- Returns:
Trueif event listener was added,falseif another listener already exists.
-
evictListener
public boolean evictListener(GridOffHeapEvictListener evictLsnr)
Sets callback for when entries are evicted due to memory constraints. The parameter into closure is key bytes.- Specified by:
evictListenerin interfaceGridOffHeapPartitionedMap- Parameters:
evictLsnr- Evict listener.- Returns:
Trueif evict listener was added,falseif another listener already exists orLRUis disabled.
-
destruct
public void destruct()
Destructs this map and deallocates all memory.- Specified by:
destructin interfaceGridOffHeapPartitionedMap
-
iterator
public GridCloseableIterator<IgniteBiTuple<byte[],byte[]>> iterator()
Gets iterator over the whole map.- Specified by:
iteratorin interfaceGridOffHeapPartitionedMap- Returns:
- Iterator over the whole map.
-
iterator
public <T> GridCloseableIterator<T> iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c)
Gets iterator over the whole map.- Specified by:
iteratorin interfaceGridOffHeapPartitionedMap- Parameters:
c- Key/value closure.- Returns:
- Iterator over the whole map.
-
iterator
public <T> GridCloseableIterator<T> iterator(CX2<T2<Long,Integer>,T2<Long,Integer>,T> c, int part)
Gets iterator over the partition.- Specified by:
iteratorin interfaceGridOffHeapPartitionedMap- Parameters:
c- Key/value closure.part- Partition.- Returns:
- Iterator over the partition.
-
iterator
public GridCloseableIterator<IgniteBiTuple<byte[],byte[]>> iterator(int p)
Gets iterator over certain partition.- Specified by:
iteratorin interfaceGridOffHeapPartitionedMap- Parameters:
p- Partition.- Returns:
- Iterator over certain partition.
-
lruStripes
public short lruStripes()
Gets number of LRU stripes.- Returns:
- Number of LRU stripes.
-
lruMemorySize
public long lruMemorySize()
Gets memory size occupied by LRU queue.- Returns:
- Memory size occupied by LRU queue.
-
lruSize
public long lruSize()
Gets number of elements in LRU queue.- Returns:
- Number of elements in LRU queue.
-
-