Skip to content

Commit fbdf080

Browse files
committed
db2 rocksdb
1 parent d5f50d7 commit fbdf080

19 files changed

Lines changed: 49 additions & 1121 deletions

‎src/main/java/org/tron/core/Constant.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public class Constant {
3232

3333
//config for junit test
3434
public static final String TEST_CONF = "config-test.conf";
35-
public static final String TESTBACKUP_CONF = "config-dbbackup.conf";
3635

3736
public static final String DATABASE_DIR = "storage.directory";
3837

‎src/main/java/org/tron/core/config/DefaultConfig.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.tron.core.config.args.Args;
1313
import org.tron.core.db.RevokingDatabase;
1414
import org.tron.core.db.RevokingStore;
15-
import org.tron.core.db.RevokingStoreRocks;
1615
import org.tron.core.db.TransactionCache;
1716
import org.tron.core.db.api.IndexHelper;
1817
import org.tron.core.db.backup.BackupRocksDBAspect;
@@ -58,10 +57,6 @@ public RevokingDatabase revokingDatabase() {
5857
revokingDatabase = RevokingStore.getInstance();
5958
} else if (dbVersion == 2) {
6059
revokingDatabase = new SnapshotManager();
61-
} else if (dbVersion == 3) {
62-
revokingDatabase = RevokingStoreRocks.getInstance();
63-
} else if (dbVersion == 4) {
64-
revokingDatabase = new SnapshotManager();
6560
} else {
6661
throw new RuntimeException("db version is error.");
6762
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ public class Args {
123123
@Parameter(names = {"--storage-db-version"}, description = "Storage db version.(1 or 2)")
124124
private String storageDbVersion = "";
125125

126+
@Parameter(names = {
127+
"--storage-db-engine"}, description = "Storage db engine.(leveldb or rocksdb)")
128+
private String storageDbEngine = "";
129+
126130
@Parameter(names = {
127131
"--storage-db-synchronous"}, description = "Storage db is synchronous or not.(true or flase)")
128132
private String storageDbSynchronous = "";
@@ -612,6 +616,10 @@ public static void setParam(final String[] args, final String confFileName) {
612616
.map(Integer::valueOf)
613617
.orElse(Storage.getDbVersionFromConfig(config)));
614618

619+
INSTANCE.storage.setDbEngine(Optional.ofNullable(INSTANCE.storageDbEngine)
620+
.filter(StringUtils::isNotEmpty)
621+
.orElse(Storage.getDbEngineFromConfig(config)));
622+
615623
INSTANCE.storage.setDbSync(Optional.ofNullable(INSTANCE.storageDbSynchronous)
616624
.filter(StringUtils::isNotEmpty)
617625
.map(Boolean::valueOf)
@@ -1140,8 +1148,7 @@ private static double calcMaxTimeRatio() {
11401148
private static void initRocksDbSettings(Config config) {
11411149
String prefix = "storage.dbSettings.";
11421150

1143-
if (Args.getInstance().getStorage().getDbVersion() == 3
1144-
|| Args.getInstance().getStorage().getDbVersion() == 4) {
1151+
if (Args.getInstance().getStorage().getDbEngine().equals("ROCKSDB")) {
11451152
int levelNumber = config.hasPath(prefix + "levelNumber")
11461153
? config.getInt(prefix + "levelNumber") : 7;
11471154
int compactThreads = config.hasPath(prefix + "compactThreads")
@@ -1173,8 +1180,7 @@ private static void initRocksDbSettings(Config config) {
11731180

11741181
private static void initRocksDbBackupProperty(Config config) {
11751182
boolean enable = false;
1176-
if (Args.getInstance().getStorage().getDbVersion() == 3
1177-
|| Args.getInstance().getStorage().getDbVersion() == 4) {
1183+
if (Args.getInstance().getStorage().getDbEngine().toUpperCase().equals("ROCKSDB")) {
11781184
enable =
11791185
config.hasPath("storage.backup.enable") && config.getBoolean("storage.backup.enable");
11801186
}
@@ -1223,6 +1229,7 @@ private static void logConfig() {
12231229
logger.info("Code version : {}", Version.getVersion());
12241230
logger.info("************************ DB config *************************");
12251231
logger.info("DB version : {}", args.getStorage().getDbVersion());
1232+
logger.info("DB engine : {}", args.getStorage().getDbEngine());
12261233
logger.info("***************************************************************");
12271234
logger.info("\n");
12281235
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class Storage {
4242
*/
4343
private static final String DB_DIRECTORY_CONFIG_KEY = "storage.db.directory";
4444
private static final String DB_VERSION_CONFIG_KEY = "storage.db.version";
45+
private static final String DB_ENGINE_CONFIG_KEY = "storage.db.engine";
4546
private static final String DB_SYNC_CONFIG_KEY = "storage.db.sync";
4647
private static final String INDEX_DIRECTORY_CONFIG_KEY = "storage.index.directory";
4748
private static final String INDEX_SWITCH_CONFIG_KEY = "storage.index.switch";
@@ -64,6 +65,7 @@ public class Storage {
6465
* Default values of directory
6566
*/
6667
private static final int DEFAULT_DB_VERSION = 2;
68+
private static final String DEFAULT_DB_ENGINE = "LEVELDB";
6769
private static final boolean DEFAULT_DB_SYNC = false;
6870
private static final String DEFAULT_DB_DIRECTORY = "database";
6971
private static final String DEFAULT_INDEX_DIRECTORY = "index";
@@ -95,6 +97,10 @@ public class Storage {
9597
@Setter
9698
private int dbVersion;
9799

100+
@Getter
101+
@Setter
102+
private String dbEngine;
103+
98104
@Getter
99105
@Setter
100106
private boolean dbSync;
@@ -135,6 +141,11 @@ public static int getDbVersionFromConfig(final Config config) {
135141
config.getInt(DB_VERSION_CONFIG_KEY) : DEFAULT_DB_VERSION;
136142
}
137143

144+
public static String getDbEngineFromConfig(final Config config) {
145+
return config.hasPath(DB_ENGINE_CONFIG_KEY) ?
146+
config.getString(DB_ENGINE_CONFIG_KEY) : DEFAULT_DB_ENGINE;
147+
}
148+
138149
public static Boolean getDbVersionSyncFromConfig(final Config config) {
139150
return config.hasPath(DB_SYNC_CONFIG_KEY) ?
140151
config.getBoolean(DB_SYNC_CONFIG_KEY) : DEFAULT_DB_SYNC;

0 commit comments

Comments
 (0)