Skip to content

Conversation

AminR443
Copy link
Contributor

@AminR443 AminR443 commented Sep 3, 2025

This implement a simple Iterator interface in Go (Next, Key, Value) using the introduced FFI functions, without batching.

Depends On: #1255

Copy link
Contributor

@alarso16 alarso16 left a comment

Choose a reason for hiding this comment

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

It looks good to me, I left some non-blocking comments and didn't look at the Rust code

@alarso16
Copy link
Contributor

alarso16 commented Sep 4, 2025

I do think there's some test cases missing. What if you're using IterLatest and a proposal is committed? What if you're using Iter on a proposal and it's committed? What happens if the database closed? These should be easy tests to right, and their behavior isn't necessarily obvious but should be well defined

Comment on lines +217 to +226
func (db *Database) LatestRevision() (*Revision, error) {
root, err := db.Root()
if err != nil {
return nil, err
}
if bytes.Equal(root, EmptyRoot) {
return nil, errRevisionNotFound
}
return db.Revision(root)
}
Copy link
Member

Choose a reason for hiding this comment

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

This is racy. If a commit occurs after line 218 and before line 225, you won't have the latest revision.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the user's responsibility to ensure that there isn't a commit occurring.

Comment on lines +1064 to +1068
i := 0
for ; it.Next(); i += 1 {
r.Equal(keys[i], it.Key())
r.Equal(vals[i], it.Value())
}
Copy link
Member

Choose a reason for hiding this comment

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

Why did we decide not to use go iterators and range here?

}

// Value returns the value of the current pair
func (it *Iterator) Value() []byte {
Copy link
Member

Choose a reason for hiding this comment

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

Is there ever a case where the caller will only be interested in the key or the value (not both)? If not, then it seems like having a method called KeyValue would be a lot more usable, which returns (key []byte, value []byte)

let out = self.iterator.as_mut()?.next();
if out.is_none() {
// iterator exhausted; drop it so the NodeStore can be released
self.iterator.take();
Copy link
Member

Choose a reason for hiding this comment

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

why take?

This should be:

Suggested change
self.iterator.take();
self.iterator = None;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants