Removed maxDuplicatedBlocksWhenArchiving setting as it's no longer needed.

This commit is contained in:
CalDescent 2021-09-12 09:52:28 +01:00
parent 70c6048cc1
commit 5656de79a2
5 changed files with 8 additions and 33 deletions

View File

@ -35,7 +35,7 @@ public class BlockArchiver implements Runnable {
while (!Controller.isStopping()) { while (!Controller.isStopping()) {
repository.discardChanges(); repository.discardChanges();
final int maximumArchiveHeight = BlockArchiveWriter.getMaxArchiveHeight(repository, true); final int maximumArchiveHeight = BlockArchiveWriter.getMaxArchiveHeight(repository);
Thread.sleep(Settings.getInstance().getArchiveInterval()); Thread.sleep(Settings.getInstance().getArchiveInterval());

View File

@ -42,34 +42,16 @@ public class BlockArchiveWriter {
this.repository = repository; this.repository = repository;
} }
public static int getMaxArchiveHeight(Repository repository, boolean useMaximumDuplicatedLimit) throws DataException { public static int getMaxArchiveHeight(Repository repository) throws DataException {
// We must only archive trimmed blocks, or the archive will grow far too large // We must only archive trimmed blocks, or the archive will grow far too large
final int accountSignaturesTrimStartHeight = repository.getBlockRepository().getOnlineAccountsSignaturesTrimHeight(); final int accountSignaturesTrimStartHeight = repository.getBlockRepository().getOnlineAccountsSignaturesTrimHeight();
final int atTrimStartHeight = repository.getATRepository().getAtTrimHeight(); final int atTrimStartHeight = repository.getATRepository().getAtTrimHeight();
final int trimStartHeight = Math.min(accountSignaturesTrimStartHeight, atTrimStartHeight); final int trimStartHeight = Math.min(accountSignaturesTrimStartHeight, atTrimStartHeight);
return trimStartHeight - 1; // subtract 1 because these values represent the first _untrimmed_ block
// In some cases we want to restrict the upper height of the archiver to save space
if (useMaximumDuplicatedLimit) {
// To save on disk space, it's best to not allow the archiver to get too far ahead of the pruner
// This reduces the amount of data that is held twice during the transition
final int blockPruneStartHeight = repository.getBlockRepository().getBlockPruneHeight();
final int atPruneStartHeight = repository.getATRepository().getAtPruneHeight();
final int pruneStartHeight = Math.min(blockPruneStartHeight, atPruneStartHeight);
final int maximumDuplicatedBlocks = Settings.getInstance().getMaxDuplicatedBlocksWhenArchiving();
// To summarize the above:
// - We must never archive anything greater than or equal to trimStartHeight
// - We should avoid archiving anything maximumDuplicatedBlocks higher than pruneStartHeight
return Math.min(trimStartHeight, pruneStartHeight + maximumDuplicatedBlocks);
}
else {
// We don't want to apply the maximum duplicated limit
return trimStartHeight;
}
} }
public static boolean isArchiverUpToDate(Repository repository, boolean useMaximumDuplicatedLimit) throws DataException { public static boolean isArchiverUpToDate(Repository repository) throws DataException {
final int maxArchiveHeight = BlockArchiveWriter.getMaxArchiveHeight(repository, useMaximumDuplicatedLimit); final int maxArchiveHeight = BlockArchiveWriter.getMaxArchiveHeight(repository);
final int actualArchiveHeight = repository.getBlockArchiveRepository().getBlockArchiveHeight(); final int actualArchiveHeight = repository.getBlockArchiveRepository().getBlockArchiveHeight();
final float progress = (float)actualArchiveHeight / (float) maxArchiveHeight; final float progress = (float)actualArchiveHeight / (float) maxArchiveHeight;
LOGGER.info(String.format("maxArchiveHeight: %d, actualArchiveHeight: %d, progress: %f", LOGGER.info(String.format("maxArchiveHeight: %d, actualArchiveHeight: %d, progress: %f",

View File

@ -41,7 +41,7 @@ public class HSQLDBDatabaseArchiving {
LOGGER.info("Building block archive - this process could take a while... (approx. 15 mins on high spec)"); LOGGER.info("Building block archive - this process could take a while... (approx. 15 mins on high spec)");
final int maximumArchiveHeight = BlockArchiveWriter.getMaxArchiveHeight(repository, false); final int maximumArchiveHeight = BlockArchiveWriter.getMaxArchiveHeight(repository);
int startHeight = 0; int startHeight = 0;
while (!Controller.isStopping()) { while (!Controller.isStopping()) {

View File

@ -52,7 +52,7 @@ public class HSQLDBDatabasePruning {
// Only proceed if we can see that the archiver has already finished // Only proceed if we can see that the archiver has already finished
// This way, if the archiver failed for any reason, we can prune once it has had // This way, if the archiver failed for any reason, we can prune once it has had
// some opportunities to try again // some opportunities to try again
boolean upToDate = BlockArchiveWriter.isArchiverUpToDate(repository, false); boolean upToDate = BlockArchiveWriter.isArchiverUpToDate(repository);
if (!upToDate) { if (!upToDate) {
return false; return false;
} }
@ -253,7 +253,7 @@ public class HSQLDBDatabasePruning {
// Only proceed if we can see that the archiver has already finished // Only proceed if we can see that the archiver has already finished
// This way, if the archiver failed for any reason, we can prune once it has had // This way, if the archiver failed for any reason, we can prune once it has had
// some opportunities to try again // some opportunities to try again
boolean upToDate = BlockArchiveWriter.isArchiverUpToDate(repository, false); boolean upToDate = BlockArchiveWriter.isArchiverUpToDate(repository);
if (!upToDate) { if (!upToDate) {
return false; return false;
} }

View File

@ -136,9 +136,6 @@ public class Settings {
private boolean archiveEnabled = true; private boolean archiveEnabled = true;
/** How often to attempt archiving (ms). */ /** How often to attempt archiving (ms). */
private long archiveInterval = 7171L; // milliseconds private long archiveInterval = 7171L; // milliseconds
/** The maximum number of blocks that can exist in both the
* database and the archive at the same time */
private int maxDuplicatedBlocksWhenArchiving = 100000;
// Peer-to-peer related // Peer-to-peer related
@ -599,8 +596,4 @@ public class Settings {
return this.archiveInterval; return this.archiveInterval;
} }
public int getMaxDuplicatedBlocksWhenArchiving() {
return this.maxDuplicatedBlocksWhenArchiving;
}
} }