Closed slav closed 7 years ago
That is a strange error. The function causing that panic is C.GoBytes()
, which seems very strange.
The error is probably because lmdb.Set
will not actually read values from the database, as you said. So whatever value lmdb-go is trying to extract wouldn't be valid anyway. I will add a test case for this to reproduce.
I will probably end up having the Cursor.Get
method check the cursor op so it can short circuit and return nil slices when op is lmdb.Set
.
AFAIK the op in question is the only one which does not return data. Are you aware of any other ops like this @slav?
http://www.lmdb.tech/doc/group__mdb.html#ga1206b2af8b95e7f6b0ef6b28708c9127
Thanks for the report.
Interestingly, on my primary Linux machine lmdb.Set
and lmdb.SetKey
seem to operate the same (they return the same values).
I notice that you are running your program in a Windows environment. Perhaps you could run the tests for me on your computer and confirm that the test case I added does in fact reproduce the panic for you? It has been some time since I compiled lmdb-go on Windows myself, so I will have to try to get that environment running again.
Branch: bmatsuo/cursor-op-set-testing (commit c9757f4)
All the tests in branch "bmatsuo/cursor-op-set-testing" pass on windows.
I'm also unaware which ops init key/data and which don't. Documentation is only specific about MDB_SET_KEY to return key + data.
OK. Thanks for checking that, @slav. I understand what is happening now. This is an issue with the bytes.Buffer
type that I have run into before in #56. I can reproduce the error now and I will work on a fix.
I have pushed a commit to that branch (bmatsuo/cursor-op-set-testing). I have a working fix that I will upload to another branch and issue a pull request to respect the process. Thanks again for your help, @slav. It is very much appreciated.
I have db with dup values (not sure if relevant). When I'm trying to do
k, v, e = cursor.Get(buf.Bytes(), nil, lmdb.Set)
I get exception (see below). Withk, v, e = cursor.Get(buf.Bytes(), nil, lmdb.SetKey)
it works. Just Set positions cursor at the key but doesn't read value. But cursor.Get still attempts to read it which leads to the exception.