Skip to content

Commit d46631e

Browse files
committed
Merge branch 'develop' into add_http_stest_case
2 parents cfae06c + bff3fc3 commit d46631e

23 files changed

Lines changed: 567 additions & 191 deletions

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

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package org.tron.common.storage;
22

3-
4-
import java.util.ArrayList;
5-
import java.util.Arrays;
6-
import java.util.List;
73
import lombok.Getter;
84
import lombok.extern.slf4j.Slf4j;
9-
import org.rocksdb.CompressionType;
105

116
@Slf4j
127
public class DBSettings {
@@ -28,8 +23,6 @@ public class DBSettings {
2823
@Getter
2924
private int level0FileNumCompactionTrigger;
3025
@Getter
31-
private List<CompressionType> compressionTypeList;
32-
@Getter
3326
private long targetFileSizeBase;
3427
@Getter
3528
private int targetFileSizeMultiplier;
@@ -43,9 +36,8 @@ private DBSettings() {
4336
public static DBSettings getDefaultSettings() {
4437
DBSettings defaultSettings = new DBSettings();
4538
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);
39+
.withTargetFileSizeBase(256).withMaxBytesForLevelMultiplier(10).withTargetFileSizeMultiplier(1)
40+
.withMaxBytesForLevelBase(256).withMaxOpenFiles(-1).withEnableStatistics(false);
4941
}
5042

5143
public static DBSettings getSettings() {
@@ -57,8 +49,8 @@ public static DBSettings getSettings() {
5749

5850
public static DBSettings initCustomSettings(int levelNumber, int compactThreads, int blocksize,
5951
long maxBytesForLevelBase,
60-
double maxBytesForLevelMultiplier, String compressionStr,
61-
int level0FileNumCompactionTrigger, long targetFileSizeBase, int targetFileSizeMultiplier) {
52+
double maxBytesForLevelMultiplier, int level0FileNumCompactionTrigger, long targetFileSizeBase,
53+
int targetFileSizeMultiplier) {
6254
settings = new DBSettings()
6355
.withMaxOpenFiles(-1)
6456
.withEnableStatistics(false)
@@ -67,7 +59,6 @@ public static DBSettings initCustomSettings(int levelNumber, int compactThreads,
6759
.withBlockSize(blocksize)
6860
.withMaxBytesForLevelBase(maxBytesForLevelBase)
6961
.withMaxBytesForLevelMultiplier(maxBytesForLevelMultiplier)
70-
.withCompressionTypeList(compressionStr)
7162
.withLevel0FileNumCompactionTrigger(level0FileNumCompactionTrigger)
7263
.withTargetFileSizeBase(targetFileSizeBase)
7364
.withTargetFileSizeMultiplier(targetFileSizeMultiplier);
@@ -105,24 +96,6 @@ public DBSettings withLevel0FileNumCompactionTrigger(int level0FileNumCompaction
10596
return this;
10697
}
10798

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-
12699
public DBSettings withEnableStatistics(boolean enable) {
127100
this.enableStatistics = enable;
128101
return this;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
*/
1818
package org.tron.common.storage;
1919

20+
import java.util.Map;
2021
import java.util.Set;
2122

2223

23-
public interface DbSourceInter<V> extends BatchSourceInter<byte[], V> {
24+
public interface DbSourceInter<V> extends BatchSourceInter<byte[], V>, Iterable<Map.Entry<byte[], V>> {
2425

2526

2627
String getDBName();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ public void initDB(DBSettings settings) {
192192
options.setMaxBytesForLevelMultiplier(settings.getMaxBytesForLevelMultiplier());
193193
options.setMaxBytesForLevelBase(settings.getMaxBytesForLevelBase());
194194
options.setMaxBackgroundCompactions(settings.getCompactThreads());
195-
options.setCompressionPerLevel(settings.getCompressionTypeList());
196195
options.setLevel0FileNumCompactionTrigger(settings.getLevel0FileNumCompactionTrigger());
197196
options.setTargetFileSizeMultiplier(settings.getTargetFileSizeMultiplier());
198197
options.setTargetFileSizeBase(settings.getTargetFileSizeBase());
@@ -482,7 +481,8 @@ public Set<byte[]> getValuesNext(byte[] key, long limit) {
482481
}
483482

484483
public void backup(String dir) throws RocksDBException {
485-
Checkpoint.create(database).createCheckpoint(dir + this.getDBName());
484+
Checkpoint cp = Checkpoint.create(database);
485+
cp.createCheckpoint(dir + this.getDBName());
486486
}
487487

488488
public boolean deleteDbBakPath(String dir) {

‎src/main/java/org/tron/common/utils/FileUtil.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ public static boolean createFileIfNotExists(String filepath) {
130130
if (!file.exists()) {
131131
try {
132132
file.createNewFile();
133-
} catch (IOException e) {
134-
e.printStackTrace();
133+
} catch (Exception e) {
135134
return false;
136135
}
137136
}

‎src/main/java/org/tron/common/utils/PropUtil.java‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import java.io.BufferedWriter;
66
import java.io.FileInputStream;
77
import java.io.FileOutputStream;
8+
import java.io.IOException;
89
import java.io.InputStream;
910
import java.io.InputStreamReader;
1011
import java.io.OutputStream;
1112
import java.io.OutputStreamWriter;
12-
import java.net.URISyntaxException;
13-
import java.util.ArrayList;
14-
import java.util.List;
1513
import java.util.Properties;
1614
import lombok.extern.slf4j.Slf4j;
1715

@@ -60,18 +58,38 @@ public static String readProperty(String file, String key) {
6058
public static boolean writeProperty(String file, String key, String value) {
6159
FileInputStream fis = null;
6260
Properties properties = new Properties();
61+
OutputStream out = null;
6362
try {
6463
fis = new FileInputStream(file);
6564
BufferedReader bf = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
6665
properties.load(bf);
67-
OutputStream out = new FileOutputStream(file);
66+
out = new FileOutputStream(file);
6867
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
6968
properties.setProperty(key, value);
7069
properties.store(bw, "Generated by the application. PLEASE DO NOT EDIT! ");
71-
out.close();
7270
} catch (Exception e) {
7371
logger.warn("{}", e);
7472
return false;
73+
} finally {
74+
if (properties != null) {
75+
properties = null;
76+
}
77+
//fis
78+
try {
79+
if (fis != null) {
80+
fis.close();
81+
fis = null;
82+
}
83+
} catch (Exception e) {
84+
logger.warn("{}", e);
85+
}
86+
//out
87+
try {
88+
out.close();
89+
out = null;
90+
} catch (IOException e) {
91+
logger.warn("{}", e);
92+
}
7593
}
7694
return true;
7795
}

‎src/main/java/org/tron/core/config/args/Args.java‎

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,11 @@ public static void setParam(final String[] args, final String confFileName) {
625625
.filter(StringUtils::isNotEmpty)
626626
.orElse(Storage.getDbEngineFromConfig(config)));
627627

628+
if (INSTANCE.storage.getDbEngine().toUpperCase().equals("ROCKSDB")
629+
&& INSTANCE.storage.getDbVersion() == 1) {
630+
throw new RuntimeException("db.version = 1 is not supported by ROCKSDB engine.");
631+
}
632+
628633
INSTANCE.storage.setDbSync(Optional.ofNullable(INSTANCE.storageDbSynchronous)
629634
.filter(StringUtils::isNotEmpty)
630635
.map(Boolean::valueOf)
@@ -848,8 +853,10 @@ public static void setParam(final String[] args, final String confFileName) {
848853
config.getString("trx.reference.block") : "head";
849854

850855
INSTANCE.trxExpirationTimeInMilliseconds =
851-
config.hasPath("trx.expiration.timeInMilliseconds") && config.getLong("trx.expiration.timeInMilliseconds") > 0 ?
852-
config.getLong("trx.expiration.timeInMilliseconds") : Constant.TRANSACTION_DEFAULT_EXPIRATION_TIME;
856+
config.hasPath("trx.expiration.timeInMilliseconds")
857+
&& config.getLong("trx.expiration.timeInMilliseconds") > 0 ?
858+
config.getLong("trx.expiration.timeInMilliseconds")
859+
: Constant.TRANSACTION_DEFAULT_EXPIRATION_TIME;
853860

854861
INSTANCE.minEffectiveConnection = config.hasPath("node.rpc.minEffectiveConnection") ?
855862
config.getInt("node.rpc.minEffectiveConnection") : 1;
@@ -872,8 +879,10 @@ public static void setParam(final String[] args, final String confFileName) {
872879
config.hasPath("event.subscribe.filter") ? getEventFilter(config) : null;
873880

874881
initBackupProperty(config);
875-
initRocksDbBackupProperty(config);
876-
initRocksDbSettings(config);
882+
if (Args.getInstance().getStorage().getDbEngine().toUpperCase().equals("ROCKSDB")) {
883+
initRocksDbBackupProperty(config);
884+
initRocksDbSettings(config);
885+
}
877886

878887
logConfig();
879888
}
@@ -1156,43 +1165,35 @@ private static double calcMaxTimeRatio() {
11561165

11571166
private static void initRocksDbSettings(Config config) {
11581167
String prefix = "storage.dbSettings.";
1159-
1160-
if (Args.getInstance().getStorage().getDbEngine().equals("ROCKSDB")) {
1161-
int levelNumber = config.hasPath(prefix + "levelNumber")
1162-
? config.getInt(prefix + "levelNumber") : 7;
1163-
int compactThreads = config.hasPath(prefix + "compactThreads")
1164-
? config.getInt(prefix + "compactThreads")
1165-
: max(Runtime.getRuntime().availableProcessors(), 1);
1166-
int blocksize = config.hasPath(prefix + "blocksize")
1167-
? config.getInt(prefix + "blocksize") : 16;
1168-
long maxBytesForLevelBase = config.hasPath(prefix + "maxBytesForLevelBase")
1169-
? config.getInt(prefix + "maxBytesForLevelBase") : 256;
1170-
double maxBytesForLevelMultiplier = config.hasPath(prefix + "maxBytesForLevelMultiplier")
1171-
? config.getDouble(prefix + "maxBytesForLevelMultiplier") : 10;
1172-
String compressionStr = config.hasPath(prefix + "compressionTypeListStr")
1173-
? config.getString(prefix + "compressionTypeListStr") : "no:no:lz4:lz4:lz4:zstd:zstd";
1174-
int level0FileNumCompactionTrigger =
1175-
config.hasPath(prefix + "level0FileNumCompactionTrigger") ? config
1176-
.getInt(prefix + "level0FileNumCompactionTrigger") : 2;
1177-
long targetFileSizeBase = config.hasPath(prefix + "targetFileSizeBase") ? config
1178-
.getLong(prefix + "targetFileSizeBase") : 64;
1179-
int targetFileSizeMultiplier = config.hasPath(prefix + "targetFileSizeMultiplier") ? config
1180-
.getInt(prefix + "targetFileSizeMultiplier") : 1;
1181-
1182-
INSTANCE.rocksDBCustomSettings = DBSettings
1183-
.initCustomSettings(levelNumber, compactThreads, blocksize, maxBytesForLevelBase,
1184-
maxBytesForLevelMultiplier, compressionStr, level0FileNumCompactionTrigger,
1185-
targetFileSizeBase, targetFileSizeMultiplier);
1186-
DBSettings.loggingSettings();
1187-
}
1168+
int levelNumber = config.hasPath(prefix + "levelNumber")
1169+
? config.getInt(prefix + "levelNumber") : 7;
1170+
int compactThreads = config.hasPath(prefix + "compactThreads")
1171+
? config.getInt(prefix + "compactThreads")
1172+
: max(Runtime.getRuntime().availableProcessors(), 1);
1173+
int blocksize = config.hasPath(prefix + "blocksize")
1174+
? config.getInt(prefix + "blocksize") : 16;
1175+
long maxBytesForLevelBase = config.hasPath(prefix + "maxBytesForLevelBase")
1176+
? config.getInt(prefix + "maxBytesForLevelBase") : 256;
1177+
double maxBytesForLevelMultiplier = config.hasPath(prefix + "maxBytesForLevelMultiplier")
1178+
? config.getDouble(prefix + "maxBytesForLevelMultiplier") : 10;
1179+
int level0FileNumCompactionTrigger =
1180+
config.hasPath(prefix + "level0FileNumCompactionTrigger") ? config
1181+
.getInt(prefix + "level0FileNumCompactionTrigger") : 2;
1182+
long targetFileSizeBase = config.hasPath(prefix + "targetFileSizeBase") ? config
1183+
.getLong(prefix + "targetFileSizeBase") : 64;
1184+
int targetFileSizeMultiplier = config.hasPath(prefix + "targetFileSizeMultiplier") ? config
1185+
.getInt(prefix + "targetFileSizeMultiplier") : 1;
1186+
1187+
INSTANCE.rocksDBCustomSettings = DBSettings
1188+
.initCustomSettings(levelNumber, compactThreads, blocksize, maxBytesForLevelBase,
1189+
maxBytesForLevelMultiplier, level0FileNumCompactionTrigger,
1190+
targetFileSizeBase, targetFileSizeMultiplier);
1191+
DBSettings.loggingSettings();
11881192
}
11891193

11901194
private static void initRocksDbBackupProperty(Config config) {
1191-
boolean enable = false;
1192-
if (Args.getInstance().getStorage().getDbEngine().toUpperCase().equals("ROCKSDB")) {
1193-
enable =
1194-
config.hasPath("storage.backup.enable") && config.getBoolean("storage.backup.enable");
1195-
}
1195+
boolean enable =
1196+
config.hasPath("storage.backup.enable") && config.getBoolean("storage.backup.enable");
11961197
String propPath = config.hasPath("storage.backup.propPath")
11971198
? config.getString("storage.backup.propPath") : "prop.properties";
11981199
String bak1path = config.hasPath("storage.backup.bak1path")

‎src/main/java/org/tron/core/config/args/Storage.java‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public class Storage {
126126
@Getter
127127
@Setter
128128
private static class Property {
129+
129130
private String name;
130131
private String path;
131132
private Options dbOptions;
@@ -148,7 +149,7 @@ public static String getDbEngineFromConfig(final Config config) {
148149

149150
public static Boolean getDbVersionSyncFromConfig(final Config config) {
150151
return config.hasPath(DB_SYNC_CONFIG_KEY) ?
151-
config.getBoolean(DB_SYNC_CONFIG_KEY) : DEFAULT_DB_SYNC;
152+
config.getBoolean(DB_SYNC_CONFIG_KEY) : DEFAULT_DB_SYNC;
152153
}
153154

154155
public static String getDbDirectoryFromConfig(final Config config) {
@@ -168,8 +169,8 @@ public static String getIndexSwitchFromConfig(final Config config) {
168169
}
169170

170171
public static String getTransactionHistoreSwitchFromConfig(final Config config) {
171-
return config.hasPath(TRANSACTIONHISTORY_SWITCH_CONFIG_KEY)?
172-
config.getString(TRANSACTIONHISTORY_SWITCH_CONFIG_KEY) : DEFAULT_TRANSACTIONHISTORY_SWITCH;
172+
return config.hasPath(TRANSACTIONHISTORY_SWITCH_CONFIG_KEY) ?
173+
config.getString(TRANSACTIONHISTORY_SWITCH_CONFIG_KEY) : DEFAULT_TRANSACTIONHISTORY_SWITCH;
173174
}
174175

175176
/**
@@ -254,11 +255,13 @@ private static Property createProperty(final ConfigObject conf) {
254255

255256
File file = new File(path);
256257
if (!file.exists() && !file.mkdirs()) {
257-
throw new IllegalArgumentException("[storage.properties] can not create storage path: " + path);
258+
throw new IllegalArgumentException(
259+
"[storage.properties] can not create storage path: " + path);
258260
}
259261

260262
if (!file.canWrite()) {
261-
throw new IllegalArgumentException("[storage.properties] permission denied to write to: " + path);
263+
throw new IllegalArgumentException(
264+
"[storage.properties] permission denied to write to: " + path);
262265
}
263266

264267
property.setPath(path);
@@ -301,7 +304,8 @@ private static Property createProperty(final ConfigObject conf) {
301304
)
302305
);
303306
} catch (NumberFormatException e) {
304-
throw new IllegalArgumentException("[storage.properties] compressionType must be Integer type.");
307+
throw new IllegalArgumentException(
308+
"[storage.properties] compressionType must be Integer type.");
305309
}
306310
}
307311

@@ -325,7 +329,8 @@ private static Property createProperty(final ConfigObject conf) {
325329
)
326330
);
327331
} catch (NumberFormatException e) {
328-
throw new IllegalArgumentException("[storage.properties] writeBufferSize must be Integer type.");
332+
throw new IllegalArgumentException(
333+
"[storage.properties] writeBufferSize must be Integer type.");
329334
}
330335
}
331336

@@ -349,7 +354,8 @@ private static Property createProperty(final ConfigObject conf) {
349354
)
350355
);
351356
} catch (NumberFormatException e) {
352-
throw new IllegalArgumentException("[storage.properties] maxOpenFiles must be Integer type.");
357+
throw new IllegalArgumentException(
358+
"[storage.properties] maxOpenFiles must be Integer type.");
353359
}
354360
}
355361

0 commit comments

Comments
 (0)