public class GridOffHeapSnapTreeMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer> extends AbstractMap<K,V> implements ConcurrentNavigableMap<K,V>, Cloneable, AutoCloseable, GridReservable
This data structure honors all of the contracts of ConcurrentSkipListMap, with the additional contract
that clone, size, toArray, and iteration are linearizable (atomic).
The tree uses optimistic concurrency control. No locks are usually required for get, containsKey, firstKey, firstEntry, lastKey, or lastEntry. Reads are not lock free (or even obstruction free), but obstructing threads perform no memory allocation, system calls, or loops, which seems to work okay in practice. All of the updates to the tree are performed in fixed- size blocks, so restoration of the AVL balance criteria may occur after a change to the tree has linearized (but before the mutating operation has returned). The tree is always properly balanced when quiescent.
To clone the tree (or produce a snapshot for consistent iteration) the root node is marked as shared, which must be (*) done while there are no pending mutations. New mutating operations are blocked if a mark is pending, and when existing mutating operations are completed the mark is made. * - It would be less disruptive if we immediately marked the root as shared, and then waited for pending operations that might not have seen the mark without blocking new mutations. This could result in imbalance being frozen into the shared portion of the tree, though. To minimize the problem we perform the mark and reenable mutation on whichever thread notices that the entry count has become zero, to reduce context switches on the critical path.
The same multi-cache line data structure required for efficiently tracking the entry and exit for mutating operations is used to maintain the current size of the tree. This means that the size can be computed by quiescing as for a clone, but without doing any marking.
Range queries such as higherKey are not amenable to the optimistic hand-over-hand locking scheme used for exact searches, so they are implemented with pessimistic concurrency control. Mutation can be considered to acquire a lock on the map in Intention-eXclusive mode, range queries, size(), and root marking acquire the lock in Shared mode.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Modifier and Type | Field and Description |
|---|---|
protected GridUnsafeGuard |
guard |
protected GridUnsafeMemory |
mem |
| Constructor and Description |
|---|
GridOffHeapSnapTreeMap(GridOffHeapSmartPointerFactory keyFactory,
GridOffHeapSmartPointerFactory valFactory,
GridUnsafeMemory mem,
GridUnsafeGuard guard) |
GridOffHeapSnapTreeMap(GridOffHeapSmartPointerFactory keyFactory,
GridOffHeapSmartPointerFactory valFactory,
GridUnsafeMemory mem,
GridUnsafeGuard guard,
Comparator<? super K> comparator) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterNodeUpdate_nl(long node,
V val)
Special protected method to be overridden by extending classes.
|
Map.Entry<K,V> |
ceilingEntry(K key) |
K |
ceilingKey(K key) |
void |
clear() |
GridOffHeapSnapTreeMap<K,V> |
clone() |
void |
close()
Closes tree map and reclaims memory.
|
protected Comparable<? super K> |
comparable(Object key) |
Comparator<? super K> |
comparator() |
boolean |
containsKey(Object key) |
NavigableSet<K> |
descendingKeySet() |
ConcurrentNavigableMap<K,V> |
descendingMap() |
Set<Map.Entry<K,V>> |
entrySet() |
Map.Entry<K,V> |
firstEntry() |
K |
firstKey() |
Map.Entry<K,V> |
floorEntry(K key) |
K |
floorKey(K key) |
V |
get(Object key) |
ConcurrentNavigableMap<K,V> |
headMap(K toKey) |
ConcurrentNavigableMap<K,V> |
headMap(K toKey,
boolean inclusive) |
Map.Entry<K,V> |
higherEntry(K key) |
K |
higherKey(K key) |
boolean |
isEmpty() |
protected void |
key(long ptr,
K key) |
protected long |
keyPtr(long node) |
NavigableSet<K> |
keySet() |
Map.Entry<K,V> |
lastEntry() |
K |
lastKey() |
Map.Entry<K,V> |
lowerEntry(K key) |
K |
lowerKey(K key) |
NavigableSet<K> |
navigableKeySet() |
Map.Entry<K,V> |
pollFirstEntry() |
Map.Entry<K,V> |
pollLastEntry() |
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value) |
void |
release()
Releases.
|
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
V |
replace(K key,
V value) |
boolean |
replace(K key,
V oldValue,
V newValue) |
boolean |
reserve()
Reserves.
|
protected void |
right(long ptr,
long nodePtr) |
int |
size() |
ConcurrentNavigableMap<K,V> |
subMap(K fromKey,
boolean fromInclusive,
K toKey,
boolean toInclusive) |
ConcurrentNavigableMap<K,V> |
subMap(K fromKey,
K toKey) |
ConcurrentNavigableMap<K,V> |
tailMap(K fromKey) |
ConcurrentNavigableMap<K,V> |
tailMap(K fromKey,
boolean inclusive) |
containsValue, equals, hashCode, putAll, toString, valuesfinalize, getClass, notify, notifyAll, wait, wait, waitcontainsValue, equals, hashCode, putAllprotected final GridUnsafeMemory mem
protected final GridUnsafeGuard guard
public GridOffHeapSnapTreeMap(GridOffHeapSmartPointerFactory keyFactory, GridOffHeapSmartPointerFactory valFactory, GridUnsafeMemory mem, GridUnsafeGuard guard)
keyFactory - Key factory.valFactory - Value factory.mem - Unsafe memory.guard - Guard.public GridOffHeapSnapTreeMap(GridOffHeapSmartPointerFactory keyFactory, GridOffHeapSmartPointerFactory valFactory, GridUnsafeMemory mem, GridUnsafeGuard guard, Comparator<? super K> comparator)
keyFactory - Key factory.valFactory - Value factory.mem - Unsafe memory.guard - Guard.comparator - Comparator.protected long keyPtr(long node)
node - Node.protected void right(long ptr,
long nodePtr)
ptr - Node pointer.nodePtr - Right child's pointer.protected void key(long ptr,
K key)
ptr - Node pointer.key - Key.public boolean reserve()
reserve in interface GridReservabletrue If reserved successfully.public void release()
release in interface GridReservablepublic void close()
close in interface AutoCloseablepublic GridOffHeapSnapTreeMap<K,V> clone()
clone in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public int size()
size in interface Map<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>size in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public boolean isEmpty()
isEmpty in interface Map<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>isEmpty in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public void clear()
clear in interface Map<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>clear in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public Comparator<? super K> comparator()
comparator in interface SortedMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public boolean containsKey(Object key)
containsKey in interface Map<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>containsKey in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public V get(Object key)
get in interface Map<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>get in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>protected Comparable<? super K> comparable(Object key)
key - Key.public K firstKey()
firstKey in interface SortedMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public Map.Entry<K,V> firstEntry()
firstEntry in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public K lastKey()
lastKey in interface SortedMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public Map.Entry<K,V> lastEntry()
lastEntry in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public K lowerKey(K key)
lowerKey in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public K floorKey(K key)
floorKey in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public K ceilingKey(K key)
ceilingKey in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public K higherKey(K key)
higherKey in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public Map.Entry<K,V> lowerEntry(K key)
lowerEntry in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public Map.Entry<K,V> floorEntry(K key)
floorEntry in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public Map.Entry<K,V> ceilingEntry(K key)
ceilingEntry in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public Map.Entry<K,V> higherEntry(K key)
higherEntry in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public V put(K key, V value)
put in interface Map<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>put in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public V putIfAbsent(K key, V value)
putIfAbsent in interface ConcurrentMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public V replace(K key, V value)
replace in interface ConcurrentMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public boolean replace(K key, V oldValue, V newValue)
replace in interface ConcurrentMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public V remove(Object key)
remove in interface Map<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>remove in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public boolean remove(Object key, Object value)
remove in interface ConcurrentMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>protected void afterNodeUpdate_nl(long node,
V val)
node - Node pointer.val - Value.public Map.Entry<K,V> pollFirstEntry()
pollFirstEntry in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public Map.Entry<K,V> pollLastEntry()
pollLastEntry in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public NavigableSet<K> keySet()
keySet in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>keySet in interface Map<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>keySet in interface SortedMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>keySet in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public Set<Map.Entry<K,V>> entrySet()
entrySet in interface Map<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>entrySet in interface SortedMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>entrySet in class AbstractMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public NavigableSet<K> navigableKeySet()
navigableKeySet in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>navigableKeySet in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public NavigableSet<K> descendingKeySet()
descendingKeySet in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>descendingKeySet in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public ConcurrentNavigableMap<K,V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
subMap in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>subMap in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public ConcurrentNavigableMap<K,V> headMap(K toKey, boolean inclusive)
headMap in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>headMap in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public ConcurrentNavigableMap<K,V> tailMap(K fromKey, boolean inclusive)
tailMap in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>tailMap in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public ConcurrentNavigableMap<K,V> subMap(K fromKey, K toKey)
subMap in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>subMap in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>subMap in interface SortedMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public ConcurrentNavigableMap<K,V> headMap(K toKey)
headMap in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>headMap in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>headMap in interface SortedMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public ConcurrentNavigableMap<K,V> tailMap(K fromKey)
tailMap in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>tailMap in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>tailMap in interface SortedMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>public ConcurrentNavigableMap<K,V> descendingMap()
descendingMap in interface ConcurrentNavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>descendingMap in interface NavigableMap<K extends GridOffHeapSmartPointer,V extends GridOffHeapSmartPointer>
Follow @ApacheIgnite
Ignite Fabric : ver. 1.9.0 Release Date : March 2 2017