Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make GetVersioned() available after doing LazyLoadVersion #358

Closed
wants to merge 9 commits into from
Closed

fix: Make GetVersioned() available after doing LazyLoadVersion #358

wants to merge 9 commits into from

Conversation

egonspace
Copy link
Contributor

We can use LazyLoadVersion by #148.
But if we start app with LazyLoadVersion we cannot query app state by specific height because MutableTree.GetVersioned returns nil for other previous version after doing LazyLoadVersion.

Our nodes are facing a slow booting up problem because of the large app data, and I want to hear your opinion about whether we should modify the code like this.

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

I'm not sure if the !tree.allLoade condition in GetVersion* functions is correct. Could you explain?

mutable_tree.go Outdated
@@ -438,7 +447,7 @@ func (tree *MutableTree) Rollback() {
func (tree *MutableTree) GetVersioned(key []byte, version int64) (
index int64, value []byte,
) {
if tree.versions[version] {
if !tree.allLoaded || tree.versions[version] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be:

if tree.allLoaded && tree.versions[version]

In the function below as well.

Please confirm.

Copy link
Contributor Author

@egonspace egonspace Jan 31, 2021

Choose a reason for hiding this comment

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

My intention is to fix this to be able to get the version by access of db even when we do LazyLoadVersion.
If we have done LazyLoadVersion then tree.allLoaded would be false. There is a problem that existing code cannot get a version by GetVersioned even though the version is in db when LazyLoadVersion is done .

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, we want to try to load if we didn't use LoadVersion before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If a node started with LazyLoadVersion, what should this function do? Should it be able to give us only the last version that it loaded? Or should it access the DB and give any version to us if it's there?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Exactly as you wrote - we should try to load it from DB. Maybe we could even do a small optimization to avoid loading if we already tried it:

exists, checked := tree.versions[version]
if (!tree.allLoaded && !checked) || exists {
    ...

This way, we avoid entering the load, if we already tried to do it and the he version didn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. I applied the checking to VersionExists and made other functions use it.

return existingHash, version, nil
// If the version already exists, return an error as we're attempting to overwrite.
// However, the same hash means idempotent (i.e. no-op).
if existingHash != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

len(existingHash) == 0 is a right check we should us here. It checks both the nil value and an empty slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. Only nil should be checked here. When we do LazyLoadVersion, there is no versions information, so we need to access db to see if there is the version or not. I put this condition in order not to run the code below when there is no version in db. If it is an empty slice, we should process the logic below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, makes sense. could you update the comment in the code to add information about empty slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment about empty slice is already below, but I'll add a comment about the condition existingHash != nil

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

Looks good. Please update a comment in a code before merging.

@robert-zaremba robert-zaremba self-assigned this Feb 1, 2021
@egonspace
Copy link
Contributor Author

@robert-zaremba I modified the checking code as you advised. I'd appreciate it if you review it again.

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks @egonspace

@robert-zaremba robert-zaremba added the S:automerge Automatic merge and/or update Pull requests label Apr 12, 2021
@robert-zaremba
Copy link
Collaborator

Hi @egonspace - are you planning to merge this PR?

@egonspace
Copy link
Contributor Author

egonspace commented Apr 26, 2021

I accidentally removed the branch and recreated the PR. I'd appreciate it if you could review it again even if it's too much trouble.

@egonspace egonspace closed this Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S:automerge Automatic merge and/or update Pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants