-
Notifications
You must be signed in to change notification settings - Fork 7
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
lmdb: methods to support custom comparison Txn.SetCmp(), Txn.SetCmpDup() #27
base: master
Are you sure you want to change the base?
Conversation
The methods bind the mdb_set_compare and mdb_set_dupsort functions respectively. The methods are very hard to call. They require C function pointers as arguments and hooking Go functions from custom C functions is tricky, which lots of overhead/boilerplate.
Optimization in the compiler may be defeating the simulation to some degree.
Thank you for submitting this. As far as I can see, this was never submitted as a PR by bmatsuo before and only lived in a branch. Are you aware of any issues and missing functionality with this code, or other reasons that this was never included? Aside from the ugliness and pain of having to provide an unsafe C function pointer, of course. Some thoughts:
On one hand I am not sure if we can and want to maintain such a fragile unsafe interface in this library, on the other hand I can see how this could help when interfacing with existing LMDBs that you have no control over and use this feature. This feature could break in a future Go release, as CGo is not part of the Go 1.x compatibility promise, and this is kind of stretching the scope of its use, so perhaps a warning about this needs to be added to the doc comments, and perhaps add |
Honestly, I don't really understand much of what is happening here. All I can say is that I tried it because I was interfacing with an external LMDB that had been created using a custom comparator and it worked for me and I haven't had a single issue. Also I've only used the But I think it's very reasonable to not have this merged. I would say you could perhaps just keep this PR here, either closed or open, or I could make it a draft, and then in the rare occasion that someone wants this they could find this and use the commits here in a local patch like I have been doing. |
After some thought I think it would be useful to have it, precisely for such circumstances. I would say that it can be merged after the following changes:
If you do not feel like doing this, that's OK. Maybe somebody else will in the future. |
This is an old unmerged PR from @bmatsuo that I have been using in production for many months now.
It allows one to write custom comparators for DBIs in C, like this:
Then use these with
txn.SetCmp()
: