mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-27 07:45:53 +00:00
broader exception handling and added verbosity to the logging
This commit is contained in:
parent
3043d1c2cb
commit
85910573a3
@ -46,72 +46,74 @@ public class AtStatesPruner implements Runnable {
|
|||||||
repository.saveChanges();
|
repository.saveChanges();
|
||||||
|
|
||||||
while (!Controller.isStopping()) {
|
while (!Controller.isStopping()) {
|
||||||
repository.discardChanges();
|
try {
|
||||||
|
repository.discardChanges();
|
||||||
|
|
||||||
Thread.sleep(Settings.getInstance().getAtStatesPruneInterval());
|
Thread.sleep(Settings.getInstance().getAtStatesPruneInterval());
|
||||||
|
|
||||||
BlockData chainTip = Controller.getInstance().getChainTip();
|
BlockData chainTip = Controller.getInstance().getChainTip();
|
||||||
if (chainTip == null || NTP.getTime() == null)
|
if (chainTip == null || NTP.getTime() == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Don't even attempt if we're mid-sync as our repository requests will be delayed for ages
|
// Don't even attempt if we're mid-sync as our repository requests will be delayed for ages
|
||||||
if (Synchronizer.getInstance().isSynchronizing())
|
if (Synchronizer.getInstance().isSynchronizing())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Prune AT states for all blocks up until our latest minus pruneBlockLimit
|
// Prune AT states for all blocks up until our latest minus pruneBlockLimit
|
||||||
final int ourLatestHeight = chainTip.getHeight();
|
final int ourLatestHeight = chainTip.getHeight();
|
||||||
int upperPrunableHeight = ourLatestHeight - Settings.getInstance().getPruneBlockLimit();
|
int upperPrunableHeight = ourLatestHeight - Settings.getInstance().getPruneBlockLimit();
|
||||||
|
|
||||||
// In archive mode we are only allowed to trim blocks that have already been archived
|
// In archive mode we are only allowed to trim blocks that have already been archived
|
||||||
if (archiveMode) {
|
if (archiveMode) {
|
||||||
upperPrunableHeight = repository.getBlockArchiveRepository().getBlockArchiveHeight() - 1;
|
upperPrunableHeight = repository.getBlockArchiveRepository().getBlockArchiveHeight() - 1;
|
||||||
|
|
||||||
// TODO: validate that the actual archived data exists before pruning it?
|
// TODO: validate that the actual archived data exists before pruning it?
|
||||||
}
|
}
|
||||||
|
|
||||||
int upperBatchHeight = pruneStartHeight + Settings.getInstance().getAtStatesPruneBatchSize();
|
int upperBatchHeight = pruneStartHeight + Settings.getInstance().getAtStatesPruneBatchSize();
|
||||||
int upperPruneHeight = Math.min(upperBatchHeight, upperPrunableHeight);
|
int upperPruneHeight = Math.min(upperBatchHeight, upperPrunableHeight);
|
||||||
|
|
||||||
if (pruneStartHeight >= upperPruneHeight)
|
if (pruneStartHeight >= upperPruneHeight)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LOGGER.debug(String.format("Pruning AT states between blocks %d and %d...", pruneStartHeight, upperPruneHeight));
|
LOGGER.info(String.format("Pruning AT states between blocks %d and %d...", pruneStartHeight, upperPruneHeight));
|
||||||
|
|
||||||
int numAtStatesPruned = repository.getATRepository().pruneAtStates(pruneStartHeight, upperPruneHeight);
|
int numAtStatesPruned = repository.getATRepository().pruneAtStates(pruneStartHeight, upperPruneHeight);
|
||||||
repository.saveChanges();
|
repository.saveChanges();
|
||||||
int numAtStateDataRowsTrimmed = repository.getATRepository().trimAtStates(
|
int numAtStateDataRowsTrimmed = repository.getATRepository().trimAtStates(
|
||||||
pruneStartHeight, upperPruneHeight, Settings.getInstance().getAtStatesTrimLimit());
|
pruneStartHeight, upperPruneHeight, Settings.getInstance().getAtStatesTrimLimit());
|
||||||
repository.saveChanges();
|
repository.saveChanges();
|
||||||
|
|
||||||
if (numAtStatesPruned > 0 || numAtStateDataRowsTrimmed > 0) {
|
|
||||||
final int finalPruneStartHeight = pruneStartHeight;
|
|
||||||
LOGGER.debug(() -> String.format("Pruned %d AT state%s between blocks %d and %d",
|
|
||||||
numAtStatesPruned, (numAtStatesPruned != 1 ? "s" : ""),
|
|
||||||
finalPruneStartHeight, upperPruneHeight));
|
|
||||||
} else {
|
|
||||||
// Can we move onto next batch?
|
|
||||||
if (upperPrunableHeight > upperBatchHeight) {
|
|
||||||
pruneStartHeight = upperBatchHeight;
|
|
||||||
repository.getATRepository().setAtPruneHeight(pruneStartHeight);
|
|
||||||
maxLatestAtStatesHeight = PruneManager.getMaxHeightForLatestAtStates(repository);
|
|
||||||
repository.getATRepository().rebuildLatestAtStates(maxLatestAtStatesHeight);
|
|
||||||
repository.saveChanges();
|
|
||||||
|
|
||||||
|
if (numAtStatesPruned > 0 || numAtStateDataRowsTrimmed > 0) {
|
||||||
final int finalPruneStartHeight = pruneStartHeight;
|
final int finalPruneStartHeight = pruneStartHeight;
|
||||||
LOGGER.debug(() -> String.format("Bumping AT state base prune height to %d", finalPruneStartHeight));
|
LOGGER.info(() -> String.format("Pruned %d AT state%s between blocks %d and %d",
|
||||||
}
|
numAtStatesPruned, (numAtStatesPruned != 1 ? "s" : ""),
|
||||||
else {
|
finalPruneStartHeight, upperPruneHeight));
|
||||||
// We've pruned up to the upper prunable height
|
} else {
|
||||||
// Back off for a while to save CPU for syncing
|
// Can we move onto next batch?
|
||||||
repository.discardChanges();
|
if (upperPrunableHeight > upperBatchHeight) {
|
||||||
Thread.sleep(5*60*1000L);
|
pruneStartHeight = upperBatchHeight;
|
||||||
|
repository.getATRepository().setAtPruneHeight(pruneStartHeight);
|
||||||
|
maxLatestAtStatesHeight = PruneManager.getMaxHeightForLatestAtStates(repository);
|
||||||
|
repository.getATRepository().rebuildLatestAtStates(maxLatestAtStatesHeight);
|
||||||
|
repository.saveChanges();
|
||||||
|
|
||||||
|
final int finalPruneStartHeight = pruneStartHeight;
|
||||||
|
LOGGER.info(() -> String.format("Bumping AT state base prune height to %d", finalPruneStartHeight));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// We've pruned up to the upper prunable height
|
||||||
|
// Back off for a while to save CPU for syncing
|
||||||
|
repository.discardChanges();
|
||||||
|
Thread.sleep(5*60*1000L);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.warn("Pruning stopped working. Trying again. Report this error immediately to the developers.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (DataException e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn(String.format("Repository issue trying to prune AT states: %s", e.getMessage()));
|
LOGGER.error("Pruning is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// Time to exit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user