mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-19 05:24:58 +00:00
Try for blockchain lock before tying up repository in BlockChain.trimOldOnlineAccountsSignatures
This commit is contained in:
parent
790f569dbd
commit
9b894616ee
@ -567,27 +567,27 @@ public class BlockChain {
|
|||||||
if (now == null)
|
if (now == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try (final Repository repository = RepositoryManager.tryRepository()) {
|
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
||||||
if (repository == null)
|
if (!blockchainLock.tryLock())
|
||||||
return;
|
// Too busy to trim right now, try again later
|
||||||
|
return;
|
||||||
|
|
||||||
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
try {
|
||||||
if (!blockchainLock.tryLock())
|
try (final Repository repository = RepositoryManager.tryRepository()) {
|
||||||
// Too busy to trim right now, try again later
|
if (repository == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
|
||||||
int numBlocksTrimmed = repository.getBlockRepository().trimOldOnlineAccountsSignatures(now - BlockChain.getInstance().getOnlineAccountSignaturesMaxLifetime());
|
int numBlocksTrimmed = repository.getBlockRepository().trimOldOnlineAccountsSignatures(now - BlockChain.getInstance().getOnlineAccountSignaturesMaxLifetime());
|
||||||
|
|
||||||
if (numBlocksTrimmed > 0)
|
if (numBlocksTrimmed > 0)
|
||||||
LOGGER.debug(String.format("Trimmed old online accounts signatures from %d block%s", numBlocksTrimmed, (numBlocksTrimmed != 1 ? "s" : "")));
|
LOGGER.debug(String.format("Trimmed old online accounts signatures from %d block%s", numBlocksTrimmed, (numBlocksTrimmed != 1 ? "s" : "")));
|
||||||
|
|
||||||
repository.saveChanges();
|
repository.saveChanges();
|
||||||
} finally {
|
} catch (DataException e) {
|
||||||
blockchainLock.unlock();
|
LOGGER.warn(String.format("Repository issue trying to trim old online accounts signatures: %s", e.getMessage()));
|
||||||
}
|
}
|
||||||
} catch (DataException e) {
|
} finally {
|
||||||
LOGGER.warn(String.format("Repository issue trying to trim old online accounts signatures: %s", e.getMessage()));
|
blockchainLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user