Skip to content

Commit 351876e

Browse files
authored
Merge pull request #1 from alibaba/develop
sync from fescar
2 parents a50f959 + 33275c7 commit 351876e

File tree

11 files changed

+45
-45
lines changed

11 files changed

+45
-45
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ target
88
/logs
99
*.iml
1010
*.class
11+
/distribution/bin
12+
/distribution/conf
13+
/distribution/lib

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ Contributors are welcomed to join the FEATS project. Please check [CONTRIBUTING]
8383

8484
* [Twitter](https://twitter.com/fescar): TBD. Follow along for latest FESCAR news on Twitter.
8585
* Email Group:
86-
* TBD: FESCAR usage general discussion.
87-
* TBD: FESCAR developer discussion (APIs, feature design, etc).
88-
* TBD: Commits notice, very high frequency.
86+
* [email protected]: FESCAR developer discussion (APIs, feature design, etc).
8987

9088
**Dingtalk**
9189

config/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@
4040
<groupId>${project.groupId}</groupId>
4141
<artifactId>fescar-common</artifactId>
4242
</dependency>
43-
<dependency>
44-
<groupId>io.netty</groupId>
45-
<artifactId>netty-transport-native-epoll</artifactId>
46-
<classifier>linux-x86_64</classifier>
47-
</dependency>
48-
<dependency>
49-
<groupId>io.netty</groupId>
50-
<artifactId>netty-transport-native-kqueue</artifactId>
51-
<classifier>osx-x86_64</classifier>
52-
</dependency>
5343
<dependency>
5444
<groupId>org.slf4j</groupId>
5545
<artifactId>slf4j-api</artifactId>

core/src/main/java/com/alibaba/fescar/core/rpc/netty/AbstractRpcRemotingClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ protected Channel getNewChannel(InetSocketAddress address) {
231231
try {
232232
f.await(this.nettyClientConfig.getConnectTimeoutMillis(), TimeUnit.MILLISECONDS);
233233
if (f.isCancelled()) {
234-
throw new FrameworkException("connect cancelled, can not connect to fescar-server.");
234+
throw new FrameworkException(f.cause(), "connect cancelled, can not connect to fescar-server.");
235235
} else if (!f.isSuccess()) {
236-
throw new FrameworkException("connect failed, can not connect to fescar-server.");
236+
throw new FrameworkException(f.cause(), "connect failed, can not connect to fescar-server.");
237237
} else {
238238
channel = f.channel();
239239
}

core/src/main/java/com/alibaba/fescar/core/rpc/netty/AbstractRpcRemotingServer.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import java.net.InetSocketAddress;
2020
import java.util.concurrent.ThreadPoolExecutor;
2121

22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
2225
import com.alibaba.fescar.common.thread.NamedThreadFactory;
2326
import com.alibaba.fescar.core.rpc.RemotingServer;
2427

@@ -34,8 +37,6 @@
3437
import io.netty.channel.socket.SocketChannel;
3538
import io.netty.handler.timeout.IdleStateHandler;
3639
import io.netty.util.concurrent.DefaultEventExecutorGroup;
37-
import org.slf4j.Logger;
38-
import org.slf4j.LoggerFactory;
3940

4041
/**
4142
* The type Rpc remoting server.
@@ -56,6 +57,11 @@ public abstract class AbstractRpcRemotingServer extends AbstractRpcRemoting impl
5657
private int listenPort;
5758

5859
public void setListenPort(int listenPort) {
60+
61+
if(listenPort <= 0) {
62+
throw new IllegalArgumentException("listen port: " + listenPort +" is invalid!");
63+
}
64+
5965
this.listenPort = listenPort;
6066
}
6167

@@ -84,21 +90,24 @@ public AbstractRpcRemotingServer(final NettyServerConfig nettyServerConfig,
8490
super(messageExecutor);
8591
this.serverBootstrap = new ServerBootstrap();
8692
this.nettyServerConfig = nettyServerConfig;
87-
this.eventLoopGroupBoss = new NioEventLoopGroup(nettyServerConfig.getBossThreadSize(),
88-
new NamedThreadFactory(nettyServerConfig.getBossThreadPrefix(), nettyServerConfig.getBossThreadSize()));
8993
if (NettyServerConfig.enableEpoll()) {
94+
this.eventLoopGroupBoss = new EpollEventLoopGroup(nettyServerConfig.getBossThreadSize(),
95+
new NamedThreadFactory(nettyServerConfig.getBossThreadPrefix(), nettyServerConfig.getBossThreadSize()));
9096
this.eventLoopGroupWorker = new EpollEventLoopGroup(nettyServerConfig.getServerWorkerThreads(),
9197
new NamedThreadFactory(nettyServerConfig.getWorkerThreadPrefix(),
9298
nettyServerConfig.getServerWorkerThreads()));
9399
} else {
100+
this.eventLoopGroupBoss = new NioEventLoopGroup(nettyServerConfig.getBossThreadSize(),
101+
new NamedThreadFactory(nettyServerConfig.getBossThreadPrefix(), nettyServerConfig.getBossThreadSize()));
94102
this.eventLoopGroupWorker = new NioEventLoopGroup(nettyServerConfig.getServerWorkerThreads(),
95103
new NamedThreadFactory(nettyServerConfig.getWorkerThreadPrefix(),
96104
nettyServerConfig.getServerWorkerThreads()));
97105
}
98106
if (null != handlers) {
99107
channelHandlers = handlers;
100108
}
101-
109+
// init listenPort in constructor so that getListenPort() will always get the exact port
110+
setListenPort(nettyServerConfig.getDefaultListenPort());
102111
}
103112

104113
@Override
@@ -107,9 +116,7 @@ public void start() {
107116
nettyServerConfig.getServerWorkerThreads(),
108117
new NamedThreadFactory(nettyServerConfig.getExecutorThreadPrefix(),
109118
nettyServerConfig.getServerWorkerThreads()));
110-
if (listenPort == 0) {
111-
listenPort = nettyServerConfig.getDefaultListenPort();
112-
}
119+
113120
this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupWorker)
114121
.channel(nettyServerConfig.SERVER_CHANNEL_CLAZZ)
115122
.option(ChannelOption.SO_BACKLOG, nettyServerConfig.getSoBackLogSize())

pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,6 @@
127127
<artifactId>netty-all</artifactId>
128128
<version>${netty4.version}</version>
129129
</dependency>
130-
<dependency>
131-
<groupId>io.netty</groupId>
132-
<artifactId>netty-transport-native-epoll</artifactId>
133-
<version>${netty4.version}</version>
134-
<classifier>linux-x86_64</classifier>
135-
</dependency>
136-
<dependency>
137-
<groupId>io.netty</groupId>
138-
<artifactId>netty-transport-native-kqueue</artifactId>
139-
<version>${netty4.version}</version>
140-
<classifier>osx-x86_64</classifier>
141-
</dependency>
142130
<dependency>
143131
<groupId>com.alibaba</groupId>
144132
<artifactId>fastjson</artifactId>

server/src/main/java/com/alibaba/fescar/server/Server.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,22 @@ public class Server {
3434

3535
public static void main(String[] args) throws IOException {
3636
RpcServer rpcServer = new RpcServer(WORKING_THREADS);
37+
38+
int port = 8091;
39+
if (args.length == 0) {
40+
rpcServer.setListenPort(port);
41+
}
3742

3843
if (args.length > 0) {
39-
int port = Integer.parseInt(args[0]);
44+
try {
45+
port = Integer.parseInt(args[0]);
46+
} catch (NumberFormatException e) {
47+
System.err.println("Usage: sh fescar-server.sh $LISTEN_PORT $PATH_FOR_PERSISTENT_DATA");
48+
System.exit(0);
49+
}
4050
rpcServer.setListenPort(port);
41-
4251
}
52+
4353
String dataDir = null;
4454
if (args.length > 1) {
4555
dataDir = args[1];

server/src/main/java/com/alibaba/fescar/server/store/TransactionWriteStore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.nio.ByteBuffer;
2020

21+
import com.alibaba.fescar.common.exception.ShouldNeverHappenException;
2122
import com.alibaba.fescar.server.session.BranchSession;
2223
import com.alibaba.fescar.server.session.GlobalSession;
2324
import com.alibaba.fescar.server.store.TransactionStoreManager.LogOperation;
@@ -124,7 +125,8 @@ private SessionStorable getSessionInstanceByOperation(LogOperation logOperation)
124125
case BRANCH_REMOVE:
125126
sessionStorable = new BranchSession();
126127
break;
127-
128+
default:
129+
throw new ShouldNeverHappenException("incorrect logOperation");
128130
}
129131
return sessionStorable;
130132
}

spring/src/main/java/com/alibaba/fescar/spring/annotation/GlobalTransactional.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@
3737
* Given name of the global transaction instance.
3838
* @return Given name.
3939
*/
40-
String name() default "default";
40+
String name() default "";
4141

4242
}

spring/src/main/java/com/alibaba/fescar/spring/annotation/GlobalTransactionalInterceptor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.lang.reflect.Method;
2020

2121
import com.alibaba.fescar.common.exception.ShouldNeverHappenException;
22+
import com.alibaba.fescar.common.util.StringUtils;
2223
import com.alibaba.fescar.tm.api.DefaultFailureHandlerImpl;
2324
import com.alibaba.fescar.tm.api.FailureHandler;
2425
import com.alibaba.fescar.tm.api.TransactionalExecutor;
@@ -61,8 +62,9 @@ public int timeout() {
6162

6263
@Override
6364
public String name() {
64-
if (anno.name() != null) {
65-
return anno.name();
65+
String name = anno.name();
66+
if (!StringUtils.isEmpty(name)) {
67+
return name;
6668
}
6769
return formatMethod(methodInvocation.getMethod());
6870
}

0 commit comments

Comments
 (0)