Search in sources :

Example 1 with SenderReceiverKey

use of com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey in project hazelcast by hazelcast.

the class Networking method handleFlowControlPacket.

private void handleFlowControlPacket(Address fromAddr, byte[] packet) throws IOException {
    BufferObjectDataInput input = createObjectDataInput(nodeEngine, packet);
    for (; ; ) {
        final long executionId = input.readLong();
        if (executionId == TERMINAL_EXECUTION_ID) {
            break;
        }
        final Map<SenderReceiverKey, SenderTasklet> senderMap = jobExecutionService.getSenderMap(executionId);
        for (; ; ) {
            final int vertexId = input.readInt();
            if (vertexId == TERMINAL_VERTEX_ID) {
                break;
            }
            int ordinal = input.readInt();
            int sendSeqLimitCompressed = input.readInt();
            final SenderTasklet t;
            if (senderMap != null && (t = senderMap.get(new SenderReceiverKey(vertexId, ordinal, fromAddr))) != null) {
                t.setSendSeqLimitCompressed(sendSeqLimitCompressed);
            }
        }
    }
}
Also used : SenderReceiverKey(com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey) SenderTasklet(com.hazelcast.jet.impl.execution.SenderTasklet) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 2 with SenderReceiverKey

use of com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey in project hazelcast by hazelcast.

the class Networking method createFlowControlPacket.

private Map<Address, byte[]> createFlowControlPacket() throws IOException {
    class MemberData {

        final BufferObjectDataOutput output = createObjectDataOutput(nodeEngine, lastFlowPacketSize);

        final Connection memberConnection;

        Long startedExecutionId;

        MemberData(Address address) {
            memberConnection = getMemberConnection(nodeEngine, address);
        }
    }
    Map<Address, MemberData> res = new HashMap<>();
    for (ExecutionContext execCtx : jobExecutionService.getExecutionContexts()) {
        Map<SenderReceiverKey, ReceiverTasklet> receiverMap = execCtx.receiverMap();
        if (receiverMap == null) {
            continue;
        }
        for (Entry<SenderReceiverKey, ReceiverTasklet> en : receiverMap.entrySet()) {
            assert !en.getKey().address.equals(nodeEngine.getThisAddress());
            MemberData md = res.computeIfAbsent(en.getKey().address, address -> new MemberData(address));
            if (md.startedExecutionId == null) {
                md.startedExecutionId = execCtx.executionId();
                md.output.writeLong(md.startedExecutionId);
            }
            assert en.getKey().vertexId != TERMINAL_VERTEX_ID;
            md.output.writeInt(en.getKey().vertexId);
            md.output.writeInt(en.getKey().ordinal);
            md.output.writeInt(en.getValue().updateAndGetSendSeqLimitCompressed(md.memberConnection));
        }
        for (MemberData md : res.values()) {
            if (md.startedExecutionId != null) {
                // write a mark to terminate values for an execution
                md.output.writeInt(TERMINAL_VERTEX_ID);
                md.startedExecutionId = null;
            }
        }
    }
    for (MemberData md : res.values()) {
        assert md.output.position() > 0;
        // write a mark to terminate all executions
        // Execution IDs are generated using Flake ID generator and those are >0 normally, we
        // use MIN_VALUE as a terminator.
        md.output.writeLong(TERMINAL_EXECUTION_ID);
    }
    // finalize the packets
    int maxSize = 0;
    for (Entry<Address, MemberData> entry : res.entrySet()) {
        byte[] data = entry.getValue().output.toByteArray();
        // we break type safety to avoid creating a new map, we replace the values to a different type in place
        @SuppressWarnings({ "unchecked", "rawtypes" }) Entry<Address, byte[]> entry1 = (Entry) entry;
        entry1.setValue(data);
        if (data.length > maxSize) {
            maxSize = data.length;
        }
    }
    lastFlowPacketSize = maxSize;
    return (Map) res;
}
Also used : Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) ImdgUtil.getMemberConnection(com.hazelcast.jet.impl.util.ImdgUtil.getMemberConnection) Connection(com.hazelcast.internal.nio.Connection) ReceiverTasklet(com.hazelcast.jet.impl.execution.ReceiverTasklet) BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) Entry(java.util.Map.Entry) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext) SenderReceiverKey(com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SenderReceiverKey (com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey)2 Address (com.hazelcast.cluster.Address)1 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)1 BufferObjectDataOutput (com.hazelcast.internal.nio.BufferObjectDataOutput)1 Connection (com.hazelcast.internal.nio.Connection)1 ExecutionContext (com.hazelcast.jet.impl.execution.ExecutionContext)1 ReceiverTasklet (com.hazelcast.jet.impl.execution.ReceiverTasklet)1 SenderTasklet (com.hazelcast.jet.impl.execution.SenderTasklet)1 ImdgUtil.getMemberConnection (com.hazelcast.jet.impl.util.ImdgUtil.getMemberConnection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1