swh:1:snp:5115096b921df712aeb2a08114fede57fb3331fb
Revision 0493719649c4ea4dbf1f859763809beedee0fdb9 authored by Mike Kolupaev on 16 February 2018, 15:58:18 UTC, committed by Sagar Vemuri on 16 February 2018, 19:34:46 UTC
Summary:
Deadlock: a memtable flush holds DB::mutex_ and calls ThreadLocalPtr::Scrape(), which locks ThreadLocalPtr mutex; meanwhile, a thread exit handler locks ThreadLocalPtr mutex and calls SuperVersionUnrefHandle, which tries to lock DB::mutex_.

This deadlock is hit all the time on our workload. It blocks our release.

In general, the problem is that ThreadLocalPtr takes an arbitrary callback and calls it while holding a lock on a global mutex. The same global mutex is (at least in some cases) locked by almost all ThreadLocalPtr methods, on any instance of ThreadLocalPtr. So, there'll be a deadlock if the callback tries to do anything to any instance of ThreadLocalPtr, or waits for another thread to do so.

So, probably the only safe way to use ThreadLocalPtr callbacks is to do only do simple and lock-free things in them.

This PR fixes the deadlock by making sure that local_sv_ never holds the last reference to a SuperVersion, and therefore SuperVersionUnrefHandle never has to do any nontrivial cleanup.

I also searched for other uses of ThreadLocalPtr to see if they may have similar bugs. There's only one other use, in transaction_lock_mgr.cc, and it looks fine.
Closes https://github.com/facebook/rocksdb/pull/3510

Reviewed By: sagar0

Differential Revision: D7005346

Pulled By: al13n321

fbshipit-source-id: 37575591b84f07a891d6659e87e784660fde815f
1 parent 7ad7940
History
Tip revision: 19076c95aa2bcee55c26fcf0960cc844ad86ee9c authored by Levi Tamasi on 21 January 2021, 22:18:25 UTC
Update HISTORY.md for PR 7888 (#7890)
Tip revision: 19076c9
File Mode Size
buckifier
build_tools
cache
cmake
coverage
db
docs
env
examples
hdfs
include
java
memtable
monitoring
options
port
table
third-party
tools
util
utilities
.clang-format -rw-r--r-- 138 bytes
.gitignore -rw-r--r-- 705 bytes
.travis.yml -rw-r--r-- 3.0 KB
AUTHORS -rw-r--r-- 322 bytes
CMakeLists.txt -rw-r--r-- 32.5 KB
CODE_OF_CONDUCT.md -rw-r--r-- 249 bytes
CONTRIBUTING.md -rw-r--r-- 706 bytes
COPYING -rw-r--r-- 17.7 KB
DEFAULT_OPTIONS_HISTORY.md -rw-r--r-- 1.5 KB
DUMP_FORMAT.md -rw-r--r-- 763 bytes
HISTORY.md -rw-r--r-- 53.1 KB
INSTALL.md -rw-r--r-- 6.8 KB
LANGUAGE-BINDINGS.md -rw-r--r-- 855 bytes
LICENSE.Apache -rw-r--r-- 11.1 KB
LICENSE.leveldb -rw-r--r-- 1.5 KB
Makefile -rw-r--r-- 62.6 KB
README.md -rw-r--r-- 1.4 KB
ROCKSDB_LITE.md -rw-r--r-- 1.0 KB
TARGETS -rw-r--r-- 26.0 KB
USERS.md -rw-r--r-- 5.3 KB
Vagrantfile -rw-r--r-- 877 bytes
WINDOWS_PORT.md -rw-r--r-- 12.5 KB
appveyor.yml -rw-r--r-- 428 bytes
issue_template.md -rw-r--r-- 243 bytes
src.mk -rw-r--r-- 26.7 KB
thirdparty.inc -rw-r--r-- 7.3 KB

README.md

back to top