ethereum/ethereumj

DBSettings should be initialized in writeLock

chenjw13097 opened this issue · 3 comments

org.ethereum.datasource.rocksdb.RocksDbDataSource#init(org.ethereum.datasource.DbSettings)

old code is:
public void init(DbSettings settings) {
(1)this.settings = settings;
(2)resetDbLock.writeLock().lock();
try {
logger.debug("~> RocksDbDataSource.init(): " + name);

but it should be like this:
public void init(DbSettings settings) {
resetDbLock.writeLock().lock();
try {
this.settings = settings;
logger.debug("~> RocksDbDataSource.init(): " + name);

For old code, if two thread(T1 and T2) call the method with different DbSettings, follow code may be wrong(T1(1)->T2(1)->T1(2)->T2(2)):
options.setMaxOpenFiles(settings.getMaxOpenFiles());
options.setIncreaseParallelism(settings.getMaxThreads());

Could you please make a PR and provide a rationale behind this change in its description?

I did it with PR #1255.