Skip to content

Commit 5ba9053

Browse files
committed
optimize FilterTriggerCapsule
1 parent 4bf108a commit 5ba9053

6 files changed

Lines changed: 23 additions & 17 deletions

File tree

common/src/main/java/org/tron/common/es/ExecutorServiceManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ public static ScheduledExecutorService newSingleThreadScheduledExecutor(String n
3939
}
4040

4141
public static ForkJoinPool newForkJoinPool(String name, int parallelism) {
42+
return newForkJoinPool(name, parallelism, false);
43+
}
44+
45+
public static ForkJoinPool newForkJoinPool(String name, int parallelism, boolean isDaemon) {
4246
AtomicInteger counter = new AtomicInteger(0);
4347
ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> {
4448
ForkJoinWorkerThread thread =
4549
ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
4650
thread.setName(name + "-" + counter.getAndIncrement());
51+
thread.setDaemon(isDaemon);
4752
return thread;
4853
};
4954
return new ForkJoinPool(parallelism, factory, null, false);
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.tron.common.logsfilter.capsule;
22

3-
public class FilterTriggerCapsule extends TriggerCapsule {
3+
public class FilterTriggerCapsule {
44

5-
public void processFilterTrigger() {
6-
throw new UnsupportedOperationException();
7-
}
85
}

framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static org.tron.core.services.jsonrpc.JsonRpcApiUtil.triggerCallContract;
1515

1616
import com.alibaba.fastjson.JSON;
17+
import com.google.common.annotations.VisibleForTesting;
1718
import com.google.common.cache.Cache;
1819
import com.google.common.cache.CacheBuilder;
1920
import com.google.protobuf.ByteString;
@@ -34,7 +35,6 @@
3435
import java.util.concurrent.TimeUnit;
3536
import java.util.regex.Pattern;
3637
import lombok.Getter;
37-
import lombok.Setter;
3838
import lombok.extern.slf4j.Slf4j;
3939
import org.apache.commons.lang3.StringUtils;
4040
import org.bouncycastle.util.encoders.Hex;
@@ -169,7 +169,6 @@ public enum RequestSource {
169169
private static final String NO_BLOCK_HEADER_BY_HASH = "header for hash not found";
170170

171171
private static final String ERROR_SELECTOR = "08c379a0"; // Function selector for Error(string)
172-
@Setter
173172
private int filterParallelThreshold = 10000;
174173
/**
175174
* Using the default maxLogFilterNum of 20,000, a 3-thread pool can keep up with log event
@@ -184,7 +183,6 @@ public enum RequestSource {
184183
private final ExecutorService sectionExecutor;
185184
private final NodeInfoService nodeInfoService;
186185
private final Wallet wallet;
187-
@Setter
188186
@Autowired
189187
private Manager manager;
190188
private final String esName = "query-section";
@@ -196,6 +194,16 @@ public TronJsonRpcImpl(@Autowired NodeInfoService nodeInfoService, @Autowired Wa
196194
this.sectionExecutor = ExecutorServiceManager.newFixedThreadPool(esName, 5);
197195
}
198196

197+
@VisibleForTesting
198+
public void setManager(Manager manager) {
199+
this.manager = manager;
200+
}
201+
202+
@VisibleForTesting
203+
public void setFilterParallelThreshold(int filterParallelThreshold) {
204+
this.filterParallelThreshold = filterParallelThreshold;
205+
}
206+
199207
public void handleBLockFilter(BlockFilterCapsule blockFilterCapsule) {
200208
Iterator<Entry<String, BlockFilterAndResult>> it;
201209

@@ -1434,6 +1442,7 @@ public String newFilter(FilterRequest fr) throws JsonRpcInvalidParamsException,
14341442
} else {
14351443
eventFilter2Result = eventFilter2ResultSolidity;
14361444
}
1445+
// Due to concurrent access, the threshold may occasionally be exceeded.
14371446
if (maxLogFilterNum > 0 && eventFilter2Result.size() >= maxLogFilterNum) {
14381447
throw new JsonRpcExceedLimitException(
14391448
"exceed max log filters: " + maxLogFilterNum + ", try again later");

framework/src/test/java/org/tron/common/logsfilter/FilterQueryTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.junit.Assert;
2222
import org.junit.Test;
2323
import org.tron.common.logsfilter.capsule.ContractEventTriggerCapsule;
24-
import org.tron.common.logsfilter.capsule.FilterTriggerCapsule;
2524
import org.tron.common.logsfilter.capsule.TriggerCapsule;
2625
import org.tron.common.runtime.LogEventWrapper;
2726
import org.tron.protos.contract.SmartContractOuterClass.SmartContract.ABI.Entry;
@@ -103,13 +102,6 @@ public synchronized void testMatchFilter() {
103102
assertNotNull(filterQuery.toString());
104103
}
105104

106-
FilterTriggerCapsule filterTriggerCapsule = new FilterTriggerCapsule();
107-
try {
108-
filterTriggerCapsule.processFilterTrigger();
109-
} catch (Exception e) {
110-
logger.info(e.getMessage());
111-
}
112-
113105
TriggerCapsule triggerCapsule = new TriggerCapsule();
114106
try {
115107
triggerCapsule.processTrigger();

framework/src/test/java/org/tron/core/jsonrpc/LogMatchOverLimitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void testAtExactLimit_succeeds()
118118
* {@link JsonRpcTooManyResultException} is thrown BEFORE {@code addAll}.
119119
*/
120120
@Test
121-
public void testExceedsLimit_throwsBeforeAddAll()
121+
public void testExceedsLimit_throws()
122122
throws ItemNotFoundException, JsonRpcInvalidParamsException {
123123
// block 1: MAX_RESULT - 1 logs, block 2: 2 logs → 9999 + 2 = 10001 > MAX_RESULT
124124
Manager manager = buildMockManager(

framework/src/test/java/org/tron/core/jsonrpc/WalletCursorTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
@Slf4j
2929
public class WalletCursorTest extends BaseTest {
30+
3031
private static final String OWNER_ADDRESS;
3132
private static final String OWNER_ADDRESS_ACCOUNT_NAME = "first";
3233
@Resource
@@ -36,7 +37,7 @@ public class WalletCursorTest extends BaseTest {
3637
private static boolean init;
3738

3839
static {
39-
Args.setParam(new String[]{"--output-directory", dbPath()}, TestConstants.TEST_CONF);
40+
Args.setParam(new String[] {"--output-directory", dbPath()}, TestConstants.TEST_CONF);
4041

4142
OWNER_ADDRESS =
4243
Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
@@ -160,6 +161,7 @@ public void testEnableInFullNode() {
160161
@Test
161162
public void testNewFilter_exceedsCapThrowsException() throws Exception {
162163
int cap = 5;
164+
int saved = Args.getInstance().getJsonRpcMaxLogFilterNum();
163165
Args.getInstance().setJsonRpcMaxLogFilterNum(cap);
164166
FilterRequest fr = new FilterRequest();
165167
TronJsonRpcImpl tronJsonRpc = new TronJsonRpcImpl(nodeInfoService, wallet);
@@ -183,6 +185,7 @@ public void testNewFilter_exceedsCapThrowsException() throws Exception {
183185
}
184186
} finally {
185187
tronJsonRpc.close();
188+
Args.getInstance().setJsonRpcMaxLogFilterNum(saved);
186189
}
187190
}
188191

0 commit comments

Comments
 (0)