Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,22 @@ private void openDatabase(Options dbOptions) throws IOException {
if (!Files.isSymbolicLink(dbPath.getParent())) {
Files.createDirectories(dbPath.getParent());
}
database = factory.open(dbPath.toFile(), dbOptions);
if (!this.getDBName().startsWith("checkpoint")) {
logger.info("DB {} open success with writeBufferSize {} M, cacheSize {} M, maxOpenFiles {}.",
this.getDBName(), dbOptions.writeBufferSize() / 1024 / 1024,
dbOptions.cacheSize() / 1024 / 1024, dbOptions.maxOpenFiles());
try {
database = factory.open(dbPath.toFile(), dbOptions);
if (!this.getDBName().startsWith("checkpoint")) {
logger
.info("DB {} open success with writeBufferSize {} M, cacheSize {} M, maxOpenFiles {}.",
this.getDBName(), dbOptions.writeBufferSize() / 1024 / 1024,
dbOptions.cacheSize() / 1024 / 1024, dbOptions.maxOpenFiles());
}
} catch (IOException e) {
if (e.getMessage().contains("Corruption:")) {
logger.error("Database {} corrupted, please delete database directory({}) and restart.",
dataBaseName, parentPath, e);
} else {
logger.error("Open Database {} failed", dataBaseName, e);
}
System.exit(1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.rocksdb.RocksDBException;
import org.rocksdb.RocksIterator;
import org.rocksdb.Statistics;
import org.rocksdb.Status;
import org.rocksdb.WriteBatch;
import org.rocksdb.WriteOptions;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -265,8 +266,13 @@ protected void log(InfoLogLevel infoLogLevel, String logMsg) {
try {
database = RocksDB.open(options, dbPath.toString());
} catch (RocksDBException e) {
Comment thread
lurais marked this conversation as resolved.
throw new RuntimeException(
String.format("failed to open database: %s", dataBaseName), e);
if (Objects.equals(e.getStatus().getCode(), Status.Code.Corruption)) {
logger.error("Database {} corrupted, please delete database directory({}) " +
"and restart.", dataBaseName, parentPath, e);
} else {
logger.error("Open Database {} failed", dataBaseName, e);
}
System.exit(1);
}

alive = true;
Expand Down
1 change: 1 addition & 0 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.13.2'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.13.0'
testCompile group: 'org.hamcrest', name: 'hamcrest-junit', version: '1.0.0.1'
testCompile group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.16.0'

compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.FileUtil;
import org.tron.common.utils.PublicMethod;
Expand Down Expand Up @@ -65,6 +67,9 @@ public class LevelDbDataSourceImplTest {
private byte[] key5 = "00000005aa".getBytes();
private byte[] key6 = "00000006aa".getBytes();

@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

/**
* Release resources.
*/
Expand Down Expand Up @@ -332,4 +337,24 @@ public void prefixQueryTest() {
dataSource.resetDb();
dataSource.closeDB();
}

@Test
public void initDbTest() {
exit.expectSystemExitWithStatus(1);
makeExceptionDb("test_initDb");
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(
Args.getInstance().getOutputDirectory(), "test_initDb");
dataSource.initDB();
dataSource.closeDB();
}

private void makeExceptionDb(String dbName) {
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(
Args.getInstance().getOutputDirectory(), "test_initDb");
dataSource.initDB();
dataSource.closeDB();
FileUtil.saveData(dataSource.getDbPath().toString() + "/CURRENT",
"...", Boolean.FALSE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
import org.tron.common.storage.rocksdb.RocksDbDataSourceImpl;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.FileUtil;
Expand Down Expand Up @@ -48,6 +50,9 @@ public class RocksDbDataSourceImplTest {
private byte[] key5 = "00000005aa".getBytes();
private byte[] key6 = "00000006aa".getBytes();

@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

/**
* Release resources.
*/
Expand Down Expand Up @@ -382,4 +387,23 @@ public void prefixQueryTest() {
dataSource.resetDb();
dataSource.closeDB();
}

@Test
public void initDbTest() {
exit.expectSystemExitWithStatus(1);
makeExceptionDb("test_initDb");
RocksDbDataSourceImpl dataSource = new RocksDbDataSourceImpl(
Args.getInstance().getOutputDirectory(), "test_initDb");
dataSource.initDB();
dataSource.closeDB();
}

private void makeExceptionDb(String dbName) {
RocksDbDataSourceImpl dataSource = new RocksDbDataSourceImpl(
Args.getInstance().getOutputDirectory(), "test_initDb");
dataSource.initDB();
dataSource.closeDB();
FileUtil.saveData(dataSource.getDbPath().toString() + "/CURRENT",
"...", Boolean.FALSE);
}
}