Class ForStDBCachingPriorityQueueSet<E extends HeapPriorityQueueElement>
- java.lang.Object
-
- org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueueElement
-
- org.apache.flink.state.forst.sync.ForStDBCachingPriorityQueueSet<E>
-
- Type Parameters:
E
- the type of the contained elements in the queue.
- All Implemented Interfaces:
HeapPriorityQueueElement
,InternalPriorityQueue<E>
public class ForStDBCachingPriorityQueueSet<E extends HeapPriorityQueueElement> extends AbstractHeapPriorityQueueElement implements InternalPriorityQueue<E>
A priority queue with set semantics, implemented on top of RocksDB. This uses aTreeSet
to cache the bytes of up to the first n elements from RocksDB in memory to reduce interaction with RocksDB, in particular seek operations. Cache uses a simple write-through policy.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ForStDBCachingPriorityQueueSet.OrderedByteArraySetCache
Cache that is organized as an ordered set for byte-arrays.
-
Field Summary
-
Fields inherited from interface org.apache.flink.runtime.state.heap.HeapPriorityQueueElement
NOT_CONTAINED
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E toAdd)
Adds the given element to the set, if it is not already contained.void
addAll(Collection<? extends E> toAdd)
Adds all the given elements to the set.boolean
isEmpty()
Check if the set contains any elements.CloseableIterator<E>
iterator()
Iterator over all elements, no order guaranteed.E
peek()
Retrieves, but does not remove, the element (w.r.t. order) of this set, or returnsnull
if this set is empty.E
poll()
Retrieves and removes the first element (w.r.t. the order) of this set, or returnsnull
if this set is empty.boolean
remove(E toRemove)
Removes the given element from the set, if is contained in the set.int
size()
This implementation comes at a relatively high cost per invocation.-
Methods inherited from class org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueueElement
getInternalIndex, setInternalIndex
-
-
-
-
Method Detail
-
peek
@Nullable public E peek()
Description copied from interface:InternalPriorityQueue
Retrieves, but does not remove, the element (w.r.t. order) of this set, or returnsnull
if this set is empty.- Specified by:
peek
in interfaceInternalPriorityQueue<E extends HeapPriorityQueueElement>
- Returns:
- the first element (w.r.t. order) of this ordered set, or
null
if this set is empty.
-
poll
@Nullable public E poll()
Description copied from interface:InternalPriorityQueue
Retrieves and removes the first element (w.r.t. the order) of this set, or returnsnull
if this set is empty.NOTE: Correct key (i.e. the key of the polled element) must be set on KeyContext before calling this method.
- Specified by:
poll
in interfaceInternalPriorityQueue<E extends HeapPriorityQueueElement>
- Returns:
- the first element of this ordered set, or
null
if this set is empty.
-
add
public boolean add(@Nonnull E toAdd)
Description copied from interface:InternalPriorityQueue
Adds the given element to the set, if it is not already contained.- Specified by:
add
in interfaceInternalPriorityQueue<E extends HeapPriorityQueueElement>
- Parameters:
toAdd
- the element to add to the set.- Returns:
true
if the operation changed the head element or if it is unclear if the head element changed. Only returnsfalse
if the head element was not changed by this operation.
-
remove
public boolean remove(@Nonnull E toRemove)
Description copied from interface:InternalPriorityQueue
Removes the given element from the set, if is contained in the set.NOTE: Correct key (i.e. the key of the polled element) must be set on KeyContext before calling this method.
- Specified by:
remove
in interfaceInternalPriorityQueue<E extends HeapPriorityQueueElement>
- Parameters:
toRemove
- the element to remove.- Returns:
true
if the operation changed the head element or if it is unclear if the head element changed. Only returnsfalse
if the head element was not changed by this operation.
-
addAll
public void addAll(@Nullable Collection<? extends E> toAdd)
Description copied from interface:InternalPriorityQueue
Adds all the given elements to the set.- Specified by:
addAll
in interfaceInternalPriorityQueue<E extends HeapPriorityQueueElement>
-
isEmpty
public boolean isEmpty()
Description copied from interface:InternalPriorityQueue
Check if the set contains any elements.- Specified by:
isEmpty
in interfaceInternalPriorityQueue<E extends HeapPriorityQueueElement>
- Returns:
- true if the set is empty, i.e. no element is contained.
-
iterator
@Nonnull public CloseableIterator<E> iterator()
Description copied from interface:InternalPriorityQueue
Iterator over all elements, no order guaranteed. Iterator must be closed after usage.- Specified by:
iterator
in interfaceInternalPriorityQueue<E extends HeapPriorityQueueElement>
-
size
public int size()
This implementation comes at a relatively high cost per invocation. It should not be called repeatedly when it is clear that the value did not change. Currently this is only truly used to realize certain higher-level tests.- Specified by:
size
in interfaceInternalPriorityQueue<E extends HeapPriorityQueueElement>
- Returns:
- the number of elements in this set.
-
-