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

Memory saves and deletes. Cache dependant commits. #4

Closed
wants to merge 6 commits into from

Conversation

Sriep
Copy link

@Sriep Sriep commented Jun 7, 2019

Add modified saveVersion and deleteVersions that only change the in-memory tree and don't commit changes to the database.
Add a maxCahce to nodedb, so that data is only written to the disk if the max Cache size is exceeded.

@Sriep Sriep changed the base branch from master to loomchain June 7, 2019 10:44
@Sriep Sriep mentioned this pull request Jun 13, 2019
4 tasks
@@ -342,13 +400,25 @@ func (ndb *nodeDB) uncacheNode(hash []byte) {
}
}

func (ndb *nodeDB) MaxChacheSizeExceeded() bool {
Copy link

Choose a reason for hiding this comment

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

cacheSize

@jaekwon
Copy link

jaekwon commented Jun 22, 2019

Thank you for the contribution. It's been a while since I looked at this code and the orphan system. I wish there were more of a design document that explained the previous orphan system, the changes, and the new code with ideally diagrams and prose to make this easy to understand for future maintainers about versioning and orphaning.

// Saves orphaned nodes to disk under a special prefix.
// version: the new version being saved.
// orphans: the orphan nodes created since version-1
func (ndb *nodeDB) SaveOrphans(version int64, orphans map[string]int64) {
ndb.mtx.Lock()
defer ndb.mtx.Unlock()

toVersion := ndb.getPreviousVersion(version)
// When saving a new version, the previous version will always be one less than the new version
Copy link

Choose a reason for hiding this comment

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

What happens when you save a version (H), delete it (H, so now the latest saved state is H-1), but then you save again? Is it H+1 or H?

ndb.deleteOrphansWithPredecessor(version, predecessor, nil)
}

func (ndb *nodeDB) deleteOrphansWithPredecessor(version, predecessor int64, unsavedOrphans *map[string]int64) {
Copy link

Choose a reason for hiding this comment

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

what is the purpose of this function w/ the unsavedOrphans arg? It never gets called?

@Sriep
Copy link
Author

Sriep commented Jun 28, 2019

Still updating this idea.
Databases can get bloated with large numbers of orphans, and disk database size can become the critical issue. At this point, orphans can move from being the solution to becomeing the problem.

This suggests a new paradigm where you don't use orphan except possibly in the most recent blocks. Instead, after deleting old blocks, you can scan the database removing nodes that are not part of a tree anymore.

@Sriep Sriep closed this Jul 5, 2019
@enlight enlight deleted the new-store branch May 18, 2021 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants