Skip to content

Commit 75fea18

Browse files
author
wubin1
committed
rebase develop branch
2 parents a4fbc05 + d593a0e commit 75fea18

49 files changed

Lines changed: 2850 additions & 289 deletions

Some content is hidden

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

‎.circleci/config.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ jobs:
55
only:
66
- master
77
- develop
8+
- addinCircleCI
9+
810
docker:
911
- image: circleci/openjdk:8-jdk-browsers
1012
working_directory: ~/java-tron
1113
steps:
1214
- checkout
13-
- run: curl http://60.205.215.34/Daily_Build_Task_Report
15+
- run:
16+
name: Daily Build Report
17+
command: curl http://60.205.215.34/Daily_Build_Task_Report
18+
19+
20+
- run:
21+
name: Download Links
22+
command: sh DownloadLinks.sh

‎DownloadLinks.sh‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
PassFlag=`curl -s http://60.205.215.34/Daily_Build_Task_Report | grep "Failed: 0" | wc -c`
2+
3+
if [ $PassFlag -eq 0 ]; then
4+
echo "Daily Build Stest Fail"
5+
echo "To view Daily Replay and Stress Test logs please visit website below on browsers"
6+
echo "--- http://60.205.215.34/latestReplayLog"
7+
echo "--- http://60.205.215.34/latestStressLog"
8+
9+
else
10+
echo "Daily Build Stest Pass"
11+
echo "Build on `date +"%Y-%m-%d"` 3:00:00 (CST), UTC +8"
12+
echo "Please visit following website to download java-tron.jar on browsers"
13+
echo "--- http://60.205.215.34/Daily_Build/java-tron.jar"
14+
echo "To view Daily Replay and Stress Test logs please visit website below on browsers"
15+
echo "--- http://60.205.215.34/latestReplayLog"
16+
echo "--- http://60.205.215.34/latestStressLog"
17+
echo "The following compressed package is provided for user to set up Fullnode. Please use Linux OS to Download"
18+
echo "--- curl -# -O http://60.205.215.34/Daily_Build/java-tron.tar.gz"
19+
echo "To unzip file use the command below"
20+
echo "--- tar -xzvf java-tron.tar.gz"
21+
fi

