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

[dubbo-2029]: upgrade netty4 to the latest release and make it the default option for transporter #2049

Merged
merged 2 commits into from
Jul 9, 2018
Merged
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
2 changes: 1 addition & 1 deletion dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<spring_version>4.3.16.RELEASE</spring_version>
<javassist_version>3.20.0-GA</javassist_version>
<netty_version>3.2.5.Final</netty_version>
<netty4_version>4.0.35.Final</netty4_version>
<netty4_version>4.1.25.Final</netty4_version>
<mina_version>1.1.7</mina_version>
<grizzly_version>2.1.4</grizzly_version>
<httpclient_version>4.5.3</httpclient_version>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-config/dubbo-config-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-config/dubbo-config-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
<artifactId>dubbo-remoting-netty4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
<artifactId>dubbo-remoting-netty4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-monitor/dubbo-monitor-default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-registry/dubbo-registry-default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class NettyTransporter implements Transporter {

public static final String NAME = "netty";
public static final String NAME = "netty3";

@Override
public Server bind(URL url, ChannelHandler listener) throws RemotingException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
netty=org.apache.dubbo.remoting.transport.netty.NettyTransporter
netty3=org.apache.dubbo.remoting.transport.netty.NettyTransporter
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void after() throws Exception {

@Test
public void testServerHeartbeat() throws Exception {
URL serverURL = URL.valueOf("header://localhost:55555");
URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty3");
serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000);
TestHeartbeatHandler handler = new TestHeartbeatHandler();
server = Exchangers.bind(serverURL, handler);
Expand All @@ -74,7 +74,7 @@ public void testServerHeartbeat() throws Exception {

@Test
public void testHeartbeat() throws Exception {
URL serverURL = URL.valueOf("header://localhost:55555");
URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty3");
serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000);
TestHeartbeatHandler handler = new TestHeartbeatHandler();
server = Exchangers.bind(serverURL, handler);
Expand All @@ -91,7 +91,7 @@ public void testHeartbeat() throws Exception {
@Test
public void testClientHeartbeat() throws Exception {
FakeChannelHandlers.setTestingChannelHandlers();
URL serverURL = URL.valueOf("header://localhost:55555");
URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty3");
TestHeartbeatHandler handler = new TestHeartbeatHandler();
server = Exchangers.bind(serverURL, handler);
System.out.println("Server bind successfully");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testReconnect() throws RemotingException, InterruptedException {
public void testReconnectWarnLog() throws RemotingException, InterruptedException {
int port = NetUtils.getAvailablePort();
DubboAppender.doStart();
String url = "exchange://127.0.0.2:" + port + "/client.reconnect.test?check=false&"
String url = "exchange://127.0.0.2:" + port + "/client.reconnect.test?check=false&client=netty3&"
+ Constants.RECONNECT_KEY + "=" + 1; //1ms reconnect, ensure that there is enough frequency to reconnect
try {
Exchangers.connect(url);
Expand All @@ -97,12 +97,12 @@ public void testReconnectWarnLog() throws RemotingException, InterruptedExceptio
}

public Client startClient(int port, int reconnectPeriod) throws RemotingException {
final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?check=false&" + Constants.RECONNECT_KEY + "=" + reconnectPeriod;
final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?check=false&client=netty3&" + Constants.RECONNECT_KEY + "=" + reconnectPeriod;
return Exchangers.connect(url);
}

public Server startServer(int port) throws RemotingException {
final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test";
final String url = "exchange://127.0.0.1:" + port + "/client.reconnect.test?server=netty3";
return Exchangers.bind(url, new HandlerAdapter());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testGetTransportNull() {

@Test
public void testGetTransport3() {
String name = "netty";
String name = "netty3";
assertEquals(NettyTransporter.class, ExtensionLoader.getExtensionLoader(Transporter.class).getExtension(name).getClass());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class NettyClientTest {

@BeforeClass
public static void setUp() throws Exception {
server = Exchangers.bind(URL.valueOf("exchange://localhost:10001?server=netty"), new TelnetServerHandler());
server = Exchangers.bind(URL.valueOf("exchange://localhost:10001?server=netty3"), new TelnetServerHandler());
}

@AfterClass
Expand All @@ -52,15 +52,15 @@ public static void tearDown() throws Exception {
}

public static void main(String[] args) throws RemotingException, InterruptedException {
ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty&heartbeat=1000"));
ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://10.20.153.10:20880?client=netty3&heartbeat=1000"));
Thread.sleep(60 * 1000 * 50);
}

@Test
public void testClientClose() throws Exception {
List<ExchangeChannel> clients = new ArrayList<ExchangeChannel>(100);
for (int i = 0; i < 100; i++) {
ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://localhost:10001?client=netty"));
ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://localhost:10001?client=netty3"));
Thread.sleep(5);
clients.add(client);
}
Expand All @@ -73,7 +73,7 @@ public void testClientClose() throws Exception {
@Test
public void testServerClose() throws Exception {
for (int i = 0; i < 100; i++) {
Server aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + (5000 + i) + "?client=netty"), new TelnetServerHandler());
Server aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + (5000 + i) + "?server=netty3"), new TelnetServerHandler());
aServer.close();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
public class NettyClientToServerTest extends ClientToServerTest {

protected ExchangeServer newServer(int port, Replier<?> receiver) throws RemotingException {
return Exchangers.bind(URL.valueOf("exchange://localhost:" + port + "?server=netty"), receiver);
return Exchangers.bind(URL.valueOf("exchange://localhost:" + port + "?server=netty3"), receiver);
}

protected ExchangeChannel newClient(int port) throws RemotingException {
return Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?client=netty"));
return Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?client=netty3"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static void setUp() throws Exception {
//int port = (int) (1000 * Math.random() + 10000);
int port = 10001;
System.out.println(port);
server = Exchangers.bind(URL.valueOf("telnet://0.0.0.0:" + port + "?server=netty"), new TelnetServerHandler());
client = Exchangers.connect(URL.valueOf("telnet://127.0.0.1:" + port + "?client=netty"), new TelnetClientHandler());
server = Exchangers.bind(URL.valueOf("telnet://0.0.0.0:" + port + "?server=netty3"), new TelnetServerHandler());
client = Exchangers.connect(URL.valueOf("telnet://127.0.0.1:" + port + "?client=netty3"), new TelnetClientHandler());
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package org.apache.dubbo.remoting.transport.netty4;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.ChannelHandler;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import org.apache.dubbo.remoting.exchange.Request;
import org.apache.dubbo.remoting.exchange.Response;

/**
* NettyClientHandler
Expand Down Expand Up @@ -81,7 +84,18 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
super.write(ctx, msg, promise);
NettyChannel channel = NettyChannel.getOrAddChannel(ctx.channel(), url, handler);
try {
handler.sent(channel, msg);
// if error happens from write, mock a BAD_REQUEST response so that invoker can return immediately without
// waiting until timeout. FIXME: not sure if this is the right approach, but exceptionCaught doesn't work
// as expected.
if (promise.cause() != null && msg instanceof Request) {
Request request = (Request) msg;
Response response = new Response(request.getId(), request.getVersion());
response.setStatus(Response.BAD_REQUEST);
response.setErrorMessage(StringUtils.toString(promise.cause()));
handler.received(channel, response);
} else {
handler.sent(channel, msg);
}
} finally {
NettyChannel.removeChannelIfDisconnected(ctx.channel());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class NettyTransporter implements Transporter {

public static final String NAME = "netty4";
public static final String NAME = "netty";

@Override
public Server bind(URL url, ChannelHandler listener) throws RemotingException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
netty4=org.apache.dubbo.remoting.transport.netty4.NettyTransporter
netty4=org.apache.dubbo.remoting.transport.netty4.NettyTransporter
netty=org.apache.dubbo.remoting.transport.netty4.NettyTransporter
2 changes: 1 addition & 1 deletion dubbo-remoting/dubbo-remoting-p2p/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
Expand Down
12 changes: 3 additions & 9 deletions dubbo-rpc/dubbo-rpc-dubbo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,13 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-mina</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-rpc/dubbo-rpc-thrift/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
<artifactId>dubbo-remoting-netty4</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
Expand Down