Search in sources :

Example 1 with Chunk

use of org.apache.flink.runtime.state.heap.space.Chunk in project flink by apache.

the class SkipListUtils method helpGetNodeLatestVersion.

/**
 * Return of the newest version of value for the node.
 *
 * @param node the node.
 * @param spaceAllocator the space allocator.
 */
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);
}
Also used : Chunk(org.apache.flink.runtime.state.heap.space.Chunk) MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 2 with Chunk

use of org.apache.flink.runtime.state.heap.space.Chunk 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);
}
Also used : Chunk(org.apache.flink.runtime.state.heap.space.Chunk) MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 3 with Chunk

use of org.apache.flink.runtime.state.heap.space.Chunk 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);
    }
}
Also used : Chunk(org.apache.flink.runtime.state.heap.space.Chunk) MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 4 with Chunk

use of org.apache.flink.runtime.state.heap.space.Chunk 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);
}
Also used : Chunk(org.apache.flink.runtime.state.heap.space.Chunk) MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 5 with Chunk

use of org.apache.flink.runtime.state.heap.space.Chunk 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);
}
Also used : Chunk(org.apache.flink.runtime.state.heap.space.Chunk) MemorySegment(org.apache.flink.core.memory.MemorySegment)

Aggregations

MemorySegment (org.apache.flink.core.memory.MemorySegment)15 Chunk (org.apache.flink.runtime.state.heap.space.Chunk)15