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

Streaming iterator spike #342

Closed
wants to merge 17 commits into from
Closed

Conversation

rkuris
Copy link
Collaborator

@rkuris rkuris commented Nov 3, 2023

This is ready for feedback.

There are still some unfinished parts, all annotated with TODO. Notably:

  • You should be able to start at a key that doesn't exist
  • You should be able to start at the beginning of the trie
  • We can be more efficient on building and maintaining current_key

There are several TODOs here, but the code works for the two test cases
I created. Both of these avoid making extension nodes, which are going
away, and this code may need some tweaks to support values inside branch
nodes.
@rkuris rkuris marked this pull request as ready for review November 8, 2023 00:14
Copy link
Contributor

@richardpringle richardpringle left a comment

Choose a reason for hiding this comment

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

I didn't really dive super far into this, but I would love to see some more test to prove or refute my suspicions before this gets merged.

Branches having paths will also complicate things.

firewood/src/merkle.rs Outdated Show resolved Hide resolved
firewood/src/merkle.rs Outdated Show resolved Hide resolved
firewood/src/merkle.rs Outdated Show resolved Hide resolved
firewood/src/merkle.rs Outdated Show resolved Hide resolved
firewood/src/merkle.rs Outdated Show resolved Hide resolved
firewood/src/merkle.rs Outdated Show resolved Hide resolved
firewood/src/merkle.rs Outdated Show resolved Hide resolved
firewood/src/merkle.rs Outdated Show resolved Hide resolved
firewood/src/merkle.rs Outdated Show resolved Hide resolved
firewood/src/merkle.rs Outdated Show resolved Hide resolved
Per review comments
IteratorState is any of:
 - Start at the beginning of the trie
 - Start at a specific key value of the trie
 - Continue after a saved node and parents

See the inline comments for more details.

TODO:
 - Implement StartAtBegininng (and tests)
 - If a key is provided that doesn't exist, start iterating at the next
   one (if we really need this)
 - If an error is returned, we should next return None, then start from
   the beginning. This makes the resumption after an error a little
   cleaner. We'd need another IteratorState for this.
 - Remove extension nodes (depends on other diffs)
@rkuris rkuris requested a review from richardpringle November 9, 2023 18:21
This was an artifact from an earlier change. Reverted back to original.
Not sure how this got in there. Reverting it.
Seems like we can just reference self and it works!
Removed unnecessary clone
Added additional comments
Added TODO for a few things:
 - possible to return a reference to the value instead of a copy
 - should handle case of branch nodes with values while traversing

Adding a randomized key-value test after extension nodes are removed is
also recommended.
@rkuris rkuris self-assigned this Nov 11, 2023
Copy link
Contributor

@xinifinity xinifinity left a comment

Choose a reason for hiding this comment

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

Mostly about the TODOs which some of them would be straightforward to fix in this PR, I'm good with tracking all non fixed TODOs in a issue as well, since they seem essential to have.

.map(|node| (node, u8::MAX))
.map_err(|e| api::Error::InternalError(e.into()))?;

// TODO: If the branch has a value, then we shouldn't keep_going
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, would it be better to fix this issue in this PR instead of leaving a TODO? It seems a straightforward fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in #346

use node::tests::{extension, leaf};
use shale::{cached::DynamicMem, compact::CompactSpace, CachedStore};
use std::sync::Arc;
use test_case::test_case;
//use itertools::Itertools;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Why not remove this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in #346

key: Option<K>,
root: DiskAddress,
) -> Result<MerkleKeyValueStream<'_, S>, MerkleError> {
// TODO: if DiskAddress::is_null() ...
Copy link
Contributor

Choose a reason for hiding this comment

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

Will all this TODOs be tracked in a issue so that we won't forget about it? All of them seem a must do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was fixed in #346

@rkuris
Copy link
Collaborator Author

rkuris commented Nov 14, 2023

Abandoning this in favor of #346, which contains all these commits

@rkuris rkuris closed this Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants