-
Notifications
You must be signed in to change notification settings - Fork 76
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
Consider adding lower-level iterator controls available in LevelDB #17
Comments
also, we need to support closing iterators, so that we don't have to wait for garbage collection to kick in to free the leveldb snapshot backing the iterator |
The ability to close iterators explicitly is actually an issue on itself. I've just opened #19 for that. |
thx |
I have a few remarks on the initial report.
That is not correct.
This depends on how the iterator is used:
It seems to me the same can be achieved using
Again, this depends on how the iterator is used (see above).
Indeed, Python has an (imho very sophisticated) iteration interface. I've spent quite some time transforming the LevelDB iterator interface to conform to Python's conventions. The result is that the underlying code is a state machine instead of a straight-forward API bridge. Mixing this already quite hairy code with additional Python-level access to the underlying LevelDB concepts is, at best, a daunting task. I'm especially worried about all the corner cases combining things like prefixed databases, the |
Thanks for the response. One correction in my original report: it's not seek() that doesn't move the iterator, it's seek_to_start() and seek_to_stop() that do not. These calls defer actual movement of the iterator to real_next() and real_prev(). The fact that seek() operates as expected (and moves the iterator position in LevelDB) makes the case for exposing Valid() a little stronger because, as you noted, next() and prev() can return entirely different things, depending on the database contents. The ambiguity can lead to confusion when implementing seek() (i.e. should i use next or prev here?). I think that seek() really doesn't fit the Python iterator idiom in general - there isn't such a concept in the iterator protocol. The Python model would accommodate a seek by range-based iterating, which is already implemented. Manually stepping with next() and prev() is totally fine. We've implemented it precisely that way, wrapping it in a try/except block to emulate an exception-free step. I think the core concern here is that Plyvel is an excellent Python interface for LevelDB's C library - but our code makes some assumptions about seek(), seek_to_start(), and seek_to_stop() that aren't respected in Plyvel and are incompatible with the Python concept of iteration. Given this, if we can't find a good fit for these features here, I'm totally fine maintaining a fork or branch of Plyvel that implements these lower-level features that never sees use outside of our (rather unique) code base. |
the only differences i really am aware of between python iterators and leveldb iterators are that leveldb-next advances the iterator once, whereas python-next saves the current key and value, advances the iterator, and then returns the saved key and value. prev is similar but in the opposite order. basically the difference between i++ and ++i, right? i feel like it should be fine to let both semantics coexist defaulting to python semantics, provided that there's calls to the lower level leveldb semantics-style calls? maybe i'm just talking out of my rear end again, as i'm not as familiar with plyvel as either of you two. i'm also aware wouter had some questions about the leveldb-py interface (it seemed weird to him), but i think it's possible for both semantics to coexist. for someone looking for a fast leveldb library in python, it's possible they'll want to use leveldb semantics, in the case they're transliterating code from a different language or something. |
Not exactly. However, both Example:
Well, not exactly 'weird', but mostly not reallly Pythonic. With Plyvel, all common iteration patterns can be expressed using a common |
Fwiw, I would not mind adding a "low level iterator" API to Plyvel, but I'd like to keep it separate from the Pythonic iterator API with all its quirks and corner cases, as outlined before. What do you think of a |
that would be fantastic. |
What is your opinion on .key() and .value() methods versus return values from .next() and .prev() (and maybe others)? And should there be a .valid() method, or should the code handle this inside the other methods?
(Sent from my tablet. Please ignore the typos.)
|
whoops, i suck at email once again. i'm on freenode as 'jtolds' btw the benefit to having separate key and value methods is that you don't have to call the underlying c method if you don't need to, reducing memory copies. it also helps makes code more general. you can have some chunk of code decide where to seek the iterator to, and another chunk of code to handle the iterator post seeking. i also think a valid method is useful, cause try/except blocks around every seek/step seem like worse code to me, but i guess that's more subjective |
Added a .raw_iterator() method to DB and Snapshot instances. The RawIterator instance returned by .raw_iterator() mimics the C++ iterator API provided by LevelDB. The API is almost a direct mapping, except for some added error handling, which is required to avoid segfaults or other aborts from within LevelDB. See issue #17.
I've just implemented a RawIterator (published in the @tommetge, @jtolds: please review these changes. The tests provide example API usage; the implementation itself shows the exposed API. |
Relevant parts of the commit message:
|
looks good to me |
Okay, so this just needs docs. I'll look into that later.
(Sent from my phone. Please ignore the typos.) JT [email protected] schreef:
|
Just released Plyvel 0.7 with this new API. https://plyvel.readthedocs.org/en/latest/news.html#plyvel-0-7 |
awesome, thx wouter |
Specifically:
This is a completely different model of iteration from standard python. As mentioned here:
tommetge@25364fc
... we have an existing code base whose logic depends on the outlined features. It may not be appropriate for the general Plyvel consumer.
Let me know what you think.
The text was updated successfully, but these errors were encountered: