-
Notifications
You must be signed in to change notification settings - Fork 20
feat(ffi-iterator): Implementation of Iterator in Go (2/4) #1256
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
base: amin/ffi-iterator-p1
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
I do think there's some test cases missing. What if you're using |
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) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
i := 0 | ||
for ; it.Next(); i += 1 { | ||
r.Equal(keys[i], it.Key()) | ||
r.Equal(vals[i], it.Value()) | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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:
self.iterator.take(); | |
self.iterator = None; |
This implement a simple Iterator interface in Go (
Next
,Key
,Value
) using the introduced FFI functions, without batching.Depends On: #1255