Skip to content

Commit 7e2b7fc

Browse files
committed
Merge branch 'develop' of github.com:tronprotocol/java-tron into fix_msg_process
2 parents e2fd664 + b9ab07a commit 7e2b7fc

File tree

67 files changed

+1328
-487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1328
-487
lines changed

chainbase/src/main/java/org/tron/core/db2/core/AbstractSnapshot.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public abstract class AbstractSnapshot<K, V> implements Snapshot {
1515

1616
protected WeakReference<Snapshot> next;
1717

18+
protected boolean isOptimized;
19+
1820
@Override
1921
public Snapshot advance() {
2022
return new SnapshotImpl(this);
@@ -34,4 +36,9 @@ public void setNext(Snapshot next) {
3436
public String getDbName() {
3537
return db.getDbName();
3638
}
39+
40+
@Override
41+
public boolean isOptimized(){
42+
return isOptimized;
43+
}
3744
}

chainbase/src/main/java/org/tron/core/db2/core/Snapshot.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ static boolean isImpl(Snapshot snapshot) {
4646
void updateSolidity();
4747

4848
String getDbName();
49+
50+
boolean isOptimized();
51+
52+
void reloadToMem();
4953
}

chainbase/src/main/java/org/tron/core/db2/core/SnapshotImpl.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public class SnapshotImpl extends AbstractSnapshot<Key, Value> {
3030
}
3131
previous = snapshot;
3232
snapshot.setNext(this);
33+
isOptimized = snapshot.isOptimized();
34+
if (isOptimized && root == previous) {
35+
Streams.stream(root.iterator()).forEach( e -> put(e.getKey(),e.getValue()));
36+
}
3337
}
3438

3539
@Override
@@ -40,6 +44,7 @@ public byte[] get(byte[] key) {
4044
private byte[] get(Snapshot head, byte[] key) {
4145
Snapshot snapshot = head;
4246
Value value;
47+
4348
while (Snapshot.isImpl(snapshot)) {
4449
if ((value = ((SnapshotImpl) snapshot).db.get(Key.of(key))) != null) {
4550
return value.getBytes();
@@ -83,6 +88,19 @@ public void merge(Snapshot from) {
8388
Streams.stream(fromImpl.db).forEach(e -> db.put(e.getKey(), e.getValue()));
8489
}
8590

91+
public void mergeAhead(Snapshot from) {
92+
if (from instanceof SnapshotRoot) {
93+
return ;
94+
}
95+
SnapshotImpl fromImpl = (SnapshotImpl) from;
96+
Streams.stream(fromImpl.db).forEach(e -> {
97+
if (db.get(e.getKey()) == null) {
98+
db.put(e.getKey(), e.getValue());
99+
}
100+
}
101+
);
102+
}
103+
86104
@Override
87105
public Snapshot retreat() {
88106
return previous;
@@ -177,4 +195,9 @@ public String getDbName() {
177195
public Snapshot newInstance() {
178196
return new SnapshotImpl(this);
179197
}
198+
199+
@Override
200+
public void reloadToMem() {
201+
mergeAhead(previous);
202+
}
180203
}

chainbase/src/main/java/org/tron/core/db2/core/SnapshotManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ public synchronized void commit() {
221221
}
222222

223223
--activeSession;
224+
225+
dbs.forEach(db -> {
226+
if (db.getHead().isOptimized()) {
227+
db.getHead().reloadToMem();
228+
}
229+
});
224230
}
225231

226232
public synchronized void pop() {

chainbase/src/main/java/org/tron/core/db2/core/SnapshotRoot.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public SnapshotRoot(DB<byte[], byte[]> db) {
3838
if (CACHE_DBS.contains(this.db.getDbName())) {
3939
this.cache = CacheManager.allocate(CacheType.findByType(this.db.getDbName()));
4040
}
41+
isOptimized = "properties".equalsIgnoreCase(db.getDbName());
4142
}
4243

4344
private boolean needOptAsset() {
@@ -221,4 +222,7 @@ public String getDbName() {
221222
public Snapshot newInstance() {
222223
return new SnapshotRoot(db.newInstance());
223224
}
225+
226+
@Override
227+
public void reloadToMem() { }
224228
}

common/src/main/java/org/tron/common/logsfilter/trigger/TransactionLogTrigger.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.tron.common.logsfilter.trigger;
22

33
import java.util.List;
4+
import java.util.Map;
5+
46
import lombok.Getter;
57
import lombok.Setter;
68

@@ -91,6 +93,10 @@ public class TransactionLogTrigger extends Trigger {
9193
@Setter
9294
private long energyUnitPrice;
9395

96+
@Getter
97+
@Setter
98+
private Map<String, Long> extMap;
99+
94100
public TransactionLogTrigger() {
95101
setTriggerName(Trigger.TRANSACTION_TRIGGER_NAME);
96102
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public interface Application {
3434

3535
void startServices();
3636

37+
// DO NOT USE THIS METHOD IN TEST CASES MAIN-THREAD
38+
default void blockUntilShutdown() {
39+
}
40+
3741
void shutdownServices();
3842

3943
void addService(Service service);

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

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import lombok.extern.slf4j.Slf4j;
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.stereotype.Component;
6-
import org.tron.common.logsfilter.EventPluginLoader;
76
import org.tron.common.parameter.CommonParameter;
87
import org.tron.core.ChainBaseManager;
98
import org.tron.core.config.args.Args;
10-
import org.tron.core.config.args.DynamicArgs;
119
import org.tron.core.consensus.ConsensusService;
1210
import org.tron.core.db.Manager;
1311
import org.tron.core.metrics.MetricsUtil;
@@ -31,9 +29,6 @@ public class ApplicationImpl implements Application {
3129
@Autowired
3230
private ConsensusService consensusService;
3331

34-
@Autowired
35-
private DynamicArgs dynamicArgs;
36-
3732
@Override
3833
public void setOptions(Args args) {
3934
// not used
@@ -64,35 +59,30 @@ public void startup() {
6459
}
6560
consensusService.start();
6661
MetricsUtil.init();
67-
dynamicArgs.init();
62+
this.initServices(Args.getInstance());
63+
this.startServices();
6864
}
6965

7066
@Override
7167
public void shutdown() {
72-
logger.info("******** start to shutdown ********");
68+
this.shutdownServices();
69+
consensusService.stop();
7370
if (!Args.getInstance().isSolidityNode() && (!Args.getInstance().p2pDisable)) {
7471
tronNetService.close();
7572
}
76-
consensusService.stop();
77-
synchronized (dbManager.getRevokingStore()) {
78-
dbManager.getSession().reset();
79-
closeRevokingStore();
80-
}
81-
dbManager.stopRePushThread();
82-
dbManager.stopRePushTriggerThread();
83-
EventPluginLoader.getInstance().stopPlugin();
84-
dbManager.stopFilterProcessThread();
85-
dbManager.stopValidateSignThread();
86-
getChainBaseManager().shutdown();
87-
dynamicArgs.close();
88-
logger.info("******** end to shutdown ********");
73+
dbManager.close();
8974
}
9075

9176
@Override
9277
public void startServices() {
9378
services.start();
9479
}
9580

81+
@Override
82+
public void blockUntilShutdown() {
83+
services.blockUntilShutdown();
84+
}
85+
9686
@Override
9787
public void shutdownServices() {
9888
services.stop();
@@ -108,9 +98,4 @@ public ChainBaseManager getChainBaseManager() {
10898
return chainBaseManager;
10999
}
110100

111-
private void closeRevokingStore() {
112-
logger.info("******** start to closeRevokingStore ********");
113-
dbManager.getRevokingStore().shutdown();
114-
}
115-
116101
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* java-tron is free software: you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License as published by
4+
* the Free Software Foundation, either version 3 of the License, or
5+
* (at your option) any later version.
6+
*
7+
* java-tron is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
package org.tron.common.application;
17+
18+
import com.google.common.base.Objects;
19+
import lombok.extern.slf4j.Slf4j;
20+
import org.eclipse.jetty.server.Server;
21+
22+
@Slf4j(topic = "rpc")
23+
public abstract class HttpService implements Service {
24+
25+
protected Server apiServer;
26+
protected int port;
27+
28+
@Override
29+
public void blockUntilShutdown() {
30+
if (apiServer != null) {
31+
try {
32+
apiServer.join();
33+
} catch (InterruptedException e) {
34+
logger.warn("{}", e.getMessage());
35+
Thread.currentThread().interrupt();
36+
}
37+
}
38+
}
39+
40+
@Override
41+
public void start() {
42+
if (apiServer != null) {
43+
try {
44+
apiServer.start();
45+
logger.info("{} started, listening on {}", this.getClass().getSimpleName(), port);
46+
} catch (Exception e) {
47+
logger.error("{}", this.getClass().getSimpleName(), e);
48+
}
49+
}
50+
}
51+
52+
@Override
53+
public void stop() {
54+
if (apiServer != null) {
55+
logger.info("{} shutdown...", this.getClass().getSimpleName());
56+
try {
57+
apiServer.stop();
58+
} catch (Exception e) {
59+
logger.warn("{}", this.getClass().getSimpleName(), e);
60+
}
61+
logger.info("{} shutdown complete", this.getClass().getSimpleName());
62+
}
63+
}
64+
65+
@Override
66+
public boolean equals(Object o) {
67+
if (this == o) {
68+
return true;
69+
}
70+
if (o == null || getClass() != o.getClass()) {
71+
return false;
72+
}
73+
HttpService that = (HttpService) o;
74+
return port == that.port;
75+
}
76+
77+
@Override
78+
public int hashCode() {
79+
return Objects.hashCode(getClass().getSimpleName(), port);
80+
}
81+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* java-tron is free software: you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License as published by
4+
* the Free Software Foundation, either version 3 of the License, or
5+
* (at your option) any later version.
6+
*
7+
* java-tron is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
package org.tron.common.application;
17+
18+
import com.google.common.base.Objects;
19+
import io.grpc.Server;
20+
import java.io.IOException;
21+
import java.util.concurrent.TimeUnit;
22+
import lombok.extern.slf4j.Slf4j;
23+
24+
@Slf4j(topic = "rpc")
25+
public abstract class RpcService implements Service {
26+
27+
protected Server apiServer;
28+
protected int port;
29+
30+
@Override
31+
public void blockUntilShutdown() {
32+
if (apiServer != null) {
33+
try {
34+
apiServer.awaitTermination();
35+
} catch (InterruptedException e) {
36+
logger.warn("{}", e.getMessage());
37+
Thread.currentThread().interrupt();
38+
}
39+
}
40+
}
41+
42+
@Override
43+
public void start() {
44+
if (apiServer != null) {
45+
try {
46+
apiServer.start();
47+
logger.info("{} started, listening on {}", this.getClass().getSimpleName(), port);
48+
} catch (IOException e) {
49+
logger.error("{}", this.getClass().getSimpleName(), e);
50+
}
51+
}
52+
}
53+
54+
@Override
55+
public void stop() {
56+
if (apiServer != null) {
57+
logger.info("{} shutdown...", this.getClass().getSimpleName());
58+
try {
59+
apiServer.shutdown().awaitTermination(5, TimeUnit.SECONDS);
60+
} catch (InterruptedException e) {
61+
Thread.currentThread().interrupt();
62+
logger.warn("{}", this.getClass().getSimpleName(), e);
63+
}
64+
logger.info("{} shutdown complete", this.getClass().getSimpleName());
65+
}
66+
}
67+
68+
@Override
69+
public boolean equals(Object o) {
70+
if (this == o) {
71+
return true;
72+
}
73+
if (o == null || getClass() != o.getClass()) {
74+
return false;
75+
}
76+
RpcService that = (RpcService) o;
77+
return port == that.port;
78+
}
79+
80+
@Override
81+
public int hashCode() {
82+
return Objects.hashCode(getClass().getSimpleName(), port);
83+
}
84+
85+
}

0 commit comments

Comments
 (0)