Skip to content

Commit

Permalink
Merge pull request #4836 from lurais/feature/rm_useless_revokingDB
Browse files Browse the repository at this point in the history
refactor(db): remove useless revokingDB
  • Loading branch information
halibobo1205 authored Dec 13, 2022
2 parents 2fe10e3 + 2898d48 commit 0705f24
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 1,318 deletions.
477 changes: 0 additions & 477 deletions chainbase/src/main/java/org/tron/core/db/AbstractRevokingStore.java

This file was deleted.

25 changes: 0 additions & 25 deletions chainbase/src/main/java/org/tron/core/db/RevokingStore.java

This file was deleted.

67 changes: 19 additions & 48 deletions chainbase/src/main/java/org/tron/core/db/TronStoreWithRevoking.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javax.annotation.PostConstruct;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.iq80.leveldb.Options;
import org.iq80.leveldb.WriteOptions;
import org.rocksdb.DirectComparator;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -33,7 +32,6 @@
import org.tron.core.db2.common.WrappedByteArray;
import org.tron.core.db2.core.Chainbase;
import org.tron.core.db2.core.ITronChainBase;
import org.tron.core.db2.core.RevokingDBWithCachingOldValue;
import org.tron.core.db2.core.SnapshotRoot;
import org.tron.core.exception.BadItemException;
import org.tron.core.exception.ItemNotFoundException;
Expand All @@ -56,35 +54,26 @@ public abstract class TronStoreWithRevoking<T extends ProtoCapsule> implements I
private DB<byte[], byte[]> db;

