Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Increase rescan performance of old milestones after IRI restart #1204

Conversation

hmoog
Copy link

@hmoog hmoog commented Nov 29, 2018

Description

IRI always scans all potential milestone candidates after a restart. Depending on the database size this can take a really long time (hours in the worst case). If we have a local snapshot we can always immediately discard the transactions prior to the snapshot point because the node doesn't need them anymore. This increases the restart performance of IRI massively (few seconds).

Type of change

  • Enhancement (a non-breaking change which adds functionality)

Checklist:

Please delete items that are not relevant.

  • My code follows the style guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@iotaledger iotaledger deleted a comment Dec 1, 2018
@iotaledger iotaledger deleted a comment Dec 1, 2018
Copy link
Contributor

@alon-e alon-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think validateMilestone should be stateless.
it's worse enough that the depth/index is capped by milestoneIndex >= 0x200000 which is only relevant to mainnet but not to other networks w/ theoretically more leaves (+ #1180)

so adding IRRELAVENT inside the function makes it, even more, dependant on state - think of test where the hardcoded testing milestone is below the starting milestone.

-> my proposal is to pull this out of the validate milestone and into a function that checks if the index is valid or needed before calling the validation.

@hmoog
Copy link
Author

hmoog commented Dec 6, 2018

i changed the check to be part of the milestone tracker instead

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just another little change

@@ -160,10 +160,9 @@ public void resetCorruptedMilestone(int index) throws MilestoneException {
}

@Override
public MilestoneValidity validateMilestone(TransactionViewModel transactionViewModel, SpongeFactory.Mode mode,
int securityLevel) throws MilestoneException {
public MilestoneValidity validateMilestone(TransactionViewModel transactionViewModel, int milestoneIndex,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice addition of parameter

@@ -209,8 +208,13 @@ public MilestoneValidity analyzeMilestoneCandidate(TransactionViewModel transact
transaction.getCurrentIndex() == 0) {

int milestoneIndex = milestoneService.getMilestoneIndex(transaction);
if (milestoneIndex <= snapshotProvider.getInitialSnapshot().getIndex()) {
return INVALID;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Alon's beef was that the validateMilestone depended on the milestone Index. On which he was correct, we don't want other potential callers of this method to be blocked by the index.

He didn't say anything about your IRRELEVANT enum. I think that returning an INVALID on a vaild milestone will be very misleading to anyone in the future (it is at least misleading for me). I would bring back this enum value.

Copy link
Contributor

@GalRogozinski GalRogozinski Dec 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I have a better idea... Instead of adding another enum to validity (IRRELEVANT) (which doesn't make much sense), analyzeMilestoneCandidate can return a boolean: true if successfully analyzed, false otherwise.

If the milestoneIndex is below the snapshot then return true and add a little comment: "has already been analyzed if it is below the snapshot" (feel free to change the wording).

I think this makes the most sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree w/ @GalRogozinski that returning INVALID may not be the best answer. other than that lgtm.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed it accordingly

@iotaledger iotaledger deleted a comment Dec 7, 2018
@@ -203,14 +198,19 @@ public MilestoneValidity analyzeMilestoneCandidate(Hash transactionHash) throws
* {@link MilestoneSolidifier} that takes care of requesting the missing parts of the milestone bundle.<br />
*/
@Override
public MilestoneValidity analyzeMilestoneCandidate(TransactionViewModel transaction) throws MilestoneException {
public boolean processMilestoneCandidate(TransactionViewModel transaction) throws MilestoneException {
Copy link
Contributor

@GalRogozinski GalRogozinski Dec 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 on the name change

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@GalRogozinski GalRogozinski merged commit 08444bc into iotaledger:dev-localsnapshots Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants