Search in sources :

Example 1 with IVersionedSerializer

use of org.apache.cassandra.io.IVersionedSerializer in project cassandra by apache.

the class MessageIn method read.

public static <T2> MessageIn<T2> read(DataInputPlus in, int version, int id, long constructionTime) throws IOException {
    InetAddress from = CompactEndpointSerializationHelper.deserialize(in);
    MessagingService.Verb verb = MessagingService.Verb.fromId(in.readInt());
    int parameterCount = in.readInt();
    Map<String, byte[]> parameters;
    if (parameterCount == 0) {
        parameters = Collections.emptyMap();
    } else {
        ImmutableMap.Builder<String, byte[]> builder = ImmutableMap.builder();
        for (int i = 0; i < parameterCount; i++) {
            String key = in.readUTF();
            byte[] value = new byte[in.readInt()];
            in.readFully(value);
            builder.put(key, value);
        }
        parameters = builder.build();
    }
    int payloadSize = in.readInt();
    IVersionedSerializer<T2> serializer = (IVersionedSerializer<T2>) MessagingService.verbSerializers.get(verb);
    if (serializer instanceof MessagingService.CallbackDeterminedSerializer) {
        CallbackInfo callback = MessagingService.instance().getRegisteredCallback(id);
        if (callback == null) {
            // reply for expired callback.  we'll have to skip it.
            in.skipBytesFully(payloadSize);
            return null;
        }
        serializer = (IVersionedSerializer<T2>) callback.serializer;
    }
    if (payloadSize == 0 || serializer == null)
        return create(from, null, parameters, verb, version, constructionTime);
    T2 payload = serializer.deserialize(in, version);
    return MessageIn.create(from, payload, parameters, verb, version, constructionTime);
}
Also used : IVersionedSerializer(org.apache.cassandra.io.IVersionedSerializer) ImmutableMap(com.google.common.collect.ImmutableMap) InetAddress(java.net.InetAddress)

Example 2 with IVersionedSerializer

use of org.apache.cassandra.io.IVersionedSerializer in project cassandra by apache.

the class ConnectionTest method testInsufficientSpace.

@Test
public void testInsufficientSpace() throws Throwable {
    test(new Settings(null).outbound(settings -> settings.withApplicationReserveSendQueueCapacityInBytes(1 << 15, new ResourceLimits.Concurrent(1 << 16)).withApplicationSendQueueCapacityInBytes(1 << 16)), (inbound, outbound, endpoint) -> {
        CountDownLatch done = new CountDownLatch(1);
        Message<?> message = Message.out(Verb._TEST_1, new Object());
        MessagingService.instance().callbacks.addWithExpiration(new RequestCallback() {

            @Override
            public void onFailure(InetAddressAndPort from, RequestFailureReason failureReason) {
                done.countDown();
            }

            @Override
            public boolean invokeOnFailure() {
                return true;
            }

            @Override
            public void onResponse(Message msg) {
                throw new IllegalStateException();
            }
        }, message, endpoint);
        AtomicInteger delivered = new AtomicInteger();
        unsafeSetSerializer(Verb._TEST_1, () -> new IVersionedSerializer<Object>() {

            public void serialize(Object o, DataOutputPlus out, int version) throws IOException {
                for (int i = 0; i <= 4 << 16; i += 8L) out.writeLong(1L);
            }

            public Object deserialize(DataInputPlus in, int version) throws IOException {
                in.skipBytesFully(4 << 16);
                return null;
            }

            public long serializedSize(Object o, int version) {
                return 4 << 16;
            }
        });
        unsafeSetHandler(Verb._TEST_1, () -> msg -> delivered.incrementAndGet());
        outbound.enqueue(message);
        Assert.assertTrue(done.await(10, SECONDS));
        Assert.assertEquals(0, delivered.get());
        check(outbound).submitted(1).sent(0, 0).pending(0, 0).overload(1, message.serializedSize(current_version)).expired(0, 0).error(0, 0).check();
        check(inbound).received(0, 0).processed(0, 0).pending(0, 0).expired(0, 0).error(0, 0).check();
    });
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) CommitLog(org.apache.cassandra.db.commitlog.CommitLog) Random(java.util.Random) EncryptionOptions(org.apache.cassandra.config.EncryptionOptions) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) ChannelPromise(io.netty.channel.ChannelPromise) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LARGE_MESSAGE_THRESHOLD(org.apache.cassandra.net.OutboundConnections.LARGE_MESSAGE_THRESHOLD) Map(java.util.Map) After(org.junit.After) IVersionedAsymmetricSerializer(org.apache.cassandra.io.IVersionedAsymmetricSerializer) DataOutputPlus(org.apache.cassandra.io.util.DataOutputPlus) UnknownColumnException(org.apache.cassandra.exceptions.UnknownColumnException) ToLongFunction(java.util.function.ToLongFunction) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) VERSION_40(org.apache.cassandra.net.MessagingService.VERSION_40) LZ4(org.apache.cassandra.net.OutboundConnectionSettings.Framing.LZ4) AfterClass(org.junit.AfterClass) Global.approxTime(org.apache.cassandra.utils.MonotonicClock.Global.approxTime) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) FBUtilities(org.apache.cassandra.utils.FBUtilities) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) SMALL_MESSAGES(org.apache.cassandra.net.ConnectionType.SMALL_MESSAGES) Executors(java.util.concurrent.Executors) Sets(com.google.common.collect.Sets) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ConnectionUtils(org.apache.cassandra.net.ConnectionUtils) VERSION_30(org.apache.cassandra.net.MessagingService.VERSION_30) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) NoPayload.noPayload(org.apache.cassandra.net.NoPayload.noPayload) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) BeforeClass(org.junit.BeforeClass) Config(org.apache.cassandra.config.Config) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ImmutableList(com.google.common.collect.ImmutableList) ByteBuf(io.netty.buffer.ByteBuf) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IVersionedSerializer(org.apache.cassandra.io.IVersionedSerializer) ExecutorService(java.util.concurrent.ExecutorService) VERSION_3014(org.apache.cassandra.net.MessagingService.VERSION_3014) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) LARGE_MESSAGES(org.apache.cassandra.net.ConnectionType.LARGE_MESSAGES) IOException(java.io.IOException) Test(org.junit.Test) MessagingService.current_version(org.apache.cassandra.net.MessagingService.current_version) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Assert(org.junit.Assert) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) DataOutputPlus(org.apache.cassandra.io.util.DataOutputPlus) Test(org.junit.Test)

Aggregations

IVersionedSerializer (org.apache.cassandra.io.IVersionedSerializer)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)1 ChannelPromise (io.netty.channel.ChannelPromise)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1