Skip to content

Commit

Permalink
feat(db): print db internal log
Browse files Browse the repository at this point in the history
1.print db internal log
  • Loading branch information
morgan committed Dec 12, 2022
1 parent adc6b6b commit 4f9a7e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
import org.iq80.leveldb.CompressionType;
import org.iq80.leveldb.DB;
import org.iq80.leveldb.DBIterator;
import org.iq80.leveldb.Logger;
import org.iq80.leveldb.Options;
import org.iq80.leveldb.ReadOptions;
import org.iq80.leveldb.WriteBatch;
import org.iq80.leveldb.WriteOptions;
import org.slf4j.LoggerFactory;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.storage.WriteOptionsWrapper;
import org.tron.common.storage.metric.DbStat;
Expand All @@ -71,6 +73,7 @@ public class LevelDbDataSourceImpl extends DbStat implements DbSourceInter<byte[
private WriteOptions writeOptions;
private ReadWriteLock resetDbLock = new ReentrantReadWriteLock();
private static final String LEVELDB = "LEVELDB";
private static final Logger leveldbLogger = LoggerFactory.getLogger(LEVELDB)::info;

/**
* constructor.
Expand All @@ -82,7 +85,7 @@ public LevelDbDataSourceImpl(String parentPath, String dataBaseName, Options opt
CommonParameter.getInstance().getStorage().getDbDirectory()
).toString();
this.dataBaseName = dataBaseName;
this.options = options;
this.options = options.logger(leveldbLogger);
this.writeOptions = writeOptions;
initDB();
}
Expand All @@ -94,7 +97,7 @@ public LevelDbDataSourceImpl(String parentPath, String dataBaseName) {
).toString();

this.dataBaseName = dataBaseName;
options = new Options();
options = new Options().logger(leveldbLogger);
writeOptions = new WriteOptions();
}

Expand Down Expand Up @@ -163,6 +166,7 @@ private Options createDbOptions() {
dbOptions.paranoidChecks(true);
dbOptions.verifyChecksums(true);
dbOptions.maxOpenFiles(32);
dbOptions.logger(leveldbLogger);
return dbOptions;
}

Expand Down Expand Up @@ -196,7 +200,7 @@ public void destroyDb(File fileLocation) {
resetDbLock.writeLock().lock();
try {
logger.debug("Destroying existing database: " + fileLocation);
Options options = new Options();
Options options = new Options().logger(leveldbLogger);
try {
factory.destroy(fileLocation, options);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.rocksdb.BloomFilter;
import org.rocksdb.Checkpoint;
import org.rocksdb.DirectComparator;
import org.rocksdb.InfoLogLevel;
import org.rocksdb.Logger;
import org.rocksdb.Options;
import org.rocksdb.ReadOptions;
import org.rocksdb.RocksDB;
Expand All @@ -32,6 +34,7 @@
import org.rocksdb.Statistics;
import org.rocksdb.WriteBatch;
import org.rocksdb.WriteOptions;
import org.slf4j.LoggerFactory;
import org.tron.common.setting.RocksDbSettings;
import org.tron.common.storage.WriteOptionsWrapper;
import org.tron.common.storage.metric.DbStat;
Expand All @@ -57,6 +60,7 @@ public class RocksDbDataSourceImpl extends DbStat implements DbSourceInter<byte[
private static final String KEY_ENGINE = "ENGINE";
private static final String ROCKSDB = "ROCKSDB";
private DirectComparator comparator;
private static final org.slf4j.Logger rocksDbLogger = LoggerFactory.getLogger(ROCKSDB);

public RocksDbDataSourceImpl(String parentPath, String name, RocksDbSettings settings,
DirectComparator comparator) {
Expand Down Expand Up @@ -227,6 +231,12 @@ public void initDB(RocksDbSettings settings) {
if (comparator != null) {
options.setComparator(comparator);
}
options.setLogger(new Logger(options) {
@Override
protected void log(InfoLogLevel infoLogLevel, String logMsg) {
rocksDbLogger.info(logMsg);
}
});

// table options
final BlockBasedTableConfig tableCfg;
Expand Down

0 comments on commit 4f9a7e9

Please sign in to comment.