‎build.gradle‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ dependencies {
116116

117117
compile "org.iq80.leveldb:leveldb:0.7"
118118

119+
compile group: 'org.rocksdb', name: 'rocksdbjni', version: '5.15.10'
120+
119121
compile group: leveldbGroup, name: leveldbName, version: leveldbVersion
120122

121123
compile "org.apache.commons:commons-collections4:4.0"
@@ -340,5 +342,6 @@ def binaryRelease(taskName, jarName, mainClass) {
340342
artifacts {
341343
archives(binaryRelease('buildSolidityNodeJar', 'SolidityNode', 'org.tron.program.SolidityNode'),
342344
binaryRelease('buildFullNodeJar', 'FullNode', 'org.tron.program.FullNode'),
343-
binaryRelease('buildKeystoreFactoryJar', 'KeystoreFactory', 'org.tron.program.KeystoreFactory'))
345+
binaryRelease('buildKeystoreFactoryJar', 'KeystoreFactory', 'org.tron.program.KeystoreFactory'),
346+
binaryRelease('buildDBConvertJar', 'DBConvert', 'org.tron.program.DBConvert'))
344347
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void startup() {
6868
@Override
6969
public void shutdown() {
7070
logger.info("******** begin to shutdown ********");
71+
//p2pNode.shutDown();
7172
synchronized (dbManager.getRevokingStore()) {
7273
closeRevokingStore();
7374
closeAllStore();
@@ -124,6 +125,7 @@ private void closeConnection() {
124125
}
125126

126127
private void closeRevokingStore() {
128+
logger.info("******** begin to closeRevokingStore ********");
127129
dbManager.getRevokingStore().shutdown();
128130
}
129131

‎src/main/java/org/tron/common/storage/BatchSourceInter.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
package org.tron.common.storage;
2020

21-
import org.iq80.leveldb.WriteOptions;
22-
2321
import java.util.Map;
2422

2523

@@ -28,5 +26,5 @@ public interface BatchSourceInter<K, V> extends SourceInter<K, V> {
2826

2927
void updateByBatch(Map<K, V> rows);
3028

31-
void updateByBatch(Map<K, V> rows, WriteOptions writeOptions);
29+
void updateByBatch(Map<K, V> rows, WriteOptionsWrapper writeOptions);
3230
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package org.tron.common.storage;
2+
3+
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.List;
7+
import lombok.Getter;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.rocksdb.CompressionType;
10+
11+
@Slf4j
12+
public class DBSettings {
13+
14+
private static DBSettings settings;
15+
16+
@Getter
17+
private int levelNumber;
18+
@Getter
19+
private int maxOpenFiles;
20+
@Getter
21+
private int compactThreads;
22+
@Getter
23+
private long blockSize;
24+
@Getter
25+
private long maxBytesForLevelBase;
26+
@Getter
27+
private double maxBytesForLevelMultiplier;
28+
@Getter
29+
private int level0FileNumCompactionTrigger;
30+
@Getter
31+
private List<CompressionType> compressionTypeList;
32+
@Getter
33+
private long targetFileSizeBase;
34+
@Getter
35+
private int targetFileSizeMultiplier;
36+
@Getter
37+
private boolean enableStatistics;
38+
39+
private DBSettings() {
40+
41+
}
42+
43+
public static DBSettings getDefaultSettings() {
44+
DBSettings defaultSettings = new DBSettings();
45+
return defaultSettings.withLevelNumber(7).withBlockSize(64).withCompactThreads(32)
46+
.withCompressionTypeList("no:no:no:lz4:lz4:zstd:zstd").withTargetFileSizeBase(256)
47+
.withMaxBytesForLevelMultiplier(10).withTargetFileSizeMultiplier(1).withMaxBytesForLevelBase(256).withMaxOpenFiles(-1)
48+
.withEnableStatistics(false);
49+
}
50+
51+
public static DBSettings getSettings() {
52+
if (settings == null) {
53+
return getDefaultSettings();
54+
}
55+
return settings;
56+
}
57+
58+
public static DBSettings initCustomSettings(int levelNumber, int compactThreads, int blocksize,
59+
long maxBytesForLevelBase,
60+
double maxBytesForLevelMultiplier, String compressionStr,
61+
int level0FileNumCompactionTrigger, long targetFileSizeBase, int targetFileSizeMultiplier) {
62+
settings = new DBSettings()
63+
.withMaxOpenFiles(-1)
64+
.withEnableStatistics(false)
65+
.withLevelNumber(levelNumber)
66+
.withCompactThreads(compactThreads)
67+
.withBlockSize(blocksize)
68+
.withMaxBytesForLevelBase(maxBytesForLevelBase)
69+
.withMaxBytesForLevelMultiplier(maxBytesForLevelMultiplier)
70+
.withCompressionTypeList(compressionStr)
71+
.withLevel0FileNumCompactionTrigger(level0FileNumCompactionTrigger)
72+
.withTargetFileSizeBase(targetFileSizeBase)
73+
.withTargetFileSizeMultiplier(targetFileSizeMultiplier);
74+
return settings;
75+
}
76+
77+
78+
public DBSettings withMaxOpenFiles(int maxOpenFiles) {
79+
this.maxOpenFiles = maxOpenFiles;
80+
return this;
81+
}
82+
83+
public DBSettings withCompactThreads(int compactThreads) {
84+
this.compactThreads = compactThreads;
85+
return this;
86+
}
87+
88+
public DBSettings withBlockSize(long blockSize) {
89+
this.blockSize = blockSize * 1024;
90+
return this;
91+
}
92+
93+
public DBSettings withMaxBytesForLevelBase(long maxBytesForLevelBase) {
94+
this.maxBytesForLevelBase = maxBytesForLevelBase * 1024 * 1024;
95+
return this;
96+
}
97+
98+
public DBSettings withMaxBytesForLevelMultiplier(double maxBytesForLevelMultiplier) {
99+
this.maxBytesForLevelMultiplier = maxBytesForLevelMultiplier;
100+
return this;
101+
}
102+
103+
public DBSettings withLevel0FileNumCompactionTrigger(int level0FileNumCompactionTrigger) {
104+
this.level0FileNumCompactionTrigger = level0FileNumCompactionTrigger;
105+
return this;
106+
}
107+
108+
public DBSettings withCompressionTypeList(String compressionTypeListString) {
109+
List<String> compressionTypeStringList = Arrays.asList(compressionTypeListString.split(":"));
110+
List<CompressionType> compressionTypeList = new ArrayList<>();
111+
for (String str : compressionTypeStringList) {
112+
if (str.equals("no")) {
113+
compressionTypeList.add(CompressionType.NO_COMPRESSION);
114+
} else if (str.equals("lz4")) {
115+
compressionTypeList.add(CompressionType.LZ4_COMPRESSION);
116+
} else if (str.equals("zstd")) {
117+
compressionTypeList.add(CompressionType.ZSTD_COMPRESSION);
118+
} else if (str.equals("zlib")) {
119+
compressionTypeList.add(CompressionType.ZLIB_COMPRESSION);
120+
}
121+
}
122+
this.compressionTypeList = compressionTypeList;
123+
return this;
124+
}
125+
126+
public DBSettings withEnableStatistics(boolean enable) {
127+
this.enableStatistics = enable;
128+
return this;
129+
}
130+
131+
public DBSettings withLevelNumber(int levelNumber) {
132+
this.levelNumber = levelNumber;
133+
return this;
134+
}
135+
136+
137+
public DBSettings withTargetFileSizeBase(long targetFileSizeBase) {
138+
this.targetFileSizeBase = targetFileSizeBase * 1024 * 1024;
139+
return this;
140+
}
141+
142+
public DBSettings withTargetFileSizeMultiplier(int targetFileSizeMultiplier) {
143+
this.targetFileSizeMultiplier = targetFileSizeMultiplier;
144+
return this;
145+
}
146+
147+
public static void loggingSettings() {
148+
logger.info(String.format(
149+
"level number: %d, CompactThreads: %d, Blocksize: %d, maxBytesForLevelBase: %d, withMaxBytesForLevelMultiplier: %f, level0FileNumCompactionTrigger: %d, withTargetFileSizeBase: %d, withTargetFileSizeMultiplier: %d",
150+
settings.getLevelNumber(),
151+
settings.getCompactThreads(), settings.getBlockSize(), settings.getMaxBytesForLevelBase(),
152+
settings.getMaxBytesForLevelMultiplier(), settings.getLevel0FileNumCompactionTrigger(),
153+
settings.getTargetFileSizeBase(), settings.getTargetFileSizeMultiplier()));
154+
}
155+
}

‎src/main/java/org/tron/common/storage/SourceInter.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,19 @@
1818
package org.tron.common.storage;
1919

2020

21-
import org.iq80.leveldb.WriteOptions;
22-
2321
public interface SourceInter<K, V> {
2422

2523

2624
void putData(K key, V val);
2725

28-
void putData(K k, V v, WriteOptions options);
26+
void putData(K k, V v, WriteOptionsWrapper options);
2927

3028
V getData(K key);
3129

3230

3331
void deleteData(K key);
3432

35-
void deleteData(K k, WriteOptions options);
33+
void deleteData(K k, WriteOptionsWrapper options);
3634

3735
boolean flush();
3836

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.tron.common.storage;
2+
3+
public class WriteOptionsWrapper {
4+
5+
public org.rocksdb.WriteOptions rocks = null;
6+
public org.iq80.leveldb.WriteOptions level = null;
7+
8+
private WriteOptionsWrapper() {
9+
10+
}
11+
12+
public static WriteOptionsWrapper getInstance() {
13+
WriteOptionsWrapper wapper = new WriteOptionsWrapper();
14+
wapper.level = new org.iq80.leveldb.WriteOptions();
15+
wapper.rocks = new org.rocksdb.WriteOptions();
16+
return wapper;
17+
}
18+
19+
20+
public WriteOptionsWrapper sync(boolean bool) {
21+
this.level.sync(bool);
22+
this.rocks.setSync(bool);
23+
return this;
24+
}
25+
}

‎src/main/java/org/tron/common/storage/leveldb/LevelDbDataSourceImpl.java‎

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
import org.iq80.leveldb.WriteBatch;
4444
import org.iq80.leveldb.WriteOptions;
4545
import org.tron.common.storage.DbSourceInter;
46+
import org.tron.common.storage.WriteOptionsWrapper;
4647
import org.tron.common.utils.FileUtil;
48+
import org.tron.common.utils.PropUtil;
4749
import org.tron.core.config.args.Args;
4850
import org.tron.core.db.common.iterator.StoreIterator;
4951

@@ -64,13 +66,43 @@ public class LevelDbDataSourceImpl implements DbSourceInter<byte[]>,
6466
public LevelDbDataSourceImpl(String parentName, String name) {
6567
this.dataBaseName = name;
6668
this.parentName = Paths.get(
67-
parentName,
68-
Args.getInstance().getStorage().getDbDirectory()
69+
parentName,
70+
Args.getInstance().getStorage().getDbDirectory()
6971
).toString();
7072
}
7173

74+
public boolean checkOrInitEngine() {
75+
String dir = Args.getInstance().getOutputDirectory() + Args.getInstance().getStorage().getDbDirectory() + File.separator + dataBaseName;
76+
String enginePath = dir + File.separator + "engine.properties";
77+
78+
if (FileUtil.createDirIfNotExists(dir)) {
79+
if (!FileUtil.createFileIfNotExists(enginePath)) {
80+
return false;
81+
}
82+
} else {
83+
return false;
84+
}
85+
86+
String engine = PropUtil.readProperty(enginePath, "ENGINE");
87+
if (engine.equals("")) {
88+
if (!PropUtil.writeProperty(enginePath, "ENGINE", "LEVELDB")) {
89+
return false;
90+
}
91+
}
92+
engine = PropUtil.readProperty(enginePath, "ENGINE");
93+
if (engine.equals("LEVELDB")) {
94+
return true;
95+
} else {
96+
return false;
97+
}
98+
}
99+
72100
@Override
73101
public void initDB() {
102+
if (!checkOrInitEngine()) {
103+
logger.error("database engine do not match");
104+
throw new RuntimeException("Failed to initialize database");
105+
}
74106
resetDbLock.writeLock().lock();
75107
try {
76108
logger.debug("~> LevelDbDataSourceImpl.initDB(): " + dataBaseName);
@@ -207,10 +239,10 @@ public void putData(byte[] key, byte[] value) {
207239
}
208240

209241
@Override
210-
public void putData(byte[] key, byte[] value, WriteOptions options) {
242+
public void putData(byte[] key, byte[] value, WriteOptionsWrapper options) {
211243
resetDbLock.readLock().lock();
212244
try {
213-
database.put(key, value, options);
245+
database.put(key, value, options.level);
214246
} finally {
215247
resetDbLock.readLock().unlock();
216248
}
@@ -227,10 +259,10 @@ public void deleteData(byte[] key) {
227259
}
228260

229261
@Override
230-
public void deleteData(byte[] key, WriteOptions options) {
262+
public void deleteData(byte[] key, WriteOptionsWrapper options) {
231263
resetDbLock.readLock().lock();
232264
try {
233-
database.delete(key, options);
265+
database.delete(key, options.level);
234266
} finally {
235267
resetDbLock.readLock().unlock();
236268
}
@@ -416,13 +448,13 @@ public void updateByBatch(Map<byte[], byte[]> rows) {
416448
}
417449

418450
@Override
419-
public void updateByBatch(Map<byte[], byte[]> rows, WriteOptions options) {
451+
public void updateByBatch(Map<byte[], byte[]> rows, WriteOptionsWrapper options) {
420452
resetDbLock.readLock().lock();
421453
try {
422-
updateByBatchInner(rows, options);
454+
updateByBatchInner(rows, options.level);
423455
} catch (Exception e) {
424456
try {
425-
updateByBatchInner(rows, options);
457+
updateByBatchInner(rows, options.level);
426458
} catch (Exception e1) {
427459
throw new RuntimeException(e);
428460
}

0 commit comments

Comments
 (0)