Open
Description
At present the design of the Java RocksIterator is not very Java'esk. That is to say that as a Java developer you will typically hold the assumption that calling getKey()
or getValue()
on the iterator will be stable until you call next()
, prev()
, seek...
. This is not the case; see: #616 (comment)
I would suggest that the Java RocksIterator should be replaced by two different types of iterator:
- A direct iterator which uses
ByteBuffer
to access the underlying C++ memory. This would avoid the JNI copy that is done with the current RocksIterator on every call togetKey()
orgetValue()
. It would also be unstable like the current RocksIterator, however because of the use of ByteBuffer this would be expected by the Java developer. - A non-direct iterator which uses
byte[]
just as the current RocksIterator does, however the behaviour ofgetKey()
andgetValue()
would be stable untilnext()
orprev()
is called; It would also be stable for example when remove is called on a non-direct iterator of a WriteBatch. This could for example be achieved by the first call togetKey
internally caching the value, the value would be disposed on the call tonext
orclose
, the same principle would apply togetValue
.
Comments?