Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][proxy] Remove unnecessary executor callback; use assert #19670

Merged
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
[improve][proxy] Remove unnecessary executor callback; use assert
  • Loading branch information
michaeljmarshall committed Mar 1, 2023
commit 5617c8cfc1d0a3a82388e99a5060c158e11b1f20
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.pulsar.proxy.server;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
Expand Down Expand Up @@ -380,7 +379,7 @@ private synchronized void completeConnect() throws PulsarClientException {
}

private void handleBrokerConnected(DirectProxyHandler directProxyHandler, CommandConnected connected) {
checkState(ctx.executor().inEventLoop(), "This method should be called in the event loop");
assert ctx.executor().inEventLoop();
if (state == State.ProxyConnectingToBroker && ctx.channel().isOpen() && this.directProxyHandler == null) {
this.directProxyHandler = directProxyHandler;
state = State.ProxyConnectionToBroker;
Expand All @@ -401,18 +400,21 @@ private void handleBrokerConnected(DirectProxyHandler directProxyHandler, Comman
}

private void connectToBroker(InetSocketAddress brokerAddress) {
checkState(ctx.executor().inEventLoop(), "This method should be called in the event loop");
assert ctx.executor().inEventLoop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"assert" is not enabled in production
I am not sure that we enable Java assertion in tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I had opened #19653, but @lhotari pointed out that it is already enabled by surefire.

DirectProxyHandler directProxyHandler = new DirectProxyHandler(service, this);
directProxyHandler.connect(proxyToBrokerUrl, brokerAddress, protocolVersionToAdvertise);
}

public void brokerConnected(DirectProxyHandler directProxyHandler, CommandConnected connected) {
try {
final CommandConnected finalConnected = new CommandConnected().copyFrom(connected);
ctx.executor().execute(() -> handleBrokerConnected(directProxyHandler, finalConnected));
handleBrokerConnected(directProxyHandler, finalConnected);
} catch (RejectedExecutionException e) {
LOG.error("Event loop was already closed. Closing broker connection.", e);
directProxyHandler.close();
} catch (AssertionError e) {
LOG.error("Failed assertion, closing direct proxy handler.", e);
directProxyHandler.close();
}
}

Expand Down