protected TronStoreWithRevoking(String dbName) {
int dbVersion = CommonParameter.getInstance().getStorage().getDbVersion();
String dbEngine = CommonParameter.getInstance().getStorage().getDbEngine();
if (dbVersion == 1) {
this.revokingDB = new RevokingDBWithCachingOldValue(dbName,
getOptionsByDbNameForLevelDB(dbName));
} else if (dbVersion == 2) {
if ("LEVELDB".equals(dbEngine.toUpperCase())) {
this.db = new LevelDB(
new LevelDbDataSourceImpl(StorageUtils.getOutputDirectoryByDbName(dbName),
dbName,
getOptionsByDbNameForLevelDB(dbName),
new WriteOptions().sync(CommonParameter.getInstance()
.getStorage().isDbSync())));
} else if ("ROCKSDB".equals(dbEngine.toUpperCase())) {
String parentPath = Paths
.get(StorageUtils.getOutputDirectoryByDbName(dbName), CommonParameter
.getInstance().getStorage().getDbDirectory()).toString();
this.db = new RocksDB(
new RocksDbDataSourceImpl(parentPath,
dbName, CommonParameter.getInstance()
.getRocksDBCustomSettings(), getDirectComparator()));
} else {
throw new RuntimeException(String.format("db engine %s is error", dbEngine));
}
this.revokingDB = new Chainbase(new SnapshotRoot(this.db));

if ("LEVELDB".equals(dbEngine.toUpperCase())) {
this.db = new LevelDB(
new LevelDbDataSourceImpl(StorageUtils.getOutputDirectoryByDbName(dbName),
dbName,
getOptionsByDbNameForLevelDB(dbName),
new WriteOptions().sync(CommonParameter.getInstance()
.getStorage().isDbSync())));
} else if ("ROCKSDB".equals(dbEngine.toUpperCase())) {
String parentPath = Paths
.get(StorageUtils.getOutputDirectoryByDbName(dbName), CommonParameter
.getInstance().getStorage().getDbDirectory()).toString();
this.db = new RocksDB(
new RocksDbDataSourceImpl(parentPath,
dbName, CommonParameter.getInstance()
.getRocksDBCustomSettings(), getDirectComparator()));
} else {
throw new RuntimeException(String.format("db version %d is error", dbVersion));
throw new RuntimeException(String.format("db engine %s is error", dbEngine));
}
this.revokingDB = new Chainbase(new SnapshotRoot(this.db));
}

protected org.iq80.leveldb.Options getOptionsByDbNameForLevelDB(String dbName) {
Expand All @@ -96,26 +85,8 @@ protected DirectComparator getDirectComparator() {
}

protected TronStoreWithRevoking(DB<byte[], byte[]> db) {
int dbVersion = CommonParameter.getInstance().getStorage().getDbVersion();
if (dbVersion == 2) {
this.db = db;
this.revokingDB = new Chainbase(new SnapshotRoot(db));
} else {
throw new RuntimeException(String.format("db version is only 2, actual: %d", dbVersion));
}
}

// only for test
protected TronStoreWithRevoking(String dbName, RevokingDatabase revokingDatabase) {
this.revokingDB = new RevokingDBWithCachingOldValue(dbName,
(AbstractRevokingStore) revokingDatabase);
}

// only for test
protected TronStoreWithRevoking(String dbName, Options options,
RevokingDatabase revokingDatabase) {
this.revokingDB = new RevokingDBWithCachingOldValue(dbName, options,
(AbstractRevokingStore) revokingDatabase);
this.db = db;
this.revokingDB = new Chainbase(new SnapshotRoot(db));
}

@Override
Expand Down
37 changes: 16 additions & 21 deletions chainbase/src/main/java/org/tron/core/db2/common/TxCacheDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,24 @@ public TxCacheDB(String name, RecentTransactionStore recentTransactionStore) {
this.TRANSACTION_COUNT =
CommonParameter.getInstance().getStorage().getEstimatedBlockTransactions();
this.recentTransactionStore = recentTransactionStore;
int dbVersion = CommonParameter.getInstance().getStorage().getDbVersion();
String dbEngine = CommonParameter.getInstance().getStorage().getDbEngine();
if (dbVersion == 2) {
if ("LEVELDB".equals(dbEngine.toUpperCase())) {
this.persistentStore = new LevelDB(
new LevelDbDataSourceImpl(StorageUtils.getOutputDirectoryByDbName(name),
name, StorageUtils.getOptionsByDbName(name),
new WriteOptions().sync(CommonParameter.getInstance()
.getStorage().isDbSync())));
} else if ("ROCKSDB".equals(dbEngine.toUpperCase())) {
String parentPath = Paths
.get(StorageUtils.getOutputDirectoryByDbName(name), CommonParameter
.getInstance().getStorage().getDbDirectory()).toString();

this.persistentStore = new RocksDB(
new RocksDbDataSourceImpl(parentPath,
name, CommonParameter.getInstance()
.getRocksDBCustomSettings()));
} else {
throw new RuntimeException(String.format("db type: %s is not supported", dbEngine));
}
if ("LEVELDB".equals(dbEngine.toUpperCase())) {
this.persistentStore = new LevelDB(
new LevelDbDataSourceImpl(StorageUtils.getOutputDirectoryByDbName(name),
name, StorageUtils.getOptionsByDbName(name),
new WriteOptions().sync(CommonParameter.getInstance()
.getStorage().isDbSync())));
} else if ("ROCKSDB".equals(dbEngine.toUpperCase())) {
String parentPath = Paths
.get(StorageUtils.getOutputDirectoryByDbName(name), CommonParameter
.getInstance().getStorage().getDbDirectory()).toString();

this.persistentStore = new RocksDB(
new RocksDbDataSourceImpl(parentPath,
name, CommonParameter.getInstance()
.getRocksDBCustomSettings()));
} else {
throw new RuntimeException(String.format("db version: %d is not supported", dbVersion));
throw new RuntimeException(String.format("db type: %s is not supported", dbEngine));
}
this.bloomFilters[0] = BloomFilter.create(Funnels.byteArrayFunnel(),
MAX_BLOCK_SIZE * TRANSACTION_COUNT);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ public class CommonParameter {
public String password;
@Parameter(names = {"--storage-db-directory"}, description = "Storage db directory")
public String storageDbDirectory = "";
@Parameter(names = {"--storage-db-version"}, description = "Storage db version.(1 or 2)")
public String storageDbVersion = "";
@Parameter(names = {
"--storage-db-engine"}, description = "Storage db engine.(leveldb or rocksdb)")
public String storageDbEngine = "";
Expand Down
Loading

0 comments on commit 0705f24

Please sign in to comment.