Search in sources :

Example 81 with MemorySegment

use of org.apache.flink.core.memory.MemorySegment in project flink by apache.

the class CopyOnWriteSkipListStateMap method helpSetNodeStatus.

/**
 * Set node status to the given new status, and return old status.
 */
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;
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 82 with MemorySegment

use of org.apache.flink.core.memory.MemorySegment in project flink by apache.

the class CopyOnWriteSkipListStateMap method updateValueWithCopyOnWrite.

/**
 * 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.
 */
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;
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 83 with MemorySegment

use of org.apache.flink.core.memory.MemorySegment in project flink by apache.

the class CopyOnWriteSkipListStateMap method helpGetState.

/**
 * Return the state pointed by the given pointer. The value will be de-serialized with the given
 * serializer.
 */
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);
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 84 with MemorySegment

use of org.apache.flink.core.memory.MemorySegment in project flink by apache.

the class CopyOnWriteSkipListStateMap method put.

@Override
public void put(K key, N namespace, S state) {
    updateStat();
    MemorySegment keySegment = getKeySegment(key, namespace);
    int keyLen = keySegment.size();
    byte[] value = skipListValueSerializer.serialize(state);
    putValue(keySegment, 0, keyLen, value, false);
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 85 with MemorySegment

use of org.apache.flink.core.memory.MemorySegment in project flink by apache.

the class CopyOnWriteSkipListStateMap method getNodeInternal.

/**
 * 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.
 */
private S getNodeInternal(K key, N namespace) {
    MemorySegment keySegment = getKeySegment(key, namespace);
    int keyLen = keySegment.size();
    return getNode(keySegment, 0, keyLen);
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment)

Aggregations

MemorySegment (org.apache.flink.core.memory.MemorySegment)375 Test (org.junit.Test)136 ArrayList (java.util.ArrayList)52 DummyInvokable (org.apache.flink.runtime.operators.testutils.DummyInvokable)44 IOException (java.io.IOException)37 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)29 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)26 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)25 MemoryAllocationException (org.apache.flink.runtime.memory.MemoryAllocationException)24 IntPair (org.apache.flink.runtime.operators.testutils.types.IntPair)24 FileIOChannel (org.apache.flink.runtime.io.disk.iomanager.FileIOChannel)20 EOFException (java.io.EOFException)18 ByteBuffer (java.nio.ByteBuffer)18 AbstractInvokable (org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable)18 TestData (org.apache.flink.runtime.operators.testutils.TestData)18 Random (java.util.Random)16 UniformIntPairGenerator (org.apache.flink.runtime.operators.testutils.UniformIntPairGenerator)16 Chunk (org.apache.flink.runtime.state.heap.space.Chunk)15 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)15 IOManagerAsync (org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync)14