Skip to content

Commit e24693a

Browse files
author
Sunny Jiao
committed
update
1 parent b54aed3 commit e24693a

File tree

4 files changed

+103
-19
lines changed

4 files changed

+103
-19
lines changed

framework/src/main/java/org/tron/common/application/RpcService.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.grpc.netty.NettyServerBuilder;
2020
import io.grpc.protobuf.services.ProtoReflectionService;
2121
import java.util.concurrent.CompletableFuture;
22+
import java.util.concurrent.ExecutorService;
2223
import java.util.concurrent.TimeUnit;
2324
import lombok.extern.slf4j.Slf4j;
2425
import org.springframework.beans.factory.annotation.Autowired;
@@ -34,6 +35,7 @@
3435
public abstract class RpcService extends AbstractService {
3536

3637
private Server apiServer;
38+
private ExecutorService executorService;
3739
protected String executorName;
3840

3941
@Autowired
@@ -58,7 +60,24 @@ public void innerStart() throws Exception {
5860
@Override
5961
public void innerStop() throws Exception {
6062
if (this.apiServer != null) {
61-
this.apiServer.shutdown().awaitTermination(5, TimeUnit.SECONDS);
63+
this.apiServer.shutdown();
64+
try {
65+
if (!this.apiServer.awaitTermination(5, TimeUnit.SECONDS)) {
66+
logger.warn("gRPC server did not shutdown gracefully, forcing shutdown");
67+
this.apiServer.shutdownNow();
68+
}
69+
} catch (InterruptedException e) {
70+
logger.warn("Interrupted while waiting for gRPC server shutdown", e);
71+
this.apiServer.shutdownNow();
72+
Thread.currentThread().interrupt();
73+
}
74+
}
75+
76+
// Close executor
77+
if (this.executorService != null) {
78+
ExecutorServiceManager.shutdownAndAwaitTermination(
79+
this.executorService, this.executorName);
80+
this.executorService = null;
6281
}
6382
}
6483

@@ -76,9 +95,9 @@ protected NettyServerBuilder initServerBuilder() {
7695
NettyServerBuilder serverBuilder = NettyServerBuilder.forPort(this.port);
7796
CommonParameter parameter = Args.getInstance();
7897
if (parameter.getRpcThreadNum() > 0) {
79-
serverBuilder = serverBuilder
80-
.executor(ExecutorServiceManager.newFixedThreadPool(
81-
this.executorName, parameter.getRpcThreadNum()));
98+
this.executorService = ExecutorServiceManager.newFixedThreadPool(
99+
this.executorName, parameter.getRpcThreadNum());
100+
serverBuilder = serverBuilder.executor(this.executorService);
82101
}
83102
// Set configs from config.conf or default value
84103
serverBuilder

framework/src/test/java/org/tron/core/services/RpcApiServicesTest.java

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.grpc.ManagedChannelBuilder;
1212
import java.io.IOException;
1313
import java.util.Objects;
14+
import java.util.concurrent.ExecutorService;
1415
import java.util.concurrent.TimeUnit;
1516
import org.junit.AfterClass;
1617
import org.junit.Assert;
@@ -53,6 +54,7 @@
5354
import org.tron.common.application.Application;
5455
import org.tron.common.application.ApplicationFactory;
5556
import org.tron.common.application.TronApplicationContext;
57+
import org.tron.common.es.ExecutorServiceManager;
5658
import org.tron.common.utils.ByteArray;
5759
import org.tron.common.utils.PublicMethod;
5860
import org.tron.common.utils.Sha256Hash;
@@ -140,6 +142,9 @@ public class RpcApiServicesTest {
140142
private static ByteString ivk;
141143
private static ByteString d;
142144

145+
private static ExecutorService executorService;
146+
private static final String executorName = "rpc-test-executor";
147+
143148
@BeforeClass
144149
public static void init() throws IOException {
145150
Args.setParam(new String[] {"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF);
@@ -163,16 +168,22 @@ public static void init() throws IOException {
163168
String pBFTNode = String.format("%s:%d", Constant.LOCAL_HOST,
164169
getInstance().getRpcOnPBFTPort());
165170

171+
executorService = ExecutorServiceManager.newFixedThreadPool(
172+
executorName, 3);
173+
166174
channelFull = ManagedChannelBuilder.forTarget(fullNode)
167175
.usePlaintext()
176+
.executor(executorService)
168177
.intercept(new TimeoutInterceptor(5000))
169178
.build();
170179
channelPBFT = ManagedChannelBuilder.forTarget(pBFTNode)
171180
.usePlaintext()
181+
.executor(executorService)
172182
.intercept(new TimeoutInterceptor(5000))
173183
.build();
174184
channelSolidity = ManagedChannelBuilder.forTarget(solidityNode)
175185
.usePlaintext()
186+
.executor(executorService)
176187
.intercept(new TimeoutInterceptor(5000))
177188
.build();
178189
context = new TronApplicationContext(DefaultConfig.class);
@@ -197,19 +208,47 @@ public static void init() throws IOException {
197208

198209
@AfterClass
199210
public static void destroy() {
200-
if (channelFull != null) {
201-
channelFull.shutdownNow();
202-
}
203-
if (channelPBFT != null) {
204-
channelPBFT.shutdownNow();
205-
}
206-
if (channelSolidity != null) {
207-
channelSolidity.shutdownNow();
211+
shutdownChannel(channelFull);
212+
shutdownChannel(channelPBFT);
213+
shutdownChannel(channelSolidity);
214+
215+
if (executorService != null) {
216+
ExecutorServiceManager.shutdownAndAwaitTermination(
217+
executorService, executorName);
218+
executorService = null;
208219
}
220+
209221
context.close();
210222
Args.clearParam();
211223
}
212224

225+
private static void shutdownChannel(ManagedChannel channel) {
226+
if (channel == null) {
227+
return;
228+
}
229+
try {
230+
channel.shutdown();
231+
if (!channel.awaitTermination(5, TimeUnit.SECONDS)) {
232+
channel.shutdownNow();
233+
}
234+
} catch (InterruptedException e) {
235+
channel.shutdownNow();
236+
Thread.currentThread().interrupt();
237+
}
238+
}
239+
240+
@Before
241+
public void start() {
242+
logger.debug("========== Starting test: {} ==========", name.getMethodName());
243+
System.out.println("========== Starting test: " + name.getMethodName() + " ==========");
244+
}
245+
246+
@After
247+
public void end() throws InterruptedException {
248+
logger.debug("========== Ending test: {} ==========", name.getMethodName());
249+
System.out.println("========== Ending test: " + name.getMethodName() + " ==========");
250+
}
251+
213252
@Test
214253
public void testGetBlockByNum() {
215254
NumberMessage message = NumberMessage.newBuilder().setNum(0).build();

gradle/verification-metadata.xml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -846,15 +846,15 @@
846846
<sha256 value="8719f349cd542ae3ce523ac3992513a8c04020621bc86e880a79afa5f1aaf589" origin="Generated by Gradle"/>
847847
</artifact>
848848
</component>
849-
<component group="io.github.tronprotocol" name="libp2p" version="2.2.6">
850-
<artifact name="libp2p-2.2.6.jar">
851-
<sha256 value="b56584e6b6906b143fc915382aed5a6d98d8c5a5162fdb3320f58ef6f89e33e1" origin="Generated by Gradle"/>
849+
<component group="io.github.tronprotocol" name="libp2p" version="2.2.7">
850+
<artifact name="libp2p-2.2.7.jar">
851+
<sha256 value="6cf446b68723299e41189bd17d1605544ec4e8bada3830c7fa54d043b22b2208" origin="Generated by Gradle"/>
852852
</artifact>
853-
<artifact name="libp2p-2.2.6.module">
854-
<sha256 value="5eae986fb325d159eedba81e1173738597048ac8b3ac171d6cd03bd7bfb398d1" origin="Generated by Gradle"/>
853+
<artifact name="libp2p-2.2.7.module">
854+
<sha256 value="8dcf317770be76db50d2f5dd694f5b0edba98e2bf147626d9b49bbd888669689" origin="Generated by Gradle"/>
855855
</artifact>
856-
<artifact name="libp2p-2.2.6.pom">
857-
<sha256 value="6481cca729eee0f9ed796d3db601e890452eb0ed94d2f70bdb33ccd1816ae17d" origin="Generated by Gradle"/>
856+
<artifact name="libp2p-2.2.7.pom">
857+
<sha256 value="91ddb2a384207b401efa0d68b84f06ff9151fce8843e1ece3e5cf63875c1cd84" origin="Generated by Gradle"/>
858858
</artifact>
859859
</component>
860860
<component group="io.github.tronprotocol" name="zksnark-java-sdk" version="1.0.0">
@@ -1039,6 +1039,22 @@
10391039
<sha256 value="22b49f09ab47f5bc6a6d1a572692b373f0647236877b1030f0eb52e8ee678258" origin="Generated by Gradle"/>
10401040
</artifact>
10411041
</component>
1042+
<component group="io.netty" name="netty-transport-classes-epoll" version="4.1.124.Final">
1043+
<artifact name="netty-transport-classes-epoll-4.1.124.Final.jar">
1044+
<sha256 value="a098c9a095961c8b118f9352bf23c443e0de7c53db2afa0db189d703aed53ef8" origin="Generated by Gradle"/>
1045+
</artifact>
1046+
<artifact name="netty-transport-classes-epoll-4.1.124.Final.pom">
1047+
<sha256 value="32af1974d8b0f6d28112e056fb75e7365c89f3a19a9abdae5cc1caed99028f42" origin="Generated by Gradle"/>
1048+
</artifact>
1049+
</component>
1050+
<component group="io.netty" name="netty-transport-native-epoll" version="4.1.124.Final">
1051+
<artifact name="netty-transport-native-epoll-4.1.124.Final-linux-aarch_64.jar">
1052+
<sha256 value="89e18fd1c2025467229c20bbca28c79e52eefb2ac5d6ce6d32641293c37e5e56" origin="Generated by Gradle"/>
1053+
</artifact>
1054+
<artifact name="netty-transport-native-epoll-4.1.124.Final.pom">
1055+
<sha256 value="2508cebd61c7c25d2d50c95e8ebffad8f81f52baff6185a0a45d198dd8b2606e" origin="Generated by Gradle"/>
1056+
</artifact>
1057+
</component>
10421058
<component group="io.netty" name="netty-transport-native-unix-common" version="4.1.124.Final">
10431059
<artifact name="netty-transport-native-unix-common-4.1.124.Final.jar">
10441060
<sha256 value="5b824b485345d3eb4f29bd96005fe71d4bdcda3e4453a834fd58f7e113346115" origin="Generated by Gradle"/>

protocol/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apply plugin: 'com.google.protobuf'
33
def protobufVersion = '3.25.8'
44
def grpcVersion = '1.75.0'
55
def protocGenVersion = '1.60.0' // https://github.com/grpc/grpc-java/pull/11371 , 1.64.x is not supported CentOS 7.
6+
def nettyVersion = '4.1.124.Final' // Match the Netty version used by grpc-netty 1.75.0
67

78
dependencies {
89
api group: 'com.google.protobuf', name: 'protobuf-java', version: protobufVersion
@@ -19,6 +20,15 @@ dependencies {
1920

2021
// end google grpc
2122

23+
// Add Epoll support for ARM64 Linux only
24+
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
25+
def arch = System.getProperty("os.arch").toLowerCase()
26+
if (arch.contains("aarch") || arch.contains("arm")) {
27+
api group: 'io.netty', name: 'netty-transport-native-epoll',
28+
version: nettyVersion, classifier: 'linux-aarch_64'
29+
}
30+
}
31+
2232
api group: 'com.google.api.grpc', name: 'proto-google-common-protos', version: '2.15.0'
2333
}
2434

0 commit comments

Comments
 (0)