code
stringlengths
25
201k
docstring
stringlengths
19
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
51
path
stringlengths
11
314
url
stringlengths
62
377
license
stringclasses
7 values
@VisibleForTesting @Nullable S getNode(MemorySegment keySegment, int keyOffset, int keyLen) { SkipListIterateAndProcessResult result = iterateAndProcess( keySegment, keyOffset, keyLen, (pointers, isRemoved) -> { long currentNode = pointers.currentNode; return isRemoved ? null : getNodeStateHelper(currentNode); }); return result.isKeyFound ? result.state : null; }
Find the node containing the given key. @param keySegment memory segment storing the key. @param keyOffset offset of the key. @param keyLen length of the key. @return the state. Null will be returned if key does not exist.
getNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
@VisibleForTesting S putValue( MemorySegment keySegment, int keyOffset, int keyLen, byte[] value, boolean returnOldState) { SkipListIterateAndProcessResult result = iterateAndProcess( keySegment, keyOffset, keyLen, (pointers, isLogicallyRemoved) -> putValue(pointers.currentNode, value, returnOldState)); if (result.isKeyFound) { return result.state; } long prevNode = result.prevNode; long currentNode = result.currentNode; int level = getRandomIndexLevel(); levelIndexHeader.updateLevel(level); int totalMetaKeyLen = SkipListUtils.getKeyMetaLen(level) + keyLen; long node = allocateSpace(totalMetaKeyLen); int totalValueLen = SkipListUtils.getValueMetaLen() + value.length; long valuePointer = allocateSpace(totalValueLen); doWriteKey(node, level, keySegment, keyOffset, keyLen, valuePointer, currentNode); doWriteValue(valuePointer, value, stateMapVersion, node, NIL_VALUE_POINTER); helpSetNextNode(prevNode, node, 0); if (level > 0) { SkipListUtils.buildLevelIndex( node, level, keySegment, keyOffset, levelIndexHeader, spaceAllocator); } totalSize++; return null; }
Put the key into the skip list. If the key does not exist before, a new node will be created. If the key exists before, return the old state or null depending on {@code returnOldState}. @param keySegment memory segment storing the key. @param keyOffset offset of the key. @param keyLen length of the key. @param value the value. @param returnOldState whether to return old state. @return the old state. Null will be returned if key does not exist or returnOldState is false.
putValue
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private S putValue(long currentNode, byte[] value, boolean returnOldState) { int version = SkipListUtils.helpGetNodeLatestVersion(currentNode, spaceAllocator); boolean needCopyOnWrite = version < highestRequiredSnapshotVersionPlusOne; long oldValuePointer; if (needCopyOnWrite) { oldValuePointer = updateValueWithCopyOnWrite(currentNode, value); } else { oldValuePointer = updateValueWithReplace(currentNode, value); } NodeStatus oldStatus = helpSetNodeStatus(currentNode, NodeStatus.PUT); if (oldStatus == NodeStatus.REMOVE) { logicallyRemovedNodes.remove(currentNode); } S oldState = null; if (returnOldState) { oldState = helpGetState(oldValuePointer); } // for the replace, old value space need to free if (!needCopyOnWrite) { spaceAllocator.free(oldValuePointer); } return oldState; }
Update or insert the value for the given node. @param currentNode the node to put value for. @param value the value to put. @param returnOldState whether to return the old state. @return the old state if it exists and {@code returnOldState} is true, or else null.
putValue
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private S removeNode( MemorySegment keySegment, int keyOffset, int keyLen, boolean returnOldState) { SkipListIterateAndProcessResult result = iterateAndProcess( keySegment, keyOffset, keyLen, (pointers, isLogicallyRemoved) -> removeNode(pointers, isLogicallyRemoved, returnOldState)); return result.isKeyFound ? result.state : null; }
Remove the key from the skip list. The key can be removed logically or physically. Logical remove means put a null value whose size is 0. If the key exists before, the old value state will be returned. @param keySegment memory segment storing the key. @param keyOffset offset of the key. @param keyLen length of the key. @param returnOldState whether to return old state. @return the old state. Null will be returned if key does not exist or returnOldState is false.
removeNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private SkipListIterateAndProcessResult iterateAndProcess( MemorySegment keySegment, int keyOffset, int keyLen, BiFunction<SkipListNodePointers, Boolean, S> function) { int deleteCount = 0; long prevNode = findPredecessor(keySegment, keyOffset, 1); long currentNode = helpGetNextNode(prevNode, 0); long nextNode; int c; while (currentNode != NIL_NODE) { nextNode = helpGetNextNode(currentNode, 0); // Check whether the current code is already logically removed to save some comparisons // on key, // with the cost of an additional remove-then-add operation if the to-be-removed node // has the same key // with the to-be-put one. boolean isRemoved = isNodeRemoved(currentNode); if (isRemoved && highestRequiredSnapshotVersionPlusOne == 0 && deleteCount < numKeysToDeleteOneTime) { doPhysicalRemove(currentNode, prevNode, nextNode); logicallyRemovedNodes.remove(currentNode); currentNode = nextNode; deleteCount++; continue; } c = compareSegmentAndNode(keySegment, keyOffset, keyLen, currentNode); if (c < 0) { // The given key is less than the current node, break the loop break; } else if (c > 0) { // The given key is larger than the current node, continue prevNode = currentNode; currentNode = nextNode; } else { // The given key is equal to the current node, apply the function S state = function.apply( new SkipListNodePointers(prevNode, currentNode, nextNode), isRemoved); return new SkipListIterateAndProcessResult(prevNode, currentNode, true, state); } } return new SkipListIterateAndProcessResult(prevNode, currentNode, false, null); }
Iterate the skip list and perform given function. @param keySegment memory segment storing the key. @param keyOffset offset of the key. @param keyLen length of the key. @param function the function to apply when the skip list contains the given key, which accepts two parameters: an encapsulation of [previous_node, current_node, next_node] and a boolean indicating whether the node with same key has been logically removed, and returns a state. @return the iterate and processing result
iterateAndProcess
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private long findPredecessor(MemorySegment keySegment, int keyOffset, int level) { return SkipListUtils.findPredecessor( keySegment, keyOffset, level, levelIndexHeader, spaceAllocator); }
Find the predecessor node for the given key at the given level. The key is in the memory segment positioning at the given offset. @param keySegment memory segment which contains the key. @param keyOffset offset of the key in the memory segment. @param level the level. @return node id before the key at the given level.
findPredecessor
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private int compareSegmentAndNode( MemorySegment keySegment, int keyOffset, int keyLen, long targetNode) { return SkipListUtils.compareSegmentAndNode( keySegment, keyOffset, targetNode, spaceAllocator); }
Compare the first skip list key in the given memory segment with the second skip list key in the given node. @param keySegment memory segment storing the first key. @param keyOffset offset of the first key in memory segment. @param keyLen length of the first key. @param targetNode the node storing the second key. @return Returns a negative integer, zero, or a positive integer as the first key is less than, equal to, or greater than the second.
compareSegmentAndNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private int compareNamespaceAndNode( MemorySegment namespaceSegment, int namespaceOffset, int namespaceLen, long targetNode) { Node nodeStorage = getNodeSegmentAndOffset(targetNode); MemorySegment targetSegment = nodeStorage.nodeSegment; int offsetInSegment = nodeStorage.nodeOffset; int level = SkipListUtils.getLevel(targetSegment, offsetInSegment); int targetKeyOffset = offsetInSegment + SkipListUtils.getKeyDataOffset(level); return SkipListKeyComparator.compareNamespaceAndNode( namespaceSegment, namespaceOffset, namespaceLen, targetSegment, targetKeyOffset); }
Compare the first namespace in the given memory segment with the second namespace in the given node. @param namespaceSegment memory segment storing the first namespace. @param namespaceOffset offset of the first namespace in memory segment. @param namespaceLen length of the first namespace. @param targetNode the node storing the second namespace. @return Returns a negative integer, zero, or a positive integer as the first key is less than, equal to, or greater than the second.
compareNamespaceAndNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private long updateValueWithCopyOnWrite(long node, byte[] value) { // a null value indicates this is a removed node int valueSize = value == null ? 0 : value.length; int totalValueLen = SkipListUtils.getValueMetaLen() + valueSize; long valuePointer = allocateSpace(totalValueLen); Node nodeStorage = getNodeSegmentAndOffset(node); MemorySegment nodeSegment = nodeStorage.nodeSegment; int offsetInNodeSegment = nodeStorage.nodeOffset; long oldValuePointer = SkipListUtils.getValuePointer(nodeSegment, offsetInNodeSegment); doWriteValue(valuePointer, value, stateMapVersion, node, oldValuePointer); // update value pointer in node after the new value has points the older value so that // old value can be accessed concurrently SkipListUtils.putValuePointer(nodeSegment, offsetInNodeSegment, valuePointer); return oldValuePointer; }
Update the value of the node with copy-on-write mode. The old value will be linked after the new value, and can be still accessed. @param node the node to update. @param value the value. @return the old value pointer.
updateValueWithCopyOnWrite
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private long updateValueWithReplace(long node, byte[] value) { // a null value indicates this is a removed node int valueSize = value == null ? 0 : value.length; int totalValueLen = SkipListUtils.getValueMetaLen() + valueSize; long valuePointer = allocateSpace(totalValueLen); Node nodeStorage = getNodeSegmentAndOffset(node); MemorySegment nodeSegment = nodeStorage.nodeSegment; int offsetInNodeSegment = nodeStorage.nodeOffset; long oldValuePointer = SkipListUtils.getValuePointer(nodeSegment, offsetInNodeSegment); long nextValuePointer = SkipListUtils.helpGetNextValuePointer(oldValuePointer, spaceAllocator); doWriteValue(valuePointer, value, stateMapVersion, node, nextValuePointer); // update value pointer in node after the new value has points the older value so that // old value can be accessed concurrently SkipListUtils.putValuePointer(nodeSegment, offsetInNodeSegment, valuePointer); return oldValuePointer; }
Update the value of the node with replace mode. The old value will be unlinked and replaced by the new value, and can not be accessed later. Note that the space of the old value is not freed here, and the caller of this method should be responsible for the space management. @param node the node whose value will be replaced. @param value the value. @return the old value pointer.
updateValueWithReplace
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private void doPhysicalRemove(long node, long prevNode, long nextNode) { // free space used by key and level index long valuePointer = deleteNodeMeta(node, prevNode, nextNode); // free space used by value SkipListUtils.removeAllValues(valuePointer, spaceAllocator); }
Removes the node physically, and free all space used by the key and value. @param node node to remove. @param prevNode previous node at the level 0. @param nextNode next node at the level 0.
doPhysicalRemove
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private long doPhysicalRemoveAndGetValue(long node, long prevNode, long nextNode) { // free space used by key and level index long valuePointer = deleteNodeMeta(node, prevNode, nextNode); // free space used by values except for the newest-version long nextValuePointer = SkipListUtils.helpGetNextValuePointer(valuePointer, spaceAllocator); SkipListUtils.removeAllValues(nextValuePointer, spaceAllocator); return valuePointer; }
Removes the node physically, and return the newest-version value pointer. Space used by key and value will be freed here, but the space of newest-version value will not be freed, and the caller should be responsible for the free of space. @param node node to remove. @param prevNode previous node at the level 0. @param nextNode next node at the level 0. @return newest-version value pointer.
doPhysicalRemoveAndGetValue
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private long deleteNodeMeta(long node, long prevNode, long nextNode) { // set next node of prevNode at level 0 to nextNode helpSetNextNode(prevNode, nextNode, 0); // remove the level index for the node SkipListUtils.removeLevelIndex(node, spaceAllocator, levelIndexHeader); // free space used by key long valuePointer = SkipListUtils.helpGetValuePointer(node, spaceAllocator); this.spaceAllocator.free(node); // reduce total size of the skip list // note that we regard the node to be removed once its meta is deleted totalSize--; return valuePointer; }
Physically delte the meta of the node, including the node level index, the node key, and reduce the total size of the skip list. @param node node to remove. @param prevNode previous node at the level 0. @param nextNode next node at the level 0. @return value pointer of the node.
deleteNodeMeta
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private int getRandomIndexLevel() { int x = randomSeed; x ^= x << 13; x ^= x >>> 17; x ^= x << 5; randomSeed = x; // test highest and lowest bits if ((x & 0x8001) != 0) { return 0; } int level = 1; int curMax = levelIndexHeader.getLevel(); x >>>= 1; while ((x & 1) != 0) { ++level; x >>>= 1; // the level only be increased by step if (level > curMax) { break; } } return level; }
Return a random level for new node. <p>The implementation refers to the {@code randomLevel} method of JDK7's ConcurrentSkipListMap. See https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java#L899
getRandomIndexLevel
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private void doWriteKey( long node, int level, MemorySegment keySegment, int keyOffset, int keyLen, long valuePointer, long nextNode) { Node nodeStorage = getNodeSegmentAndOffset(node); MemorySegment segment = nodeStorage.nodeSegment; int offsetInSegment = nodeStorage.nodeOffset; SkipListUtils.putLevelAndNodeStatus(segment, offsetInSegment, level, NodeStatus.PUT); SkipListUtils.putKeyLen(segment, offsetInSegment, keyLen); SkipListUtils.putValuePointer(segment, offsetInSegment, valuePointer); SkipListUtils.putNextKeyPointer(segment, offsetInSegment, nextNode); SkipListUtils.putKeyData(segment, offsetInSegment, keySegment, keyOffset, keyLen, level); }
Write the meta and data for the key to the given node. @param node the node for the key to write. @param level level of this node. @param keySegment memory segment storing the key. @param keyOffset offset of key in memory segment. @param keyLen length of the key. @param valuePointer pointer to value. @param nextNode next node on level 0.
doWriteKey
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private void doWriteValue( long valuePointer, byte[] value, int version, long keyPointer, long nextValuePointer) { Node node = getNodeSegmentAndOffset(valuePointer); MemorySegment segment = node.nodeSegment; int offsetInSegment = node.nodeOffset; SkipListUtils.putValueVersion(segment, offsetInSegment, version); SkipListUtils.putKeyPointer(segment, offsetInSegment, keyPointer); SkipListUtils.putNextValuePointer(segment, offsetInSegment, nextValuePointer); SkipListUtils.putValueLen(segment, offsetInSegment, value == null ? 0 : value.length); if (value != null) { SkipListUtils.putValueData(segment, offsetInSegment, value); } }
Write the meta and data for the value to the space where the value pointer points. @param valuePointer pointer to the space where the meta and data is written. @param value data of the value. @param version version of this value. @param keyPointer pointer to the key. @param nextValuePointer pointer to the next value.
doWriteValue
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private long getFirstNodeWithNamespace( MemorySegment namespaceSegment, int namespaceOffset, int namespaceLen) { int currentLevel = levelIndexHeader.getLevel(); long prevNode = HEAD_NODE; long currentNode = helpGetNextNode(prevNode, currentLevel); int c; // find the predecessor node at level 0. for (; ; ) { if (currentNode != NIL_NODE) { c = compareNamespaceAndNode( namespaceSegment, namespaceOffset, namespaceLen, currentNode); if (c > 0) { prevNode = currentNode; currentNode = helpGetNextNode(prevNode, currentLevel); continue; } } currentLevel--; if (currentLevel < 0) { break; } currentNode = helpGetNextNode(prevNode, currentLevel); } // find the first node that has not been logically removed while (currentNode != NIL_NODE) { if (isNodeRemoved(currentNode)) { currentNode = helpGetNextNode(currentNode, 0); continue; } c = compareNamespaceAndNode( namespaceSegment, namespaceOffset, namespaceLen, currentNode); if (c == 0) { return currentNode; } if (c < 0) { break; } } return NIL_NODE; }
Find the first node with the given namespace at level 0. @param namespaceSegment memory segment storing the namespace. @param namespaceOffset offset of the namespace. @param namespaceLen length of the namespace. @return the first node with the given namespace. NIL_NODE will be returned if not exist.
getFirstNodeWithNamespace
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private void releaseAllResource() { long node = levelIndexHeader.getNextNode(0); while (node != NIL_NODE) { long nextNode = helpGetNextNode(node, 0); long valuePointer = SkipListUtils.helpGetValuePointer(node, spaceAllocator); spaceAllocator.free(node); SkipListUtils.removeAllValues(valuePointer, spaceAllocator); node = nextNode; } totalSize = 0; logicallyRemovedNodes.clear(); }
Release all resource used by the map.
releaseAllResource
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
long getValueForSnapshot(long node, int snapshotVersion) { long snapshotValuePointer = NIL_VALUE_POINTER; ValueVersionIterator versionIterator = new ValueVersionIterator(node); long valuePointer; while (versionIterator.hasNext()) { valuePointer = versionIterator.getValuePointer(); int version = versionIterator.next(); // the first value whose version is less than snapshotVersion if (version < snapshotVersion) { snapshotValuePointer = valuePointer; break; } } return snapshotValuePointer; }
Returns the value pointer used by the snapshot of the given version. @param snapshotVersion version of snapshot. @return the value pointer of the version used by the given snapshot. NIL_VALUE_POINTER will be returned if there is no value for this snapshot.
getValueForSnapshot
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
long getAndPruneValueForSnapshot(long node, int snapshotVersion) { // whether the node is being pruned by some snapshot boolean isPruning = pruningValueNodes.add(node); try { long snapshotValuePointer = NIL_VALUE_POINTER; long valuePointer; ValueVersionIterator versionIterator = new ValueVersionIterator(node); while (versionIterator.hasNext()) { valuePointer = versionIterator.getValuePointer(); int version = versionIterator.next(); // find the first value whose version is less than snapshotVersion if (snapshotValuePointer == NIL_VALUE_POINTER && version < snapshotVersion) { snapshotValuePointer = valuePointer; if (!isPruning) { break; } } // if the version of the value is no more than highestFinishedSnapshotVersion, // snapshots that is running and to be run will not use the values who are // older than this version, so these values can be safely removed. if (highestFinishedSnapshotVersion >= version) { long nextValuePointer = SkipListUtils.helpGetNextValuePointer(valuePointer, spaceAllocator); if (nextValuePointer != NIL_VALUE_POINTER) { SkipListUtils.helpSetNextValuePointer( valuePointer, NIL_VALUE_POINTER, spaceAllocator); SkipListUtils.removeAllValues(nextValuePointer, spaceAllocator); } break; } } return snapshotValuePointer; } finally { // only remove the node from the set when this snapshot has pruned values if (isPruning) { pruningValueNodes.remove(node); } } }
Returns the value pointer used by the snapshot of the given version, and useless version values will be pruned. @param snapshotVersion version of snapshot. @return the value pointer of the version used by the given snapshot. NIL_VALUE_POINTER will be returned if there is no value for this snapshot.
getAndPruneValueForSnapshot
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private S getNodeInternal(K key, N namespace) { MemorySegment keySegment = getKeySegment(key, namespace); int keyLen = keySegment.size(); return getNode(keySegment, 0, keyLen); }
Find the node containing the given key. @param key the key. @param namespace the namespace. @return id of the node. NIL_NODE will be returned if key does no exist.
getNodeInternal
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private MemorySegment getKeySegment(K key, N namespace) { return skipListKeySerializer.serializeToSegment(key, namespace); }
Get the {@link MemorySegment} wrapping up the serialized key bytes. @param key the key. @param namespace the namespace. @return the {@link MemorySegment} wrapping up the serialized key bytes.
getKeySegment
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private boolean isNodeRemoved(long node) { return SkipListUtils.isNodeRemoved(node, spaceAllocator); }
Whether the node has been logically removed.
isNodeRemoved
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private void helpSetNextNode(long node, long nextNode, int level) { SkipListUtils.helpSetNextNode(node, nextNode, level, levelIndexHeader, spaceAllocator); }
Set the next node of the given node at the given level.
helpSetNextNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
long helpGetNextNode(long node, int level) { return SkipListUtils.helpGetNextNode( node, level, this.levelIndexHeader, this.spaceAllocator); }
Return the next of the given node at the given level.
helpGetNextNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
int helpGetValueLen(long valuePointer) { return SkipListUtils.helpGetValueLen(valuePointer, spaceAllocator); }
Returns the length of the value.
helpGetValueLen
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private NodeStatus helpSetNodeStatus(long node, NodeStatus newStatus) { Node nodeStorage = getNodeSegmentAndOffset(node); MemorySegment segment = nodeStorage.nodeSegment; int offsetInSegment = nodeStorage.nodeOffset; NodeStatus oldStatus = SkipListUtils.getNodeStatus(segment, offsetInSegment); if (oldStatus != newStatus) { int level = SkipListUtils.getLevel(segment, offsetInSegment); SkipListUtils.putLevelAndNodeStatus(segment, offsetInSegment, level, newStatus); } return oldStatus; }
Set node status to the given new status, and return old status.
helpSetNodeStatus
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private S getNodeStateHelper(long node) { Node nodeStorage = getNodeSegmentAndOffset(node); MemorySegment segment = nodeStorage.nodeSegment; int offsetInSegment = nodeStorage.nodeOffset; long valuePointer = SkipListUtils.getValuePointer(segment, offsetInSegment); return helpGetState(valuePointer); }
Return the state of the node. null will be returned if the node is removed.
getNodeStateHelper
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
Tuple2<byte[], byte[]> helpGetBytesForKeyAndNamespace(long node) { Node nodeStorage = getNodeSegmentAndOffset(node); MemorySegment segment = nodeStorage.nodeSegment; int offsetInSegment = nodeStorage.nodeOffset; int level = SkipListUtils.getLevel(segment, offsetInSegment); int keyDataOffset = offsetInSegment + SkipListUtils.getKeyDataOffset(level); return skipListKeySerializer.getSerializedKeyAndNamespace(segment, keyDataOffset); }
Returns the byte arrays of serialized key and namespace. @param node the node. @return a tuple of byte arrays of serialized key and namespace
helpGetBytesForKeyAndNamespace
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
byte[] helpGetBytesForState(long valuePointer) { Node node = getNodeSegmentAndOffset(valuePointer); MemorySegment segment = node.nodeSegment; int offsetInSegment = node.nodeOffset; int valueLen = SkipListUtils.getValueLen(segment, offsetInSegment); MemorySegment valueSegment = MemorySegmentFactory.allocateUnpooledSegment(valueLen); segment.copyTo( offsetInSegment + SkipListUtils.getValueMetaLen(), valueSegment, 0, valueLen); return valueSegment.getArray(); }
Returns the byte array of serialized state. @param valuePointer pointer to value. @return byte array of serialized value.
helpGetBytesForState
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private K helpGetKey(long node) { Node nodeStorage = getNodeSegmentAndOffset(node); MemorySegment segment = nodeStorage.nodeSegment; int offsetInSegment = nodeStorage.nodeOffset; int level = SkipListUtils.getLevel(segment, offsetInSegment); int keyDataLen = SkipListUtils.getKeyLen(segment, offsetInSegment); int keyDataOffset = offsetInSegment + SkipListUtils.getKeyDataOffset(level); return skipListKeySerializer.deserializeKey(segment, keyDataOffset, keyDataLen); }
Returns the key of the node.
helpGetKey
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
S helpGetState(long valuePointer, SkipListValueSerializer<S> serializer) { if (valuePointer == NIL_VALUE_POINTER) { return null; } Node node = getNodeSegmentAndOffset(valuePointer); MemorySegment segment = node.nodeSegment; int offsetInSegment = node.nodeOffset; int valueLen = SkipListUtils.getValueLen(segment, offsetInSegment); if (valueLen == 0) { // it is a removed key return null; } return serializer.deserializeState( segment, offsetInSegment + SkipListUtils.getValueMetaLen(), valueLen); }
Return the state pointed by the given pointer. The value will be de-serialized with the given serializer.
helpGetState
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
S helpGetState(long valuePointer) { return helpGetState(valuePointer, skipListValueSerializer); }
Return the state pointed by the given pointer. The serializer used is the {@link #skipListValueSerializer}. Because serializer is not thread safe, so this method should only be called in the state map synchronously.
helpGetState
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMap.java
Apache-2.0
private void writeKeyAndNamespace(long nodeId, DataOutputView outputView) throws IOException { // tuple of byte arrays for key and namespace Tuple2<byte[], byte[]> tuple = owningStateMap.helpGetBytesForKeyAndNamespace(nodeId); // write namespace first outputView.write(tuple.f1); outputView.write(tuple.f0); }
Write key and namespace from bytes.
writeKeyAndNamespace
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapSnapshot.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapSnapshot.java
Apache-2.0
static int compareTo(MemorySegment left, int leftOffset, MemorySegment right, int rightOffset) { // compare namespace int leftNamespaceLen = left.getInt(leftOffset); int rightNamespaceLen = right.getInt(rightOffset); int c = left.compare( right, leftOffset + Integer.BYTES, rightOffset + Integer.BYTES, leftNamespaceLen, rightNamespaceLen); if (c != 0) { return c; } // compare key int leftKeyOffset = leftOffset + Integer.BYTES + leftNamespaceLen; int rightKeyOffset = rightOffset + Integer.BYTES + rightNamespaceLen; int leftKeyLen = left.getInt(leftKeyOffset); int rightKeyLen = right.getInt(rightKeyOffset); return left.compare( right, leftKeyOffset + Integer.BYTES, rightKeyOffset + Integer.BYTES, leftKeyLen, rightKeyLen); }
Compares for order. Returns a negative integer, zero, or a positive integer as the first node is less than, equal to, or greater than the second. @param left left skip list key's ByteBuffer @param leftOffset left skip list key's ByteBuffer's offset @param right right skip list key's ByteBuffer @param rightOffset right skip list key's ByteBuffer's offset @return An integer result of the comparison.
compareTo
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeyComparator.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeyComparator.java
Apache-2.0
static int compareNamespaceAndNode( MemorySegment namespaceSegment, int namespaceOffset, int namespaceLen, MemorySegment nodeSegment, int nodeKeyOffset) { int nodeNamespaceLen = nodeSegment.getInt(nodeKeyOffset); return namespaceSegment.compare( nodeSegment, namespaceOffset, nodeKeyOffset + Integer.BYTES, namespaceLen, nodeNamespaceLen); }
Compares the namespace in the memory segment with the namespace in the node . Returns a negative integer, zero, or a positive integer as the first node is less than, equal to, or greater than the second. @param namespaceSegment memory segment to store the namespace. @param namespaceOffset offset of namespace in the memory segment. @param namespaceLen length of namespace. @param nodeSegment memory segment to store the node key. @param nodeKeyOffset offset of node key in the memory segment. @return An integer result of the comparison.
compareNamespaceAndNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeyComparator.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeyComparator.java
Apache-2.0
N deserializeNamespace(MemorySegment memorySegment, int offset, int len) { MemorySegmentInputStreamWithPos inputStream = new MemorySegmentInputStreamWithPos(memorySegment, offset, len); DataInputViewStreamWrapper inputView = new DataInputViewStreamWrapper(inputStream); inputStream.setPosition(offset + Integer.BYTES); try { return namespaceSerializer.deserialize(inputView); } catch (IOException e) { throw new RuntimeException("deserialize namespace failed", e); } }
Deserialize the namespace from the byte buffer which stores skip list key. @param memorySegment the memory segment which stores the skip list key. @param offset the start position of the skip list key in the byte buffer. @param len length of the skip list key.
deserializeNamespace
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeySerializer.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeySerializer.java
Apache-2.0
K deserializeKey(MemorySegment memorySegment, int offset, int len) { MemorySegmentInputStreamWithPos inputStream = new MemorySegmentInputStreamWithPos(memorySegment, offset, len); DataInputViewStreamWrapper inputView = new DataInputViewStreamWrapper(inputStream); int namespaceLen = memorySegment.getInt(offset); inputStream.setPosition(offset + Integer.BYTES + namespaceLen + Integer.BYTES); try { return keySerializer.deserialize(inputView); } catch (IOException e) { throw new RuntimeException("deserialize key failed", e); } }
Deserialize the partition key from the byte buffer which stores skip list key. @param memorySegment the memory segment which stores the skip list key. @param offset the start position of the skip list key in the byte buffer. @param len length of the skip list key.
deserializeKey
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeySerializer.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeySerializer.java
Apache-2.0
Tuple2<byte[], byte[]> getSerializedKeyAndNamespace(MemorySegment memorySegment, int offset) { // read namespace int namespaceLen = memorySegment.getInt(offset); MemorySegment namespaceSegment = MemorySegmentFactory.allocateUnpooledSegment(namespaceLen); memorySegment.copyTo(offset + Integer.BYTES, namespaceSegment, 0, namespaceLen); // read key int keyOffset = offset + Integer.BYTES + namespaceLen; int keyLen = memorySegment.getInt(keyOffset); MemorySegment keySegment = MemorySegmentFactory.allocateUnpooledSegment(keyLen); memorySegment.copyTo(keyOffset + Integer.BYTES, keySegment, 0, keyLen); return Tuple2.of(keySegment.getArray(), namespaceSegment.getArray()); }
Gets serialized key and namespace from the byte buffer. @param memorySegment the memory segment which stores the skip list key. @param offset the start position of the skip list key in the byte buffer. @return tuple of serialized key and namespace.
getSerializedKeyAndNamespace
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeySerializer.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListKeySerializer.java
Apache-2.0
public static int getLevel(MemorySegment memorySegment, int offset) { return memorySegment.getInt(offset + KEY_META_OFFSET) & BYTE_MASK; }
Returns the level of the node. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment.
getLevel
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static NodeStatus getNodeStatus(MemorySegment memorySegment, int offset) { byte status = (byte) ((memorySegment.getInt(offset + KEY_META_OFFSET) >>> 8) & BYTE_MASK); return NodeStatus.valueOf(status); }
Returns the status of the node. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment.
getNodeStatus
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putLevelAndNodeStatus( MemorySegment memorySegment, int offset, int level, NodeStatus status) { int data = ((status.getValue() & BYTE_MASK) << 8) | level; memorySegment.putInt(offset + SkipListUtils.KEY_META_OFFSET, data); }
Puts the level and status to the key space. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment. @param level the level. @param status the status.
putLevelAndNodeStatus
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static int getKeyLen(MemorySegment memorySegment, int offset) { return memorySegment.getInt(offset + KEY_LEN_OFFSET); }
Returns the length of the key. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment.
getKeyLen
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putKeyLen(MemorySegment memorySegment, int offset, int keyLen) { memorySegment.putInt(offset + KEY_LEN_OFFSET, keyLen); }
Puts the length of key to the key space. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment. @param keyLen length of key.
putKeyLen
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static long getValuePointer(MemorySegment memorySegment, int offset) { return memorySegment.getLong(offset + VALUE_POINTER_OFFSET); }
Returns the value pointer. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment.
getValuePointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putValuePointer(MemorySegment memorySegment, int offset, long valuePointer) { memorySegment.putLong(offset + VALUE_POINTER_OFFSET, valuePointer); }
Puts the value pointer to key space. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment. @param valuePointer the value pointer.
putValuePointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static long getNextKeyPointer(MemorySegment memorySegment, int offset) { return memorySegment.getLong(offset + NEXT_KEY_POINTER_OFFSET); }
Returns the next key pointer on level 0. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment.
getNextKeyPointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putNextKeyPointer( MemorySegment memorySegment, int offset, long nextKeyPointer) { memorySegment.putLong(offset + NEXT_KEY_POINTER_OFFSET, nextKeyPointer); }
Puts the next key pointer on level 0 to key space. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment. @param nextKeyPointer next key pointer on level 0.
putNextKeyPointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static long getNextIndexNode(MemorySegment memorySegment, int offset, int level) { return memorySegment.getLong(offset + INDEX_NEXT_OFFSET_BY_LEVEL_ARRAY[level]); }
Returns next key pointer on the given index level. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment. @param level level of index.
getNextIndexNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putNextIndexNode( MemorySegment memorySegment, int offset, int level, long nextKeyPointer) { memorySegment.putLong(offset + INDEX_NEXT_OFFSET_BY_LEVEL_ARRAY[level], nextKeyPointer); }
Puts next key pointer on the given index level to key space. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment. @param level level of index. @param nextKeyPointer next key pointer on the given level.
putNextIndexNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putPrevIndexNode( MemorySegment memorySegment, int offset, int totalLevel, int level, long prevKeyPointer) { int of = getIndexOffset(offset, totalLevel, level); memorySegment.putLong(of, prevKeyPointer); }
Puts previous key pointer on the given index level to key space. @param memorySegment memory segment for key space. @param offset offset of key space in the memory segment. @param totalLevel top level of the key. @param level level of index. @param prevKeyPointer previous key pointer on the given level.
putPrevIndexNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static int getKeyMetaLen(int level) { Preconditions.checkArgument( level >= 0 && level < KEY_META_LEN_BY_LEVEL_ARRAY.length, "level " + level + " out of range [0, " + KEY_META_LEN_BY_LEVEL_ARRAY.length + ")"); return KEY_META_LEN_BY_LEVEL_ARRAY[level]; }
Returns the length of key meta with the given level. @param level level of the key.
getKeyMetaLen
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static int getKeyDataOffset(int level) { return SkipListUtils.getKeyMetaLen(level); }
Returns the offset of key data in the key space. @param level level of the key.
getKeyDataOffset
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putKeyData( MemorySegment segment, int offset, MemorySegment keySegment, int keyOffset, int keyLen, int level) { keySegment.copyTo(keyOffset, segment, offset + getKeyDataOffset(level), keyLen); }
Puts the key data into key space. @param segment memory segment for key space. @param offset offset of key space in memory segment. @param keySegment memory segment for key data. @param keyOffset offset of key data in memory segment. @param keyLen length of key data. @param level level of the key.
putKeyData
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static int getValueVersion(MemorySegment memorySegment, int offset) { return memorySegment.getInt(offset + VALUE_VERSION_OFFSET); }
Returns the version of value. @param memorySegment memory segment for value space. @param offset offset of value space in memory segment.
getValueVersion
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putValueVersion(MemorySegment memorySegment, int offset, int version) { memorySegment.putInt(offset + VALUE_VERSION_OFFSET, version); }
Puts the version of value to value space. @param memorySegment memory segment for value space. @param offset offset of value space in memory segment. @param version version of value.
putValueVersion
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static long getKeyPointer(MemorySegment memorySegment, int offset) { return memorySegment.getLong(offset + KEY_POINTER_OFFSET); }
Return the pointer to key space. @param memorySegment memory segment for value space. @param offset offset of value space in memory segment.
getKeyPointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putKeyPointer(MemorySegment memorySegment, int offset, long keyPointer) { memorySegment.putLong(offset + KEY_POINTER_OFFSET, keyPointer); }
Puts the pointer of key space. @param memorySegment memory segment for value space. @param offset offset of value space in memory segment. @param keyPointer pointer to key space.
putKeyPointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static long getNextValuePointer(MemorySegment memorySegment, int offset) { return memorySegment.getLong(offset + NEXT_VALUE_POINTER_OFFSET); }
Return the pointer to next value space. @param memorySegment memory segment for value space. @param offset offset of value space in memory segment.
getNextValuePointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putNextValuePointer( MemorySegment memorySegment, int offset, long nextValuePointer) { memorySegment.putLong(offset + NEXT_VALUE_POINTER_OFFSET, nextValuePointer); }
Puts the pointer of next value space. @param memorySegment memory segment for value space. @param offset offset of value space in memory segment. @param nextValuePointer pointer to next value space.
putNextValuePointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static int getValueLen(MemorySegment memorySegment, int offset) { return memorySegment.getInt(offset + VALUE_LEN_OFFSET); }
Return the length of value data. @param memorySegment memory segment for value space. @param offset offset of value space in memory segment.
getValueLen
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putValueLen(MemorySegment memorySegment, int offset, int valueLen) { memorySegment.putInt(offset + VALUE_LEN_OFFSET, valueLen); }
Puts the length of value data. @param memorySegment memory segment for value space. @param offset offset of value space in memory segment. @param valueLen length of value data.
putValueLen
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static int getValueMetaLen() { return VALUE_DATA_OFFSET; }
Returns the length of value meta.
getValueMetaLen
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
public static void putValueData(MemorySegment memorySegment, int offset, byte[] value) { MemorySegment valueSegment = MemorySegmentFactory.wrap(value); valueSegment.copyTo(0, memorySegment, offset + getValueMetaLen(), value.length); }
Puts the value data into value space. @param memorySegment memory segment for value space. @param offset offset of value space in memory segment. @param value value data.
putValueData
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static void helpSetNextNode( long node, long nextNode, int level, LevelIndexHeader levelIndexHeader, Allocator spaceAllocator) { if (node == HEAD_NODE) { levelIndexHeader.updateNextNode(level, nextNode); return; } Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(node)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(node); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); if (level == 0) { putNextKeyPointer(segment, offsetInByteBuffer, nextNode); } else { putNextIndexNode(segment, offsetInByteBuffer, level, nextNode); } }
Set the next node of the given node at the given level. @param node the node. @param nextNode the next node to set. @param level the level to find the next node. @param levelIndexHeader the header of the level index. @param spaceAllocator the space allocator.
helpSetNextNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static long helpGetNextNode( long node, int level, LevelIndexHeader levelIndexHeader, Allocator spaceAllocator) { if (node == HEAD_NODE) { return levelIndexHeader.getNextNode(level); } Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(node)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(node); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); return level == 0 ? getNextKeyPointer(segment, offsetInByteBuffer) : getNextIndexNode(segment, offsetInByteBuffer, level); }
Return the next of the given node at the given level. @param node the node to find the next node for. @param level the level to find the next node. @param levelIndexHeader the header of the level index. @param spaceAllocator the space allocator. @return the pointer to the next node of the given node at the given level.
helpGetNextNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static void helpSetPrevNode(long node, long prevNode, int level, Allocator spaceAllocator) { Preconditions.checkArgument(level > 0, "only index level have previous node"); if (node == HEAD_NODE || node == NIL_NODE) { return; } Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(node)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(node); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); int topLevel = getLevel(segment, offsetInByteBuffer); putPrevIndexNode(segment, offsetInByteBuffer, topLevel, level, prevNode); }
Set the previous node of the given node at the given level. The level must be positive. @param node the node. @param prevNode the previous node to set. @param level the level to find the next node. @param spaceAllocator the space allocator.
helpSetPrevNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static void helpSetPrevAndNextNode( long node, long prevNode, long nextNode, int level, Allocator spaceAllocator) { Preconditions.checkArgument(node != HEAD_NODE, "head node does not have previous node"); Preconditions.checkArgument(level > 0, "only index level have previous node"); Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(node)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(node); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); int topLevel = getLevel(segment, offsetInByteBuffer); putNextIndexNode(segment, offsetInByteBuffer, level, nextNode); putPrevIndexNode(segment, offsetInByteBuffer, topLevel, level, prevNode); }
Set the previous node and the next node of the given node at the given level. The level must be positive. @param node the node. @param prevNode the previous node to set. @param nextNode the next node to set. @param level the level to find the next node. @param spaceAllocator the space allocator.
helpSetPrevAndNextNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static boolean isNodeRemoved(long node, Allocator spaceAllocator) { if (node == NIL_NODE) { return false; } Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(node)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(node); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); return getNodeStatus(segment, offsetInByteBuffer) == NodeStatus.REMOVE; }
Whether the node has been logically removed. @param node the node to check against @param spaceAllocator the space allocator @return true if the node has been logically removed.
isNodeRemoved
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static int compareSegmentAndNode( MemorySegment keySegment, int keyOffset, long targetNode, @Nonnull Allocator spaceAllocator) { Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(targetNode)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(targetNode); MemorySegment targetKeySegment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); int level = getLevel(targetKeySegment, offsetInByteBuffer); int targetKeyOffset = offsetInByteBuffer + getKeyDataOffset(level); return SkipListKeyComparator.compareTo( keySegment, keyOffset, targetKeySegment, targetKeyOffset); }
Compare the first skip list key in the given memory segment with the second skip list key in the given node. @param keySegment memory segment storing the first key. @param keyOffset offset of the first key in memory segment. @param targetNode the node storing the second key. @param spaceAllocator the space allocator. @return Returns a negative integer, zero, or a positive integer as the first key is less than, equal to, or greater than the second.
compareSegmentAndNode
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static long findPredecessor( long node, int level, LevelIndexHeader levelIndexHeader, @Nonnull Allocator spaceAllocator) { Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(node)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(node); MemorySegment keySegment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); int keyLevel = getLevel(keySegment, offsetInByteBuffer); int keyOffset = offsetInByteBuffer + getKeyDataOffset(keyLevel); return findPredecessor(keySegment, keyOffset, level, levelIndexHeader, spaceAllocator); }
Find the predecessor node for the given node at the given level. @param node the node. @param level the level. @param levelIndexHeader the head level index. @param spaceAllocator the space allocator. @return node id before the key at the given level.
findPredecessor
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static long findPredecessor( MemorySegment keySegment, int keyOffset, int level, @Nonnull LevelIndexHeader levelIndexHeader, Allocator spaceAllocator) { int currentLevel = levelIndexHeader.getLevel(); long currentNode = HEAD_NODE; long nextNode = levelIndexHeader.getNextNode(currentLevel); for (; ; ) { if (nextNode != NIL_NODE) { int c = compareSegmentAndNode(keySegment, keyOffset, nextNode, spaceAllocator); if (c > 0) { currentNode = nextNode; nextNode = helpGetNextNode( currentNode, currentLevel, levelIndexHeader, spaceAllocator); continue; } } if (currentLevel <= level) { return currentNode; } currentLevel--; nextNode = helpGetNextNode(currentNode, currentLevel, levelIndexHeader, spaceAllocator); } }
Find the predecessor node for the given key at the given level. The key is in the memory segment positioning at the given offset. @param keySegment memory segment which contains the key. @param keyOffset offset of the key in the memory segment. @param level the level. @param levelIndexHeader the head level index. @param spaceAllocator the space allocator. @return node id before the key at the given level.
findPredecessor
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static long helpGetNextValuePointer(long valuePointer, Allocator spaceAllocator) { Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(valuePointer)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(valuePointer); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); return getNextValuePointer(segment, offsetInByteBuffer); }
Returns the next value pointer of the value. @param valuePointer the value pointer of current value. @param spaceAllocator the space allocator.
helpGetNextValuePointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static void helpSetNextValuePointer( long valuePointer, long nextValuePointer, Allocator spaceAllocator) { Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(valuePointer)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(valuePointer); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); putNextValuePointer(segment, offsetInByteBuffer, nextValuePointer); }
Sets the next value pointer of the value. @param valuePointer the value pointer. @param nextValuePointer the next value pointer to set. @param spaceAllocator the space allocator.
helpSetNextValuePointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static void buildLevelIndex( long node, int level, MemorySegment keySegment, int keyOffset, LevelIndexHeader levelIndexHeader, Allocator spaceAllocator) { int currLevel = level; long prevNode = findPredecessor(keySegment, keyOffset, currLevel, levelIndexHeader, spaceAllocator); long currentNode = helpGetNextNode(prevNode, currLevel, levelIndexHeader, spaceAllocator); for (; ; ) { if (currentNode != NIL_NODE) { int c = compareSegmentAndNode(keySegment, keyOffset, currentNode, spaceAllocator); if (c > 0) { prevNode = currentNode; currentNode = helpGetNextNode( currentNode, currLevel, levelIndexHeader, spaceAllocator); continue; } } helpSetPrevAndNextNode(node, prevNode, currentNode, currLevel, spaceAllocator); helpSetNextNode(prevNode, node, currLevel, levelIndexHeader, spaceAllocator); helpSetPrevNode(currentNode, node, currLevel, spaceAllocator); currLevel--; if (currLevel == 0) { break; } currentNode = helpGetNextNode(prevNode, currLevel, levelIndexHeader, spaceAllocator); } }
Build the level index for the given node. @param node the node. @param level level of the node. @param keySegment memory segment of the key in the node. @param keyOffset offset of the key in memory segment. @param levelIndexHeader the head level index. @param spaceAllocator the space allocator.
buildLevelIndex
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static void removeLevelIndex( long node, Allocator spaceAllocator, LevelIndexHeader levelIndexHeader) { Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(node)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(node); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); int level = getLevel(segment, offsetInByteBuffer); for (int i = 1; i <= level; i++) { long prevNode = getPrevIndexNode(segment, offsetInByteBuffer, level, i); long nextNode = getNextIndexNode(segment, offsetInByteBuffer, i); helpSetNextNode(prevNode, nextNode, i, levelIndexHeader, spaceAllocator); helpSetPrevNode(nextNode, prevNode, i, spaceAllocator); } }
Remove the level index for the node from the skip list. @param node the node. @param spaceAllocator the space allocator. @param levelIndexHeader the head level index.
removeLevelIndex
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static void removeAllValues(long valuePointer, Allocator spaceAllocator) { long nextValuePointer; while (valuePointer != NIL_VALUE_POINTER) { nextValuePointer = helpGetNextValuePointer(valuePointer, spaceAllocator); spaceAllocator.free(valuePointer); valuePointer = nextValuePointer; } }
Free the space of the linked values, and the head value is pointed by the given pointer. @param valuePointer the pointer of the value to start removing. @param spaceAllocator the space allocator.
removeAllValues
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static long helpGetValuePointer(long node, Allocator spaceAllocator) { Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(node)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(node); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); return getValuePointer(segment, offsetInByteBuffer); }
Returns the value pointer of the node. @param node the node. @param spaceAllocator the space allocator.
helpGetValuePointer
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static int helpGetValueVersion(long valuePointer, Allocator spaceAllocator) { Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(valuePointer)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(valuePointer); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); return getValueVersion(segment, offsetInByteBuffer); }
Returns the version of the value. @param valuePointer the pointer to the value. @param spaceAllocator the space allocator.
helpGetValueVersion
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static int helpGetValueLen(long valuePointer, Allocator spaceAllocator) { Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(valuePointer)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(valuePointer); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); return getValueLen(segment, offsetInByteBuffer); }
Returns the length of the value. @param valuePointer the pointer to the value. @param spaceAllocator the space allocator.
helpGetValueLen
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
static int helpGetNodeLatestVersion(long node, Allocator spaceAllocator) { Chunk chunk = spaceAllocator.getChunkById(SpaceUtils.getChunkIdByAddress(node)); int offsetInChunk = SpaceUtils.getChunkOffsetByAddress(node); MemorySegment segment = chunk.getMemorySegment(offsetInChunk); int offsetInByteBuffer = chunk.getOffsetInSegment(offsetInChunk); long valuePointer = getValuePointer(segment, offsetInByteBuffer); return helpGetValueVersion(valuePointer, spaceAllocator); }
Return of the newest version of value for the node. @param node the node. @param spaceAllocator the space allocator.
helpGetNodeLatestVersion
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListUtils.java
Apache-2.0
S deserializeState(MemorySegment memorySegment, int offset, int len) { final MemorySegmentInputStreamWithPos src = new MemorySegmentInputStreamWithPos(memorySegment, offset, len); final DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(src); try { return stateSerializer.deserialize(in); } catch (IOException e) { throw new RuntimeException("deserialize state failed", e); } }
Deserialize the state from the byte buffer which stores skip list value. @param memorySegment the memory segment which stores the skip list value. @param offset the start position of the skip list value in the byte buffer. @param len length of the skip list value.
deserializeState
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListValueSerializer.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/main/java/org/apache/flink/runtime/state/heap/SkipListValueSerializer.java
Apache-2.0
@Test void testUpdateState() { int totalSize = 3; for (int i = 1; i <= totalSize; i++) { stateMap.put(i, namespace, String.valueOf(i)); } // update state at tail of the skip list (new key is bigger than all existing keys) totalSize = putAndVerify(3, "33", totalSize, false); // update state at head of the skip list (new key is smaller than all existing keys) totalSize = putAndVerify(1, "11", totalSize, false); // update state in the middle putAndVerify(2, "22", totalSize, false); }
Test state update (put existing key).
testUpdateState
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
Apache-2.0
@Test void testTransformExistingState() throws Exception { final int key = 1; final String oldState = "1"; final int delta = 1; StateTransformationFunction<String, Integer> function = (String prevState, Integer value) -> prevState == null ? String.valueOf(value) : prevState + value; stateMap.put(key, namespace, oldState); String expectedState = function.apply(oldState, delta); stateMap.transform(key, namespace, delta, function); assertThat(stateMap.get(key, namespace)).isEqualTo(expectedState); assertThat(stateMap.size()).isEqualTo(1); assertThat(stateMap.totalSize()).isEqualTo(1); assertThat(allocator.getTotalSpaceNumber()).isEqualTo(2); }
Test state transform with existing key.
testTransformExistingState
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
Apache-2.0
@Test void testTransformAbsentState() throws Exception { final int key = 1; final int delta = 1; StateTransformationFunction<String, Integer> function = (String prevState, Integer value) -> prevState == null ? String.valueOf(value) : prevState + value; String expectedState = function.apply(null, delta); stateMap.transform(key, namespace, delta, function); assertThat(stateMap.get(key, namespace)).isEqualTo(expectedState); assertThat(stateMap.size()).isEqualTo(1); assertThat(stateMap.totalSize()).isEqualTo(1); assertThat(allocator.getTotalSpaceNumber()).isEqualTo(2); }
Test state transform with new key.
testTransformAbsentState
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
Apache-2.0
@Test void testPutAndGetNodeWithNoneZeroOffset() { final int key = 10; final long namespace = 0L; final String valueString = "test"; SkipListKeySerializer<Integer, Long> skipListKeySerializer = new SkipListKeySerializer<>(IntSerializer.INSTANCE, LongSerializer.INSTANCE); SkipListValueSerializer<String> skipListValueSerializer = new SkipListValueSerializer<>(StringSerializer.INSTANCE); byte[] keyBytes = skipListKeySerializer.serialize(key, namespace); byte[] constructedKeyBytes = new byte[keyBytes.length + 1]; System.arraycopy(keyBytes, 0, constructedKeyBytes, 1, keyBytes.length); MemorySegment keySegment = MemorySegmentFactory.wrap(constructedKeyBytes); int keyLen = keyBytes.length; byte[] value = skipListValueSerializer.serialize(valueString); stateMap.putValue(keySegment, 1, keyLen, value, false); String state = stateMap.getNode(keySegment, 1, keyLen); assertThat(state).isEqualTo(valueString); }
This tests the internal capability of using partial {@link ByteBuffer}, making sure the internal methods works when put/get state with a key stored at a none-zero offset of a ByteBuffer.
testPutAndGetNodeWithNoneZeroOffset
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
Apache-2.0
@Test void testStateIncrementalVisitor() { // map to store expected states, namespace -> key -> state Map<Long, Map<Integer, String>> referenceStates = new HashMap<>(); // put some states for (long namespace = 0; namespace < 15; namespace++) { for (int key = 0; key < 20; key++) { String state = String.valueOf(namespace * key); stateMap.put(key, namespace, state); addToReferenceState(referenceStates, key, namespace, state); } } verifyState(referenceStates, stateMap); InternalKvState.StateIncrementalVisitor<Integer, Long, String> visitor = stateMap.getStateIncrementalVisitor(5); int op = 0; while (visitor.hasNext()) { for (StateEntry<Integer, Long, String> stateEntry : visitor.nextEntries()) { int key = stateEntry.getKey(); long namespace = stateEntry.getNamespace(); String state = stateEntry.getState(); assertThat(stateMap.get(key, namespace)).isEqualTo(state); switch (op) { case 0: visitor.remove(stateEntry); removeFromReferenceState(referenceStates, key, namespace); op = 1; break; case 1: String newState = state + "-update"; visitor.update(stateEntry, newState); addToReferenceState(referenceStates, key, namespace, newState); op = 2; break; default: op = 0; break; } } } verifyState(referenceStates, stateMap); }
Test next/update/remove during global iteration of StateIncrementalVisitor.
testStateIncrementalVisitor
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
Apache-2.0
@Test void testStateIncrementalVisitorWithClosedStateMap() { CopyOnWriteSkipListStateMap<Integer, Long, String> stateMap = createEmptyStateMap(); // put some states for (long namespace = 0; namespace < 15; namespace++) { for (int key = 0; key < 20; key++) { String state = String.valueOf(namespace * key); stateMap.put(key, namespace, state); } } InternalKvState.StateIncrementalVisitor<Integer, Long, String> closedVisitor = stateMap.getStateIncrementalVisitor(5); assertThat(closedVisitor.hasNext()).isTrue(); stateMap.close(); // the visitor will be invalid after state map is closed assertThat(closedVisitor.hasNext()).isFalse(); }
Test StateIncrementalVisitor with closed state map.
testStateIncrementalVisitorWithClosedStateMap
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
Apache-2.0
@Test void testSnapshotNodeIteratorIllegalNextInvocation() { CopyOnWriteSkipListStateMapSnapshot<Integer, Long, String> snapshot = stateMap.stateSnapshot(); CopyOnWriteSkipListStateMapSnapshot.SnapshotNodeIterator iterator = snapshot.new SnapshotNodeIterator(false); while (iterator.hasNext()) { iterator.next(); } try { assertThatThrownBy(() -> iterator.next()).isInstanceOf(NoSuchElementException.class); } finally { snapshot.release(); } }
Test snapshot node iterator illegal next call.
testSnapshotNodeIteratorIllegalNextInvocation
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapBasicOpTest.java
Apache-2.0
@Test void testPhysicallyRemoveWithGet() throws IOException { testPhysicallyRemoveWithFunction( (map, reference, i) -> { map.get(i, (long) i); return 0; }); }
Tests that remove states physically when get is invoked.
testPhysicallyRemoveWithGet
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
Apache-2.0
@Test void testPhysicallyRemoveWithContains() throws IOException { testPhysicallyRemoveWithFunction( (map, reference, i) -> { assertThat(map.containsKey(i, (long) i)).isFalse(); return 0; }); }
Tests that remove states physically when contains is invoked.
testPhysicallyRemoveWithContains
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
Apache-2.0
@Test void testPhysicallyRemoveWithRemove() throws IOException { testPhysicallyRemoveWithFunction( (map, reference, i) -> { map.remove(i, (long) i); return 0; }); }
Tests that remove states physically when remove is invoked.
testPhysicallyRemoveWithRemove
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
Apache-2.0
@Test void testPhysicallyRemoveWithRemoveAndGetOld() throws IOException { testPhysicallyRemoveWithFunction( (map, reference, i) -> { assertThat(map.removeAndGetOld(i, (long) i)).isNull(); return 0; }); }
Tests that remove states physically when removeAndGetOld is invoked.
testPhysicallyRemoveWithRemoveAndGetOld
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
Apache-2.0
@Test void testPhysicallyRemoveWithPut() throws IOException { testPhysicallyRemoveWithFunction( (map, reference, i) -> { map.put(i, (long) i, String.valueOf(i)); addToReferenceState(reference, i, (long) i, String.valueOf(i)); return 1; }); }
Tests that remove states physically when put is invoked.
testPhysicallyRemoveWithPut
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
Apache-2.0
@Test void testPhysicallyRemoveWithPutAndGetOld() throws IOException { testPhysicallyRemoveWithFunction( (map, reference, i) -> { assertThat(map.putAndGetOld(i, (long) i, String.valueOf(i))).isNull(); addToReferenceState(reference, i, (long) i, String.valueOf(i)); return 1; }); }
Tests that remove states physically when putAndGetOld is invoked.
testPhysicallyRemoveWithPutAndGetOld
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
Apache-2.0
private void testPhysicallyRemoveWithFunction( TriFunction< CopyOnWriteSkipListStateMap<Integer, Long, String>, Map<Long, Map<Integer, String>>, Integer, Integer> f) throws IOException { TestAllocator spaceAllocator = new TestAllocator(256); CopyOnWriteSkipListStateMap<Integer, Long, String> stateMap = createEmptyStateMap(2, 1.0f, spaceAllocator); // map to store expected states, namespace -> key -> state Map<Long, Map<Integer, String>> referenceStates = new HashMap<>(); // here we use a trick that put all odd namespace to state map, and get/put/remove even // namespace // so that all logically removed nodes can be accessed prepareLogicallyRemovedStates( referenceStates, stateMap, keySerializer, namespaceSerializer, stateSerializer); int expectedSize = 0; for (int i = 0; i <= 100; i += 2) { expectedSize += f.apply(stateMap, referenceStates, i); } assertThat(stateMap.size()).isEqualTo(expectedSize); assertThat(stateMap.totalSize()).isEqualTo(expectedSize); assertThat(spaceAllocator.getTotalSpaceNumber()).isEqualTo(expectedSize * 2); verifyState(referenceStates, stateMap); stateMap.close(); }
Tests remove states physically when the given function is applied. @param f the function to apply for each test iteration, with [stateMap, referenceStates, testRoundIndex] as input and returns the delta size caused by applying function. @throws IOException if unexpected error occurs.
testPhysicallyRemoveWithFunction
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
Apache-2.0
@Test void testSnapshotPruneValues() throws IOException { TestAllocator spaceAllocator = new TestAllocator(256); // set logicalRemovedKeysRatio to 0 so that all logically removed states will be deleted // when snapshot CopyOnWriteSkipListStateMap<Integer, Long, String> stateMap = createEmptyStateMap(DEFAULT_MAX_KEYS_TO_DELETE_ONE_TIME, 0.0f, spaceAllocator); // firstly build value chain and snapshots as follows // ------ ------ ------ ------ // | v3 | -> | v2 | -> | v1 | -> | v0 | // ------ ------ ------ ------ // | | | | // snapshot4 snapshot3 snapshot2 snapshot1 // snapshot5 // snapshot6 List<String> referenceValues = new ArrayList<>(); // build v0 stateMap.put(1, 1L, "0"); referenceValues.add(0, "0"); // get the pointer to the node long node = stateMap.getLevelIndexHeader().getNextNode(0); // take snapshot1 CopyOnWriteSkipListStateMapSnapshot<Integer, Long, String> snapshot1 = stateMap.stateSnapshot(); // build v1 stateMap.put(1, 1L, "1"); referenceValues.add(0, "1"); // take snapshot2 CopyOnWriteSkipListStateMapSnapshot<Integer, Long, String> snapshot2 = stateMap.stateSnapshot(); // build v2 stateMap.put(1, 1L, "2"); referenceValues.add(0, "2"); // take snapshot3 CopyOnWriteSkipListStateMapSnapshot<Integer, Long, String> snapshot3 = stateMap.stateSnapshot(); // build v3 stateMap.put(1, 1L, "3"); referenceValues.add(0, "3"); // take snapshot4 CopyOnWriteSkipListStateMapSnapshot<Integer, Long, String> snapshot4 = stateMap.stateSnapshot(); // take snapshot5 CopyOnWriteSkipListStateMapSnapshot<Integer, Long, String> snapshot5 = stateMap.stateSnapshot(); // take snapshot6 CopyOnWriteSkipListStateMapSnapshot<Integer, Long, String> snapshot6 = stateMap.stateSnapshot(); assertThat(stateMap.getStateMapVersion()).isEqualTo(6); assertThat(stateMap.getHighestRequiredSnapshotVersionPlusOne()).isEqualTo(6); assertThat(stateMap.getSnapshotVersions()).hasSize(6); assertThat(spaceAllocator.getTotalSpaceNumber()).isEqualTo(5); assertThat(getAllValuesOfNode(stateMap, spaceAllocator, node)).isEqualTo(referenceValues); Map<Long, Map<Integer, String>> referenceStates = new HashMap<>(); referenceStates.put(1L, new HashMap<>()); referenceStates.get(1L).put(1, "0"); // complete snapshot 1, and no value will be removed verifySnapshotWithoutTransform( referenceStates, snapshot1, keySerializer, namespaceSerializer, stateSerializer); snapshot1.release(); assertThat(getAllValuesOfNode(stateMap, spaceAllocator, node)).isEqualTo(referenceValues); assertThat(spaceAllocator.getTotalSpaceNumber()).isEqualTo(5); assertThat(stateMap.getHighestFinishedSnapshotVersion()).isEqualTo(1); // complete snapshot 3, and v0 will be removed referenceStates.get(1L).put(1, "2"); verifySnapshotWithoutTransform( referenceStates, snapshot3, keySerializer, namespaceSerializer, stateSerializer); snapshot3.release(); referenceValues.remove(referenceValues.size() - 1); assertThat(getAllValuesOfNode(stateMap, spaceAllocator, node)).isEqualTo(referenceValues); assertThat(spaceAllocator.getTotalSpaceNumber()).isEqualTo(4); assertThat(stateMap.getHighestFinishedSnapshotVersion()).isEqualTo(1); // complete snapshot 2, and no value will be removed referenceStates.get(1L).put(1, "1"); verifySnapshotWithoutTransform( referenceStates, snapshot2, keySerializer, namespaceSerializer, stateSerializer); snapshot2.release(); assertThat(getAllValuesOfNode(stateMap, spaceAllocator, node)).isEqualTo(referenceValues); assertThat(spaceAllocator.getTotalSpaceNumber()).isEqualTo(4); assertThat(stateMap.getHighestFinishedSnapshotVersion()).isEqualTo(3); // add node to pruning set to prevent snapshot4 to prune stateMap.getPruningValueNodes().add(node); // complete snapshot 4, and no value will be removed referenceStates.get(1L).put(1, "3"); verifySnapshotWithoutTransform( referenceStates, snapshot4, keySerializer, namespaceSerializer, stateSerializer); snapshot4.release(); assertThat(getAllValuesOfNode(stateMap, spaceAllocator, node)).isEqualTo(referenceValues); assertThat(spaceAllocator.getTotalSpaceNumber()).isEqualTo(4); assertThat(stateMap.getHighestFinishedSnapshotVersion()).isEqualTo(4); stateMap.getPruningValueNodes().remove(node); // complete snapshot 5, v1 and v2 will be removed verifySnapshotWithoutTransform( referenceStates, snapshot5, keySerializer, namespaceSerializer, stateSerializer); snapshot5.release(); referenceValues.remove(referenceValues.size() - 1); referenceValues.remove(referenceValues.size() - 1); assertThat(getAllValuesOfNode(stateMap, spaceAllocator, node)).isEqualTo(referenceValues); assertThat(spaceAllocator.getTotalSpaceNumber()).isEqualTo(2); assertThat(stateMap.getHighestFinishedSnapshotVersion()).isEqualTo(5); // complete snapshot 6, no value will be removed verifySnapshotWithoutTransform( referenceStates, snapshot6, keySerializer, namespaceSerializer, stateSerializer); snapshot6.release(); assertThat(getAllValuesOfNode(stateMap, spaceAllocator, node)).isEqualTo(referenceValues); assertThat(spaceAllocator.getTotalSpaceNumber()).isEqualTo(2); assertThat(stateMap.getHighestFinishedSnapshotVersion()).isEqualTo(6); assertThat(stateMap.removeAndGetOld(1, 1L)).isEqualTo("3"); assertThat(stateMap.size()).isEqualTo(0); assertThat(spaceAllocator.getTotalSpaceNumber()).isEqualTo(0); stateMap.close(); }
Tests that snapshots prune useless values.
testSnapshotPruneValues
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/CopyOnWriteSkipListStateMapComplexOpTest.java
Apache-2.0
@Test void testOnceUpdateMoreThanOneLevel() { assertThatThrownBy(() -> heapHeadIndex.updateLevel(heapHeadIndex.getLevel() + 2)) .isInstanceOf(IllegalArgumentException.class); }
Test once update more than one level is not allowed.
testOnceUpdateMoreThanOneLevel
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/OnHeapLevelIndexHeaderTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/OnHeapLevelIndexHeaderTest.java
Apache-2.0
@Test void testUpdateToNegativeLevel() { assertThatThrownBy(() -> heapHeadIndex.updateLevel(-1)) .isInstanceOf(IllegalArgumentException.class); }
Test update to negative level is not allowed.
testUpdateToNegativeLevel
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/OnHeapLevelIndexHeaderTest.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/OnHeapLevelIndexHeaderTest.java
Apache-2.0
public synchronized int getTotalSpaceSize() { return chunkMap.size() * maxAllocateSize; }
Returns total size of used space.
getTotalSpaceSize
java
apache/flink
flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/TestAllocator.java
https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-heap-spillable/src/test/java/org/apache/flink/runtime/state/heap/TestAllocator.java
Apache-2.0