use of org.apache.flink.core.memory.MemorySegment in project flink by apache.
the class CopyOnWriteSkipListStateMap method doWriteValue.
/**
* 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.
*/
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);
}
}
use of org.apache.flink.core.memory.MemorySegment in project flink by apache.
the class SkipListUtils method compareSegmentAndNode.
/**
* 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.
*/
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);
}
use of org.apache.flink.core.memory.MemorySegment in project flink by apache.
the class SkipListUtils method removeLevelIndex.
/**
* 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.
*/
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);
}
}
use of org.apache.flink.core.memory.MemorySegment in project flink by apache.
the class SkipListUtils method helpSetPrevAndNextNode.
/**
* 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.
*/
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);
}
use of org.apache.flink.core.memory.MemorySegment in project flink by apache.
the class SkipListUtils method helpGetNextNode.
/**
* 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.
*/
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);
}
Aggregations