]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commit
Ensure the destruction order of PosixEnv and ThreadLocalPtr
authorYueh-Hsuan Chiang <yhchiang@fb.com>
Fri, 11 Dec 2015 08:21:58 +0000 (00:21 -0800)
committerYueh-Hsuan Chiang <yhchiang@fb.com>
Fri, 11 Dec 2015 08:21:58 +0000 (00:21 -0800)
commit00d6edf6a0080ac3961e56213ae962ec1d570daa
tree5323db137f688bca2881fab86d46f5dd6b02e7d1
parent64fa43843bc7bdffb4d125d8d95685e33dbdf1ff
Ensure the destruction order of PosixEnv and ThreadLocalPtr

Summary:
By default, RocksDB initializes the singletons of ThreadLocalPtr first, then initializes PosixEnv
via static initializer.  Destructor terminates objects in reverse order, so terminating PosixEnv
(calling pthread_mutex_lock), then ThreadLocal (calling pthread_mutex_destroy).

However, in certain case, application might initialize PosixEnv first, then ThreadLocalPtr.
This will cause core dump at the end of the program (eg. https://github.com/facebook/mysql-5.6/issues/122)

This patch fix this issue by ensuring the destruction order by moving the global static singletons
to function static singletons.  Since function static singletons are initialized when the function is first
called, this property allows us invoke to enforce the construction of the static PosixEnv and the
singletons of ThreadLocalPtr by calling the function where the ThreadLocalPtr singletons belongs
right before we initialize the static PosixEnv.

Test Plan: Verified in the MyRocks.

Reviewers: yoshinorim, IslamAbdelRahman, rven, kradhakrishnan, anthony, sdong, MarkCallaghan

Reviewed By: anthony

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D51789
util/env_posix.cc
util/thread_local.cc
util/thread_local.h