Search in sources :

Example 1 with BufferObjectDataOutput

use of com.hazelcast.internal.nio.BufferObjectDataOutput in project hazelcast by hazelcast.

the class MulticastService method send.

public void send(JoinMessage joinMessage) {
    if (!running) {
        return;
    }
    final BufferObjectDataOutput out = sendOutput;
    synchronized (sendLock) {
        try {
            out.writeByte(Packet.VERSION);
            out.writeObject(joinMessage);
            byte[] processed = outputProcessor != null ? outputProcessor.process(out.toByteArray()) : out.toByteArray();
            datagramPacketSend.setData(processed);
            multicastSocket.send(datagramPacketSend);
            out.clear();
        } catch (IOException e) {
            // usually catching EPERM errno
            // see https://github.com/hazelcast/hazelcast/issues/7198
            // For details about the causes look at the following discussion:
            // https://groups.google.com/forum/#!msg/comp.protocols.tcp-ip/Qou9Sfgr77E/mVQAPaeI-VUJ
            logger.warning("Sending multicast datagram failed. Exception message saying the operation is not permitted " + "usually means the underlying OS is not able to send packets at a given pace. " + "It can be caused by starting several hazelcast members in parallel when the members send " + "their join message nearly at the same time.", e);
        }
    }
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) IOException(java.io.IOException)

Example 2 with BufferObjectDataOutput

use of com.hazelcast.internal.nio.BufferObjectDataOutput 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)

Example 3 with BufferObjectDataOutput

use of com.hazelcast.internal.nio.BufferObjectDataOutput in project hazelcast by hazelcast.

the class Networking method createStreamPacketHeader.

public static byte[] createStreamPacketHeader(NodeEngine nodeEngine, long executionId, int destinationVertexId, int ordinal) {
    try (BufferObjectDataOutput output = createObjectDataOutput(nodeEngine, PACKET_HEADER_SIZE)) {
        output.writeLong(executionId);
        output.writeInt(destinationVertexId);
        output.writeInt(ordinal);
        return output.toByteArray();
    } catch (IOException e) {
        throw sneakyThrow(e);
    }
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) IOException(java.io.IOException)

Example 4 with BufferObjectDataOutput

use of com.hazelcast.internal.nio.BufferObjectDataOutput in project hazelcast by hazelcast.

the class ReceiverTaskletTest method pushObjects.

private void pushObjects(Object... objs) throws IOException {
    final BufferObjectDataOutput out = serService.createObjectDataOutput();
    // packet header
    out.writeLong(0);
    out.writeInt(0);
    out.writeInt(0);
    // the packet
    out.writeInt(objs.length);
    for (Object obj : objs) {
        out.writeObject(obj);
        // partition id
        out.writeInt(Math.abs(obj.hashCode()));
    }
    queue.add(out.toByteArray());
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput)

Example 5 with BufferObjectDataOutput

use of com.hazelcast.internal.nio.BufferObjectDataOutput in project hazelcast by hazelcast.

the class BufferPoolTest method takeOutputBuffer_whenPooledInstance.

// ======================= out ==========================================
@Test
public void takeOutputBuffer_whenPooledInstance() {
    BufferObjectDataOutput found1 = bufferPool.takeOutputBuffer();
    bufferPool.returnOutputBuffer(found1);
    BufferObjectDataOutput found2 = bufferPool.takeOutputBuffer();
    assertSame(found1, found2);
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

BufferObjectDataOutput (com.hazelcast.internal.nio.BufferObjectDataOutput)21 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)6 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 IOException (java.io.IOException)3 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 Address (com.hazelcast.cluster.Address)1 Connection (com.hazelcast.internal.nio.Connection)1 IOUtil.readData (com.hazelcast.internal.nio.IOUtil.readData)1 IOUtil.writeData (com.hazelcast.internal.nio.IOUtil.writeData)1 Data (com.hazelcast.internal.serialization.Data)1 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)1 BufferPool (com.hazelcast.internal.serialization.impl.bufferpool.BufferPool)1 CompactStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactStreamSerializerAdapter)1 CompactWithSchemaStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactWithSchemaStreamSerializerAdapter)1 ExecutionContext (com.hazelcast.jet.impl.execution.ExecutionContext)1 SenderReceiverKey (com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey)1