Search in sources :

Example 76 with MemorySegment

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

the class SkipListKeyComparatorTest method compareSkipListKey.

private <K, N> int compareSkipListKey(@Nonnull SkipListKeySerializer<K, N> keySerializer, K key1, N namespace1, K key2, N namespace2) {
    MemorySegment b1 = MemorySegmentFactory.wrap(keySerializer.serialize(key1, namespace1));
    MemorySegment b2 = MemorySegmentFactory.wrap(keySerializer.serialize(key2, namespace2));
    return SkipListKeyComparator.compareTo(b1, 0, b2, 0);
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 77 with MemorySegment

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

the class SkipListUtilsTest method verifyGetKeySpace.

private void verifyGetKeySpace(KeySpace keySpace, MemorySegment memorySegment, int offset) {
    assertEquals(keySpace.level, SkipListUtils.getLevel(memorySegment, offset));
    assertEquals(keySpace.status, SkipListUtils.getNodeStatus(memorySegment, offset));
    assertEquals(keySpace.keyData.length, SkipListUtils.getKeyLen(memorySegment, offset));
    assertEquals(keySpace.valuePointer, SkipListUtils.getValuePointer(memorySegment, offset));
    assertEquals(keySpace.nextKeyPointer, SkipListUtils.getNextKeyPointer(memorySegment, offset));
    for (int i = 1; i <= keySpace.nextIndexNodes.length; i++) {
        assertEquals(keySpace.nextIndexNodes[i - 1], SkipListUtils.getNextIndexNode(memorySegment, offset, i));
    }
    for (int i = 1; i <= keySpace.prevIndexNodes.length; i++) {
        assertEquals(keySpace.prevIndexNodes[i - 1], SkipListUtils.getPrevIndexNode(memorySegment, offset, keySpace.level, i));
    }
    int keyDataOffset = SkipListUtils.getKeyDataOffset(keySpace.level);
    MemorySegment keyDataSegment = MemorySegmentFactory.wrap(keySpace.keyData);
    assertEquals(0, memorySegment.compare(keyDataSegment, offset + keyDataOffset, 0, keySpace.keyData.length));
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 78 with MemorySegment

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

the class SkipListUtilsTest method testValueSpacePutAndGet.

@Test
public void testValueSpacePutAndGet() {
    for (int i = 0; i < 100; i++) {
        int valueLen = ThreadLocalRandom.current().nextInt(100) + 1;
        ValueSpace valueSpace = createValueSpace(valueLen);
        int valueMetaLen = SkipListUtils.getValueMetaLen();
        int totalValueSpaceLen = valueMetaLen + valueLen;
        int offset = 100;
        MemorySegment segment = MemorySegmentFactory.allocateUnpooledSegment(totalValueSpaceLen + offset);
        putValueSpace(valueSpace, segment, offset);
        verifyGetValueSpace(valueSpace, segment, offset);
    }
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment) Test(org.junit.Test)

Example 79 with MemorySegment

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

the class CopyOnWriteSkipListStateMap method removeAndGetOld.

@Override
public S removeAndGetOld(K key, N namespace) {
    updateStat();
    MemorySegment keySegment = getKeySegment(key, namespace);
    int keyLen = keySegment.size();
    return removeNode(keySegment, 0, keyLen, true);
}
Also used : MemorySegment(org.apache.flink.core.memory.MemorySegment)

Example 80 with MemorySegment

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

the class CopyOnWriteSkipListStateMap method updateValueWithReplace.

/**
 * 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.
 */
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;
}
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