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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations