Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/java/org/apache/cassandra/net/AbstractMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.slf4j.LoggerFactory;

import org.apache.cassandra.concurrent.ManyToOneConcurrentLinkedQueue;
import org.apache.cassandra.metrics.ClientMetrics;
import org.apache.cassandra.net.FrameDecoder.CorruptFrame;
import org.apache.cassandra.net.FrameDecoder.Frame;
import org.apache.cassandra.net.FrameDecoder.FrameProcessor;
Expand Down Expand Up @@ -292,7 +291,8 @@ private void onGlobalReserveCapacityRegained(Limit globalReserve, long elapsedNa
onReserveCapacityRegained(endpointReserveCapacity, globalReserve, elapsedNanos);
}

private void onReserveCapacityRegained(Limit endpointReserve, Limit globalReserve, long elapsedNanos)
@VisibleForTesting
void onReserveCapacityRegained(Limit endpointReserve, Limit globalReserve, long elapsedNanos)
{
if (isClosed)
return;
Expand All @@ -314,7 +314,7 @@ private void onReserveCapacityRegained(Limit endpointReserve, Limit globalReserv
decoder.reactivate();

if (decoder.isActive())
ClientMetrics.instance.unpauseConnection();
onConnectionUnpaused();
}
}
catch (Throwable t)
Expand All @@ -323,6 +323,10 @@ private void onReserveCapacityRegained(Limit endpointReserve, Limit globalReserv
}
}

protected void onConnectionUnpaused()
{
}

protected abstract void fatalExceptionCaught(Throwable t);

// return true if the handler should be reactivated - if no new hurdles were encountered,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public boolean process(FrameDecoder.Frame frame) throws IOException
return super.process(frame);
}

@Override
protected void onConnectionUnpaused()
{
ClientMetrics.instance.unpauseConnection();
}

/**
* Checks limits on bytes in flight and the request rate limiter (if enabled), then takes one of three actions:
*
Expand Down
86 changes: 86 additions & 0 deletions test/unit/org/apache/cassandra/net/AbstractMessageHandlerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.net;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;

import io.netty.channel.Channel;
import io.netty.channel.EventLoop;
import org.junit.Test;

import org.apache.cassandra.net.ResourceLimits.Basic;
import org.apache.cassandra.net.ResourceLimits.Limit;

import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class AbstractMessageHandlerTest
{
@Test
public void internodeReactivationDoesNotUseUninitializedClientMetrics() throws IOException
{
FrameDecoder decoder = mock(FrameDecoder.class);
when(decoder.isActive()).thenReturn(true);

EventLoop eventLoop = mock(EventLoop.class);
when(eventLoop.inEventLoop()).thenReturn(true);
Channel channel = mock(Channel.class);
when(channel.eventLoop()).thenReturn(eventLoop);

Limit endpointReserve = new Basic(1);
Limit globalReserve = new Basic(1);
AtomicReference<Throwable> failure = new AtomicReference<>();

InboundMessageHandler handler = new InboundMessageHandler(decoder,
ConnectionType.LARGE_MESSAGES,
channel,
null,
null,
MessagingService.current_version,
1,
1,
endpointReserve,
globalReserve,
AbstractMessageHandler.WaitQueue.endpoint(endpointReserve),
AbstractMessageHandler.WaitQueue.global(globalReserve),
ignored -> {},
null,
null)
{
@Override
protected boolean processUpToOneMessage(Limit endpoint, Limit global)
{
return true;
}

@Override
protected void fatalExceptionCaught(Throwable cause)
{
failure.set(cause);
}
};

handler.onReserveCapacityRegained(endpointReserve, globalReserve, 0);

assertNull(failure.get());
verify(decoder).reactivate();
}
}