Skip to content

Commit

Permalink
AKI-672: Call repository close on main instance
Browse files Browse the repository at this point in the history
When the close method is called due to a critical error the databases
that are not copied into a snapshot may remain open. This is because
during execution the main repository can be stashed while a snapshot
is used for the block import.
  • Loading branch information
AlexandraRoatis committed Mar 6, 2020
1 parent 29380f7 commit c1b66dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
public class AionBlockchainImpl implements IAionBlockchain {

private static final Logger LOG = LoggerFactory.getLogger(LogEnum.CONS.name());
private static final Logger GEN_LOG = LoggerFactory.getLogger(LogEnum.GEN.name());
private static final Logger SURVEY_LOG = LoggerFactory.getLogger(LogEnum.SURVEY.name());
private static final Logger SYNC_LOG = LoggerFactory.getLogger(LogEnum.SYNC.name());
private static final Logger TX_LOG = LoggerFactory.getLogger(LogEnum.TX.name());
Expand Down Expand Up @@ -2186,6 +2187,18 @@ public synchronized void setBestBlock(Block block) {

@Override
public synchronized void close() {
// The main repository instance is stashed when the snapshot is created. If the current repository is a snapshot that means the main one is in the stack.
// We pop the stack until we get to the main repository instance that contains access too all the databases that must be closed.
while (repository.isSnapshot()) {
popState();
}

// We do not flush before closing the database because under normal circumstances the repository was already flushed.
// If close was called due to an error (like a VM issue) then flushing may store corrupt data, so it shouldn't be done.
GEN_LOG.info("shutting down DB...");
repository.close();
GEN_LOG.info("shutdown DB... Done!");

SURVEY_LOG.info("Total import#[{}], importTime[{}]ms, 1s+Import#[{}], 10s+Import#[{}] longestImport[{}]ms",
surveyTotalImportedBlocks,
(surveyTotalImportTime / DIVISOR_MS),
Expand Down
6 changes: 0 additions & 6 deletions modAionImpl/src/org/aion/zero/impl/blockchain/AionHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,6 @@ public void close() {
genLOG.info("shutdown consensus... Done!");
}

if (blockchain.getRepository() != null) {
genLOG.info("shutting down DB...");
blockchain.getRepository().close();
genLOG.info("shutdown DB... Done!");
}

blockchain.close();

this.start.set(false);
Expand Down

0 comments on commit c1b66dd

Please sign in to comment.