-
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
Python thread error when using a custom comparator #35
Comments
Thanks for the report. I'm trying it out, but I see something different happening... Update: this particular comment should be ignored; see #36. A slightly modified version of your code (only changed so that it actually runs) run on Python 3.3, LevelDB 1.17, and latest Plyvel (git master), quickly allocates lots of memory, and crashes like this:
GDB shows this traceback:
|
With Python 2.7 I see the same as in your original report:
GDB: (gdb) run issue35.py db-issue-35
Starting program: /home/uws/Projects/Plyvel/plyvel/.tox/py27/bin/python issue35.py db-issue-35
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Inserted upto 50000 ...
Inserted upto 100000 ...
[New Thread 0x7ffff5dce700 (LWP 21375)]
Fatal Python error: This thread state must be current when releasing
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff5dce700 (LWP 21375)]
sem_post () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S:33
33 ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S: No such file or directory.
(gdb) bt
#0 sem_post () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S:33
#1 0x000000000052d299 in PyThread_release_lock ()
#2 0x00007ffff6b205d6 in PlyvelCallbackComparator::Compare (this=0x9f3e80, a=..., b=...) at plyvel/comparator.cpp:85
#3 0x00007ffff68cd5ea in leveldb::SomeFileOverlapsRange(leveldb::InternalKeyComparator const&, bool, std::vector<leveldb::FileMetaData*, std::allocator<leveldb::FileMetaData*> > const&, leveldb::Slice const*, leveldb::Slice const*) ()
from /usr/lib/x86_64-linux-gnu/libleveldb.so.1
#4 0x00007ffff68cdc76 in leveldb::Version::PickLevelForMemTableOutput(leveldb::Slice const&, leveldb::Slice const&)
() from /usr/lib/x86_64-linux-gnu/libleveldb.so.1
#5 0x00007ffff68bbbea in leveldb::DBImpl::WriteLevel0Table(leveldb::MemTable*, leveldb::VersionEdit*, leveldb::Version*) () from /usr/lib/x86_64-linux-gnu/libleveldb.so.1
#6 0x00007ffff68bcdea in leveldb::DBImpl::CompactMemTable() () from /usr/lib/x86_64-linux-gnu/libleveldb.so.1
#7 0x00007ffff68bdcd5 in leveldb::DBImpl::BackgroundCompaction() () from /usr/lib/x86_64-linux-gnu/libleveldb.so.1
#8 0x00007ffff68be932 in leveldb::DBImpl::BackgroundCall() () from /usr/lib/x86_64-linux-gnu/libleveldb.so.1
#9 0x00007ffff68e9f5b in ?? () from /usr/lib/x86_64-linux-gnu/libleveldb.so.1
#10 0x00007ffff7bc70a4 in start_thread (arg=0x7ffff5dce700) at pthread_create.c:309
#11 0x00007ffff6fdc04d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
(gdb) quit |
I found the source of the problem. I'll prepare a fix shortly. |
@wbolster that's cool, thanks for you quick response. If you have the time, can you explain a little bit the bug? |
The problem is that the custom comparator is called from a background thread created internally inside LevelDB. Even if the application itself doesn't use threading, the Python threading machinery still needs to be initialized. Plyvel didn't do this. See the commit message (and diff) for 635777d for details. Oh, and since the unit tests use the |
@darkjh btw, a comparator implemented in Python is really slow compared to the built-in comparator in LevelDB. Are you sure you can't pack your data in such a way that the default LevelDB behaviour matches your needs? In the case of integer keys, something like |
Fwiw, I just released Plyvel 0.9, which includes this fix. See https://plyvel.readthedocs.org/en/latest/news.html for the changelog. |
Thanks for the fix. |
For integers that have a known maximum value, something like ">Q" for a struct works fine. For strings it also works fine if you either have it as the last component (otherwise pad to fixed length). |
I've just encounter this problem when inserting a stream of data using a custom comparator. Code is something like below:
I got this after 100k elements are inserted:
If I use the default comparator, everything goes well.
I have no idea the implementation but it seems to me that when LevelDB begins to compact files, the error occurs.
I'm using
plyvel
0.8,LevelDB
1.15.0 andpython
2.7.8.The text was updated successfully, but these errors were encountered: