Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cc0ba3d30b | ||
|
d95cbf2e0f | ||
|
7056f18eb5 | ||
|
e81d4dd192 | ||
|
aeca831c06 | ||
|
b506c514c5 | ||
|
a76bad8d14 | ||
|
9cda7cb77b | ||
|
0d0d9bd3dc |
@ -2,16 +2,11 @@
|
||||
|
||||
### 3.9.0 (12/8/2014)
|
||||
|
||||
### New Features
|
||||
* Add rocksdb::GetThreadList(), which in the future will return the current status of all
|
||||
rocksdb-related threads. We will have more code instruments in the following RocksDB
|
||||
releases.
|
||||
|
||||
### Public API changes
|
||||
* New API to create a checkpoint added. Given a directory name, creates a new
|
||||
database which is an image of the existing database.
|
||||
*New API LinkFile added to Env. If you implement your own Env class, an
|
||||
implementation of the API LinkFile will have to be provided.
|
||||
* New API LinkFile added to Env. If you implement your own Env class, an
|
||||
implementation of the API LinkFile will have to be provided.
|
||||
* MemTableRep takes MemTableAllocator instead of Arena
|
||||
|
||||
### Improvements
|
||||
|
4
Makefile
4
Makefile
@ -83,7 +83,6 @@ install:
|
||||
@[ ! -e $(SHARED) ] || install -C -m 644 $(SHARED) $(INSTALL_PATH)/lib
|
||||
#-------------------------------------------------
|
||||
|
||||
WARNING_FLAGS = -Wall -Werror -Wsign-compare -Wshadow
|
||||
CFLAGS += $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
|
||||
CXXFLAGS += $(WARNING_FLAGS) -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT) -Woverloaded-virtual -Wnon-virtual-dtor
|
||||
|
||||
@ -164,8 +163,7 @@ TESTS = \
|
||||
flush_job_test \
|
||||
wal_manager_test \
|
||||
listener_test \
|
||||
compaction_job_test \
|
||||
thread_list_test
|
||||
compaction_job_test
|
||||
|
||||
SUBSET := $(shell echo $(TESTS) |sed s/^.*$(ROCKSDBTESTS_START)/$(ROCKSDBTESTS_START)/)
|
||||
|
||||
|
19
build_tools/dependencies.sh
Normal file
19
build_tools/dependencies.sh
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||||
GCC_BASE=/mnt/gvfs/third-party2/gcc/7331085db891a2ef4a88a48a751d834e8d68f4cb/7.x/centos7-native/b2ef2b6
|
||||
CLANG_BASE=/mnt/gvfs/third-party2/llvm-fb/963d9aeda70cc4779885b1277484fe7544a04e3e/9.0.0/platform007/9e92d53/
|
||||
LIBGCC_BASE=/mnt/gvfs/third-party2/libgcc/6ace84e956873d53638c738b6f65f3f469cca74c/7.x/platform007/5620abc
|
||||
GLIBC_BASE=/mnt/gvfs/third-party2/glibc/192b0f42d63dcf6210d6ceae387b49af049e6e0c/2.26/platform007/f259413
|
||||
SNAPPY_BASE=/mnt/gvfs/third-party2/snappy/7f9bdaada18f59bc27ec2b0871eb8a6144343aef/1.1.3/platform007/ca4da3d
|
||||
ZLIB_BASE=/mnt/gvfs/third-party2/zlib/2d9f0b9a4274cc21f61272a9e89bdb859bce8f1f/1.2.8/platform007/ca4da3d
|
||||
BZIP2_BASE=/mnt/gvfs/third-party2/bzip2/dc49a21c5fceec6456a7a28a94dcd16690af1337/1.0.6/platform007/ca4da3d
|
||||
LZ4_BASE=/mnt/gvfs/third-party2/lz4/0f607f8fc442ea7d6b876931b1898bb573d5e5da/1.9.1/platform007/ca4da3d
|
||||
ZSTD_BASE=/mnt/gvfs/third-party2/zstd/ca22bc441a4eb709e9e0b1f9fec9750fed7b31c5/1.4.x/platform007/15a3614
|
||||
GFLAGS_BASE=/mnt/gvfs/third-party2/gflags/0b9929d2588991c65a57168bf88aff2db87c5d48/2.2.0/platform007/ca4da3d
|
||||
JEMALLOC_BASE=/mnt/gvfs/third-party2/jemalloc/c26f08f47ac35fc31da2633b7da92d6b863246eb/master/platform007/c26c002
|
||||
NUMA_BASE=/mnt/gvfs/third-party2/numa/3f3fb57a5ccc5fd21c66416c0b83e0aa76a05376/2.0.11/platform007/ca4da3d
|
||||
LIBUNWIND_BASE=/mnt/gvfs/third-party2/libunwind/40c73d874898b386a71847f1b99115d93822d11f/1.4/platform007/6f3e0a9
|
||||
TBB_BASE=/mnt/gvfs/third-party2/tbb/4ce8e8dba77cdbd81b75d6f0c32fd7a1b76a11ec/2018_U5/platform007/ca4da3d
|
||||
KERNEL_HEADERS_BASE=/mnt/gvfs/third-party2/kernel-headers/fb251ecd2f5ae16f8671f7014c246e52a748fe0b/fb/platform007/da39a3e
|
||||
BINUTILS_BASE=/mnt/gvfs/third-party2/binutils/ab9f09bba370e7066cafd4eb59752db93f2e8312/2.29.1/platform007/15a3614
|
||||
VALGRIND_BASE=/mnt/gvfs/third-party2/valgrind/d42d152a15636529b0861ec493927200ebebca8e/3.15.0/platform007/ca4da3d
|
||||
LUA_BASE=/mnt/gvfs/third-party2/lua/f0cd714433206d5139df61659eb7b28b1dea6683/5.3.4/platform007/5007832
|
@ -1,105 +1,148 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Set environment variables so that we can compile rocksdb using
|
||||
# fbcode settings. It uses the latest g++ compiler and also
|
||||
# fbcode settings. It uses the latest g++ and clang compilers and also
|
||||
# uses jemalloc
|
||||
# Environment variables that change the behavior of this script:
|
||||
# PIC_BUILD -- if true, it will only take pic versions of libraries from fbcode. libraries that don't have pic variant will not be included
|
||||
|
||||
# location of libgcc
|
||||
LIBGCC_BASE="/mnt/gvfs/third-party2/libgcc/7712e757d7355cb51292454ee0b7b46a467fdfed/4.8.1/gcc-4.8.1-glibc-2.17/8aac7fc"
|
||||
LIBGCC_INCLUDE="$LIBGCC_BASE/include"
|
||||
LIBGCC_LIBS=" -L $LIBGCC_BASE/libs"
|
||||
|
||||
# location of glibc
|
||||
GLIBC_REV=6e40560b4e0b6d690fd1cf8c7a43ad7452b04cfa
|
||||
GLIBC_INCLUDE="/mnt/gvfs/third-party2/glibc/$GLIBC_REV/2.17/gcc-4.8.1-glibc-2.17/99df8fc/include"
|
||||
GLIBC_LIBS=" -L /mnt/gvfs/third-party2/glibc/$GLIBC_REV/2.17/gcc-4.8.1-glibc-2.17/99df8fc/lib"
|
||||
BASEDIR=`dirname $BASH_SOURCE`
|
||||
source "$BASEDIR/dependencies.sh"
|
||||
|
||||
# location of snappy headers and libraries
|
||||
SNAPPY_INCLUDE=" -I /mnt/gvfs/third-party2/snappy/aef17f6c0b44b4fe408bd06f67c93701ab0a6ceb/1.0.3/gcc-4.8.1-glibc-2.17/43d84e2/include"
|
||||
SNAPPY_LIBS=" /mnt/gvfs/third-party2/snappy/aef17f6c0b44b4fe408bd06f67c93701ab0a6ceb/1.0.3/gcc-4.8.1-glibc-2.17/43d84e2/lib/libsnappy.a"
|
||||
CFLAGS=""
|
||||
|
||||
# location of zlib headers and libraries
|
||||
ZLIB_INCLUDE=" -I /mnt/gvfs/third-party2/zlib/25c6216928b4d77b59ddeca0990ff6fe9ac16b81/1.2.5/gcc-4.8.1-glibc-2.17/c3f970a/include"
|
||||
ZLIB_LIBS=" /mnt/gvfs/third-party2/zlib/25c6216928b4d77b59ddeca0990ff6fe9ac16b81/1.2.5/gcc-4.8.1-glibc-2.17/c3f970a/lib/libz.a"
|
||||
# libgcc
|
||||
LIBGCC_INCLUDE="$LIBGCC_BASE/include/c++/7.3.0"
|
||||
LIBGCC_LIBS=" -L $LIBGCC_BASE/lib"
|
||||
|
||||
# location of bzip headers and libraries
|
||||
BZIP_INCLUDE=" -I /mnt/gvfs/third-party2/bzip2/c9ef7629c2aa0024f7a416e87602f06eb88f5eac/1.0.6/gcc-4.8.1-glibc-2.17/c3f970a/include/"
|
||||
BZIP_LIBS=" /mnt/gvfs/third-party2/bzip2/c9ef7629c2aa0024f7a416e87602f06eb88f5eac/1.0.6/gcc-4.8.1-glibc-2.17/c3f970a/lib/libbz2.a"
|
||||
# glibc
|
||||
GLIBC_INCLUDE="$GLIBC_BASE/include"
|
||||
GLIBC_LIBS=" -L $GLIBC_BASE/lib"
|
||||
|
||||
LZ4_REV=065ec7e38fe83329031f6668c43bef83eff5808b
|
||||
LZ4_INCLUDE=" -I /mnt/gvfs/third-party2/lz4/$LZ4_REV/r108/gcc-4.8.1-glibc-2.17/c3f970a/include"
|
||||
LZ4_LIBS=" /mnt/gvfs/third-party2/lz4/$LZ4_REV/r108/gcc-4.8.1-glibc-2.17/c3f970a/lib/liblz4.a"
|
||||
# snappy
|
||||
SNAPPY_INCLUDE=" -I $SNAPPY_BASE/include/"
|
||||
if test -z $PIC_BUILD; then
|
||||
SNAPPY_LIBS=" $SNAPPY_BASE/lib/libsnappy.a"
|
||||
else
|
||||
SNAPPY_LIBS=" $SNAPPY_BASE/lib/libsnappy_pic.a"
|
||||
fi
|
||||
CFLAGS+=" -DSNAPPY"
|
||||
|
||||
if test -z $PIC_BUILD; then
|
||||
# location of zlib headers and libraries
|
||||
ZLIB_INCLUDE=" -I $ZLIB_BASE/include/"
|
||||
ZLIB_LIBS=" $ZLIB_BASE/lib/libz.a"
|
||||
CFLAGS+=" -DZLIB"
|
||||
|
||||
# location of bzip headers and libraries
|
||||
BZIP_INCLUDE=" -I $BZIP2_BASE/include/"
|
||||
BZIP_LIBS=" $BZIP2_BASE/lib/libbz2.a"
|
||||
CFLAGS+=" -DBZIP2"
|
||||
|
||||
LZ4_INCLUDE=" -I $LZ4_BASE/include/"
|
||||
LZ4_LIBS=" $LZ4_BASE/lib/liblz4.a"
|
||||
CFLAGS+=" -DLZ4"
|
||||
|
||||
ZSTD_INCLUDE=" -I $ZSTD_BASE/include/"
|
||||
ZSTD_LIBS=" $ZSTD_BASE/lib/libzstd.a"
|
||||
CFLAGS+=" -DZSTD"
|
||||
fi
|
||||
|
||||
# location of gflags headers and libraries
|
||||
GFLAGS_INCLUDE=" -I /mnt/gvfs/third-party2/gflags/1ad047a6e6f6673991918ecadc670868205a243a/1.6/gcc-4.8.1-glibc-2.17/c3f970a/include/"
|
||||
GFLAGS_LIBS=" /mnt/gvfs/third-party2/gflags/1ad047a6e6f6673991918ecadc670868205a243a/1.6/gcc-4.8.1-glibc-2.17/c3f970a/lib/libgflags.a"
|
||||
GFLAGS_INCLUDE=" -I $GFLAGS_BASE/include/"
|
||||
if test -z $PIC_BUILD; then
|
||||
GFLAGS_LIBS=" $GFLAGS_BASE/lib/libgflags.a"
|
||||
else
|
||||
GFLAGS_LIBS=" $GFLAGS_BASE/lib/libgflags_pic.a"
|
||||
fi
|
||||
CFLAGS+=" -DGFLAGS=gflags"
|
||||
|
||||
# location of jemalloc
|
||||
JEMALLOC_INCLUDE=" -I /mnt/gvfs/third-party2/jemalloc/c60d854f7824f334195fe7fd34b2bc9057e3c1f9/3.6.0/gcc-4.8.1-glibc-2.17/4d53c6f/include"
|
||||
JEMALLOC_LIB=" -Wl,--whole-archive /mnt/gvfs/third-party2/jemalloc/c60d854f7824f334195fe7fd34b2bc9057e3c1f9/3.6.0/gcc-4.8.1-glibc-2.17/4d53c6f/lib/libjemalloc.a"
|
||||
JEMALLOC_INCLUDE=" -I $JEMALLOC_BASE/include/"
|
||||
JEMALLOC_LIB=" $JEMALLOC_BASE/lib/libjemalloc.a"
|
||||
|
||||
# location of numa
|
||||
NUMA_REV=829d10dac0230f99cd7e1778869d2adf3da24b65
|
||||
NUMA_INCLUDE=" -I /mnt/gvfs/third-party2/numa/$NUMA_REV/2.0.8/gcc-4.8.1-glibc-2.17/c3f970a/include/"
|
||||
NUMA_LIB=" /mnt/gvfs/third-party2/numa/$NUMA_REV/2.0.8/gcc-4.8.1-glibc-2.17/c3f970a/lib/libnuma.a"
|
||||
if test -z $PIC_BUILD; then
|
||||
# location of numa
|
||||
NUMA_INCLUDE=" -I $NUMA_BASE/include/"
|
||||
NUMA_LIB=" $NUMA_BASE/lib/libnuma.a"
|
||||
CFLAGS+=" -DNUMA"
|
||||
|
||||
# location of libunwind
|
||||
LIBUNWIND_REV=2c060e64064559905d46fd194000d61592087bdc
|
||||
LIBUNWIND="/mnt/gvfs/third-party2/libunwind/$LIBUNWIND_REV/1.1/gcc-4.8.1-glibc-2.17/675d945/lib/libunwind.a"
|
||||
# location of libunwind
|
||||
LIBUNWIND="$LIBUNWIND_BASE/lib/libunwind.a"
|
||||
fi
|
||||
|
||||
# location of TBB
|
||||
TBB_INCLUDE=" -isystem $TBB_BASE/include/"
|
||||
if test -z $PIC_BUILD; then
|
||||
TBB_LIBS="$TBB_BASE/lib/libtbb.a"
|
||||
else
|
||||
TBB_LIBS="$TBB_BASE/lib/libtbb_pic.a"
|
||||
fi
|
||||
CFLAGS+=" -DTBB"
|
||||
|
||||
# use Intel SSE support for checksum calculations
|
||||
export USE_SSE=" -msse -msse4.2 "
|
||||
|
||||
BINUTILS="/mnt/gvfs/third-party2/binutils/2aff2e7b474cd3e6ab23495ad1224b7d214b9f8e/2.21.1/centos6-native/da39a3e/bin"
|
||||
BINUTILS="$BINUTILS_BASE/bin"
|
||||
AR="$BINUTILS/ar"
|
||||
|
||||
DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP_INCLUDE $LZ4_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE"
|
||||
DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP_INCLUDE $LZ4_INCLUDE $ZSTD_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE $TBB_INCLUDE"
|
||||
|
||||
GCC_BASE="/mnt/gvfs/third-party2/gcc/1ec615e23800f0815d474478ba476a0adc3fe788/4.8.1/centos6-native/cc6c9dc"
|
||||
STDLIBS="-L $GCC_BASE/lib64"
|
||||
|
||||
CLANG_BIN="$CLANG_BASE/bin"
|
||||
CLANG_LIB="$CLANG_BASE/lib"
|
||||
CLANG_SRC="$CLANG_BASE/../../src"
|
||||
|
||||
CLANG_ANALYZER="$CLANG_BIN/clang++"
|
||||
CLANG_SCAN_BUILD="$CLANG_SRC/llvm/tools/clang/tools/scan-build/bin/scan-build"
|
||||
|
||||
if [ -z "$USE_CLANG" ]; then
|
||||
# gcc
|
||||
CC="$GCC_BASE/bin/gcc"
|
||||
CXX="$GCC_BASE/bin/g++"
|
||||
|
||||
CFLAGS="-B$BINUTILS/gold -m64 -mtune=generic"
|
||||
CFLAGS+=" -isystem $GLIBC_INCLUDE"
|
||||
|
||||
CFLAGS+=" -B$BINUTILS/gold"
|
||||
CFLAGS+=" -isystem $LIBGCC_INCLUDE"
|
||||
CFLAGS+=" -isystem $GLIBC_INCLUDE"
|
||||
JEMALLOC=1
|
||||
else
|
||||
# clang
|
||||
CLANG_BASE="/mnt/gvfs/third-party2/clang/9ab68376f938992c4eb5946ca68f90c3185cffc8/3.4"
|
||||
CLANG_INCLUDE="$CLANG_BASE/gcc-4.8.1-glibc-2.17/fb0f730/lib/clang/3.4/include"
|
||||
CC="$CLANG_BASE/centos6-native/9cefd8a/bin/clang"
|
||||
CXX="$CLANG_BASE/centos6-native/9cefd8a/bin/clang++"
|
||||
# clang
|
||||
CLANG_INCLUDE="$CLANG_LIB/clang/stable/include"
|
||||
CC="$CLANG_BIN/clang"
|
||||
CXX="$CLANG_BIN/clang++"
|
||||
|
||||
KERNEL_HEADERS_INCLUDE="/mnt/gvfs/third-party2/kernel-headers/a683ed7135276731065a9d76d3016c9731f4e2f9/3.2.18_70_fbk11_00129_gc8882d0/gcc-4.8.1-glibc-2.17/da39a3e/include/"
|
||||
KERNEL_HEADERS_INCLUDE="$KERNEL_HEADERS_BASE/include"
|
||||
|
||||
CFLAGS="-B$BINUTILS/gold -nostdinc -nostdlib"
|
||||
CFLAGS+=" -isystem $LIBGCC_BASE/include/c++/4.8.1 "
|
||||
CFLAGS+=" -isystem $LIBGCC_BASE/include/c++/4.8.1/x86_64-facebook-linux "
|
||||
CFLAGS+=" -B$BINUTILS/gold -nostdinc -nostdlib"
|
||||
CFLAGS+=" -isystem $LIBGCC_BASE/include/c++/7.x "
|
||||
CFLAGS+=" -isystem $LIBGCC_BASE/include/c++/7.x/x86_64-facebook-linux "
|
||||
CFLAGS+=" -isystem $GLIBC_INCLUDE"
|
||||
CFLAGS+=" -isystem $LIBGCC_INCLUDE"
|
||||
CFLAGS+=" -isystem $CLANG_INCLUDE"
|
||||
CFLAGS+=" -isystem $KERNEL_HEADERS_INCLUDE/linux "
|
||||
CFLAGS+=" -isystem $KERNEL_HEADERS_INCLUDE "
|
||||
CFLAGS+=" -Wno-expansion-to-defined "
|
||||
CXXFLAGS="-nostdinc++"
|
||||
fi
|
||||
|
||||
CFLAGS+=" $DEPS_INCLUDE"
|
||||
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_FALLOCATE_PRESENT"
|
||||
CFLAGS+=" -DSNAPPY -DGFLAGS=google -DZLIB -DBZIP2 -DLZ4 -DNUMA"
|
||||
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_SUPPORT_THREAD_LOCAL -DHAVE_SSE42"
|
||||
CXXFLAGS+=" $CFLAGS"
|
||||
|
||||
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $GFLAGS_LIBS $NUMA_LIB"
|
||||
EXEC_LDFLAGS+=" -Wl,--dynamic-linker,/usr/local/fbcode/gcc-4.8.1-glibc-2.17/lib/ld.so"
|
||||
EXEC_LDFLAGS+=" -Wl,--no-whole-archive $LIBUNWIND"
|
||||
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS"
|
||||
EXEC_LDFLAGS+=" -B$BINUTILS/gold"
|
||||
EXEC_LDFLAGS+=" -Wl,--dynamic-linker,/usr/local/fbcode/platform007/lib/ld.so"
|
||||
EXEC_LDFLAGS+=" $LIBUNWIND"
|
||||
EXEC_LDFLAGS+=" -Wl,-rpath=/usr/local/fbcode/platform007/lib"
|
||||
# required by libtbb
|
||||
EXEC_LDFLAGS+=" -ldl"
|
||||
|
||||
PLATFORM_LDFLAGS="$LIBGCC_LIBS $GLIBC_LIBS $STDLIBS -lgcc -lstdc++"
|
||||
|
||||
EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $GFLAGS_LIBS"
|
||||
EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $TBB_LIBS"
|
||||
|
||||
VALGRIND_REV=b2a9f85e4b70cd03abc85a7f3027fbc4cef35bd0
|
||||
VALGRIND_VER="/mnt/gvfs/third-party2/valgrind/$VALGRIND_REV/3.8.1/gcc-4.8.1-glibc-2.17/c3f970a/bin/"
|
||||
VALGRIND_VER="$VALGRIND_BASE/bin/"
|
||||
|
||||
export CC CXX AR CFLAGS CXXFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED VALGRIND_VER JEMALLOC_LIB JEMALLOC_INCLUDE
|
||||
export CC CXX AR CFLAGS CXXFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED VALGRIND_VER JEMALLOC_LIB JEMALLOC_INCLUDE CLANG_ANALYZER CLANG_SCAN_BUILD
|
||||
|
@ -77,7 +77,6 @@
|
||||
#include "util/stop_watch.h"
|
||||
#include "util/sync_point.h"
|
||||
#include "util/string_util.h"
|
||||
#include "util/thread_status_impl.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
@ -246,7 +245,6 @@ DBImpl::DBImpl(const DBOptions& options, const std::string& dbname)
|
||||
}
|
||||
|
||||
DBImpl::~DBImpl() {
|
||||
EraseThreadStatusDbInfo();
|
||||
mutex_.Lock();
|
||||
|
||||
if (flush_on_destroy_) {
|
||||
@ -2505,11 +2503,6 @@ Status DBImpl::CreateColumnFamily(const ColumnFamilyOptions& cf_options,
|
||||
}
|
||||
} // MutexLock l(&mutex_)
|
||||
|
||||
// this is outside the mutex
|
||||
if (s.ok()) {
|
||||
NewThreadStatusCfInfo(
|
||||
reinterpret_cast<ColumnFamilyHandleImpl*>(*handle)->cfd());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -2545,7 +2538,6 @@ Status DBImpl::DropColumnFamily(ColumnFamilyHandle* column_family) {
|
||||
// Note that here we erase the associated cf_info of the to-be-dropped
|
||||
// cfd before its ref-count goes to zero to avoid having to erase cf_info
|
||||
// later inside db_mutex.
|
||||
EraseThreadStatusCfInfo(cfd);
|
||||
assert(cfd->IsDropped());
|
||||
auto* mutable_cf_options = cfd->GetLatestMutableCFOptions();
|
||||
max_total_in_memory_state_ -= mutable_cf_options->write_buffer_size *
|
||||
@ -3574,7 +3566,6 @@ Status DB::Open(const DBOptions& db_options, const std::string& dbname,
|
||||
if (cfd != nullptr) {
|
||||
handles->push_back(
|
||||
new ColumnFamilyHandleImpl(cfd, impl, &impl->mutex_));
|
||||
impl->NewThreadStatusCfInfo(cfd);
|
||||
} else {
|
||||
if (db_options.create_missing_column_families) {
|
||||
// missing column family, create it
|
||||
@ -3739,44 +3730,6 @@ Status DestroyDB(const std::string& dbname, const Options& options) {
|
||||
return result;
|
||||
}
|
||||
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
void DBImpl::NewThreadStatusCfInfo(
|
||||
ColumnFamilyData* cfd) const {
|
||||
if (db_options_.enable_thread_tracking) {
|
||||
ThreadStatusImpl::NewColumnFamilyInfo(
|
||||
this, GetName(), cfd, cfd->GetName());
|
||||
}
|
||||
}
|
||||
|
||||
void DBImpl::EraseThreadStatusCfInfo(
|
||||
ColumnFamilyData* cfd) const {
|
||||
if (db_options_.enable_thread_tracking) {
|
||||
ThreadStatusImpl::EraseColumnFamilyInfo(cfd);
|
||||
}
|
||||
}
|
||||
|
||||
void DBImpl::EraseThreadStatusDbInfo() const {
|
||||
if (db_options_.enable_thread_tracking) {
|
||||
ThreadStatusImpl::EraseDatabaseInfo(this);
|
||||
}
|
||||
}
|
||||
|
||||
Status GetThreadList(std::vector<ThreadStatus>* thread_list) {
|
||||
return thread_local_status.GetThreadList(thread_list);
|
||||
}
|
||||
#else
|
||||
void DBImpl::NewThreadStatusCfInfo(
|
||||
ColumnFamilyData* cfd) const {
|
||||
}
|
||||
|
||||
void DBImpl::EraseThreadStatusCfInfo(
|
||||
ColumnFamilyData* cfd) const {
|
||||
}
|
||||
|
||||
void DBImpl::EraseThreadStatusDbInfo() const {
|
||||
}
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||
|
||||
//
|
||||
// A global method that can dump out the build version
|
||||
void DumpRocksDBBuildVersion(Logger * log) {
|
||||
|
@ -267,12 +267,6 @@ class DBImpl : public DB {
|
||||
void NotifyOnFlushCompleted(ColumnFamilyData* cfd, uint64_t file_number,
|
||||
const MutableCFOptions& mutable_cf_options);
|
||||
|
||||
void NewThreadStatusCfInfo(ColumnFamilyData* cfd) const;
|
||||
|
||||
void EraseThreadStatusCfInfo(ColumnFamilyData* cfd) const;
|
||||
|
||||
void EraseThreadStatusDbInfo() const;
|
||||
|
||||
private:
|
||||
friend class DB;
|
||||
friend class InternalStats;
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "db/merge_context.h"
|
||||
#include "db/db_iter.h"
|
||||
#include "util/perf_context_imp.h"
|
||||
#include "util/thread_status_impl.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
@ -154,10 +153,6 @@ Status DB::OpenForReadOnly(
|
||||
impl->mutex_.Unlock();
|
||||
if (s.ok()) {
|
||||
*dbptr = impl;
|
||||
for (auto* h : *handles) {
|
||||
impl->NewThreadStatusCfInfo(
|
||||
reinterpret_cast<ColumnFamilyHandleImpl*>(h)->cfd());
|
||||
}
|
||||
} else {
|
||||
for (auto h : *handles) {
|
||||
delete h;
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "rocksdb/table.h"
|
||||
#include "rocksdb/options.h"
|
||||
#include "rocksdb/table_properties.h"
|
||||
#include "rocksdb/thread_status.h"
|
||||
#include "rocksdb/utilities/write_batch_with_index.h"
|
||||
#include "rocksdb/utilities/checkpoint.h"
|
||||
#include "table/block_based_table_factory.h"
|
||||
@ -51,7 +50,6 @@
|
||||
#include "util/testutil.h"
|
||||
#include "util/mock_env.h"
|
||||
#include "util/string_util.h"
|
||||
#include "util/thread_status_impl.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
@ -9104,73 +9102,6 @@ TEST(DBTest, DynamicMemtableOptions) {
|
||||
sleeping_task_low3.WaitUntilDone();
|
||||
}
|
||||
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
TEST(DBTest, GetThreadList) {
|
||||
Options options;
|
||||
options.env = env_;
|
||||
options.enable_thread_tracking = true;
|
||||
TryReopen(options);
|
||||
|
||||
std::vector<ThreadStatus> thread_list;
|
||||
Status s = GetThreadList(&thread_list);
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
// repeat the test with differet number of high / low priority threads
|
||||
const int kTestCount = 3;
|
||||
const unsigned int kHighPriCounts[kTestCount] = {3, 2, 5};
|
||||
const unsigned int kLowPriCounts[kTestCount] = {10, 15, 3};
|
||||
for (int test = 0; test < kTestCount; ++test) {
|
||||
// Change the number of threads in high / low priority pool.
|
||||
env_->SetBackgroundThreads(kHighPriCounts[test], Env::HIGH);
|
||||
env_->SetBackgroundThreads(kLowPriCounts[test], Env::LOW);
|
||||
// Wait to ensure the all threads has been registered
|
||||
env_->SleepForMicroseconds(100000);
|
||||
s = GetThreadList(&thread_list);
|
||||
ASSERT_OK(s);
|
||||
unsigned int thread_type_counts[ThreadStatus::ThreadType::TOTAL];
|
||||
memset(thread_type_counts, 0, sizeof(thread_type_counts));
|
||||
for (auto thread : thread_list) {
|
||||
ASSERT_LT(thread.thread_type, ThreadStatus::ThreadType::TOTAL);
|
||||
thread_type_counts[thread.thread_type]++;
|
||||
}
|
||||
// Verify the total number of threades
|
||||
ASSERT_EQ(
|
||||
thread_list.size(),
|
||||
kHighPriCounts[test] + kLowPriCounts[test]);
|
||||
// Verify the number of high-priority threads
|
||||
ASSERT_EQ(
|
||||
thread_type_counts[ThreadStatus::ThreadType::ROCKSDB_HIGH_PRIORITY],
|
||||
kHighPriCounts[test]);
|
||||
// Verify the number of low-priority threads
|
||||
ASSERT_EQ(
|
||||
thread_type_counts[ThreadStatus::ThreadType::ROCKSDB_LOW_PRIORITY],
|
||||
kLowPriCounts[test]);
|
||||
}
|
||||
if (i == 0) {
|
||||
// repeat the test with multiple column families
|
||||
CreateAndReopenWithCF({"pikachu", "about-to-remove"}, options);
|
||||
ThreadStatusImpl::TEST_VerifyColumnFamilyInfoMap(handles_, true);
|
||||
}
|
||||
}
|
||||
db_->DropColumnFamily(handles_[2]);
|
||||
delete handles_[2];
|
||||
handles_.erase(handles_.begin() + 2);
|
||||
ThreadStatusImpl::TEST_VerifyColumnFamilyInfoMap(handles_, true);
|
||||
Close();
|
||||
ThreadStatusImpl::TEST_VerifyColumnFamilyInfoMap(handles_, true);
|
||||
}
|
||||
|
||||
TEST(DBTest, DisableThreadList) {
|
||||
Options options;
|
||||
options.env = env_;
|
||||
options.enable_thread_tracking = false;
|
||||
TryReopen(options);
|
||||
CreateAndReopenWithCF({"pikachu", "about-to-remove"}, options);
|
||||
// Verify non of the column family info exists
|
||||
ThreadStatusImpl::TEST_VerifyColumnFamilyInfoMap(handles_, false);
|
||||
}
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||
|
||||
TEST(DBTest, DynamicCompactionOptions) {
|
||||
// minimum write buffer size is enforced at 64KB
|
||||
const uint64_t k32KB = 1 << 15;
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "rocksdb/types.h"
|
||||
#include "rocksdb/transaction_log.h"
|
||||
#include "rocksdb/listener.h"
|
||||
#include "rocksdb/thread_status.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
@ -548,11 +547,6 @@ Status DestroyDB(const std::string& name, const Options& options);
|
||||
Status RepairDB(const std::string& dbname, const Options& options);
|
||||
#endif
|
||||
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
// Obtain the status of all rocksdb-related threads.
|
||||
Status GetThreadList(std::vector<ThreadStatus>* thread_list);
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
|
@ -1,67 +0,0 @@
|
||||
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#ifndef ROCKSDB_USING_THREAD_STATUS
|
||||
#define ROCKSDB_USING_THREAD_STATUS \
|
||||
!defined(ROCKSDB_LITE) && \
|
||||
!defined(NROCKSDB_THREAD_STATUS) && \
|
||||
!defined(OS_MACOSX) && \
|
||||
!defined(IOS_CROSS_COMPILE)
|
||||
#endif
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
// A structure that describes the current status of a thread.
|
||||
// The status of active threads can be fetched using
|
||||
// rocksdb::GetThreadList().
|
||||
struct ThreadStatus {
|
||||
enum ThreadType {
|
||||
ROCKSDB_HIGH_PRIORITY = 0x0,
|
||||
ROCKSDB_LOW_PRIORITY = 0x1,
|
||||
USER_THREAD = 0x2,
|
||||
TOTAL = 0x3
|
||||
};
|
||||
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
ThreadStatus(const uint64_t _id,
|
||||
const ThreadType _thread_type,
|
||||
const std::string& _db_name,
|
||||
const std::string& _cf_name,
|
||||
const std::string& _event) :
|
||||
thread_id(_id), thread_type(_thread_type),
|
||||
db_name(_db_name),
|
||||
cf_name(_cf_name),
|
||||
event(_event) {}
|
||||
|
||||
// An unique ID for the thread.
|
||||
const uint64_t thread_id;
|
||||
|
||||
// The type of the thread, it could be ROCKSDB_HIGH_PRIORITY,
|
||||
// ROCKSDB_LOW_PRIORITY, and USER_THREAD
|
||||
const ThreadType thread_type;
|
||||
|
||||
// The name of the DB instance where the thread is currently
|
||||
// involved with. It would be set to empty string if the thread
|
||||
// does not involve in any DB operation.
|
||||
const std::string db_name;
|
||||
|
||||
// The name of the column family where the thread is currently
|
||||
// It would be set to empty string if the thread does not involve
|
||||
// in any column family.
|
||||
const std::string cf_name;
|
||||
|
||||
// The event that the current thread is involved.
|
||||
// It would be set to empty string if the information about event
|
||||
// is not currently available.
|
||||
const std::string event;
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||
};
|
||||
|
||||
} // namespace rocksdb
|
@ -6,7 +6,7 @@
|
||||
|
||||
#define ROCKSDB_MAJOR 3
|
||||
#define ROCKSDB_MINOR 9
|
||||
#define ROCKSDB_PATCH 0
|
||||
#define ROCKSDB_PATCH 1
|
||||
|
||||
// Do not use these. We made the mistake of declaring macros starting with
|
||||
// double underscore. Now we have to live with our choice. We'll deprecate these
|
||||
|
@ -6,6 +6,7 @@
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include "util/random.h"
|
||||
#include "util/iostats_context_imp.h"
|
||||
#include "util/rate_limiter.h"
|
||||
#include "util/thread_status_impl.h"
|
||||
|
||||
// Get nano time for mach systems
|
||||
#ifdef __MACH__
|
||||
@ -76,10 +75,6 @@ int rocksdb_kill_odds = 0;
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
extern ThreadStatusImpl thread_local_status;
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
// A wrapper for fadvise, if the platform doesn't support fadvise,
|
||||
@ -1667,18 +1662,8 @@ class PosixEnv : public Env {
|
||||
BGThreadMetadata* meta = reinterpret_cast<BGThreadMetadata*>(arg);
|
||||
size_t thread_id = meta->thread_id_;
|
||||
ThreadPool* tp = meta->thread_pool_;
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
// for thread-status
|
||||
thread_local_status.SetThreadType(
|
||||
(tp->GetThreadPriority() == Env::Priority::HIGH ?
|
||||
ThreadStatus::ThreadType::ROCKSDB_HIGH_PRIORITY :
|
||||
ThreadStatus::ThreadType::ROCKSDB_LOW_PRIORITY));
|
||||
#endif
|
||||
delete meta;
|
||||
tp->BGThread(thread_id);
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
thread_local_status.UnregisterThread();
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -1,156 +0,0 @@
|
||||
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "util/thread_status_impl.h"
|
||||
#include "util/testharness.h"
|
||||
#include "rocksdb/db.h"
|
||||
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
class SleepingBackgroundTask {
|
||||
public:
|
||||
SleepingBackgroundTask(const void* db_key, const std::string& db_name,
|
||||
const void* cf_key, const std::string& cf_name)
|
||||
: db_key_(db_key), db_name_(db_name),
|
||||
cf_key_(cf_key), cf_name_(cf_name),
|
||||
should_sleep_(true), sleeping_count_(0) {
|
||||
ThreadStatusImpl::NewColumnFamilyInfo(
|
||||
db_key_, db_name_, cf_key_, cf_name_);
|
||||
}
|
||||
|
||||
~SleepingBackgroundTask() {
|
||||
ThreadStatusImpl::EraseDatabaseInfo(db_key_);
|
||||
}
|
||||
|
||||
void DoSleep() {
|
||||
thread_local_status.SetColumnFamilyInfoKey(cf_key_);
|
||||
std::unique_lock<std::mutex> l(mutex_);
|
||||
sleeping_count_++;
|
||||
while (should_sleep_) {
|
||||
bg_cv_.wait(l);
|
||||
}
|
||||
sleeping_count_--;
|
||||
bg_cv_.notify_all();
|
||||
thread_local_status.SetColumnFamilyInfoKey(0);
|
||||
}
|
||||
void WakeUp() {
|
||||
std::unique_lock<std::mutex> l(mutex_);
|
||||
should_sleep_ = false;
|
||||
bg_cv_.notify_all();
|
||||
}
|
||||
void WaitUntilDone() {
|
||||
std::unique_lock<std::mutex> l(mutex_);
|
||||
while (sleeping_count_ > 0) {
|
||||
bg_cv_.wait(l);
|
||||
}
|
||||
}
|
||||
|
||||
static void DoSleepTask(void* arg) {
|
||||
reinterpret_cast<SleepingBackgroundTask*>(arg)->DoSleep();
|
||||
}
|
||||
|
||||
private:
|
||||
const void* db_key_;
|
||||
const std::string db_name_;
|
||||
const void* cf_key_;
|
||||
const std::string cf_name_;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable bg_cv_;
|
||||
bool should_sleep_;
|
||||
std::atomic<int> sleeping_count_;
|
||||
};
|
||||
|
||||
class ThreadListTest {
|
||||
public:
|
||||
ThreadListTest() {
|
||||
}
|
||||
};
|
||||
|
||||
TEST(ThreadListTest, SimpleColumnFamilyInfoTest) {
|
||||
Env* env = Env::Default();
|
||||
const int kHighPriorityThreads = 3;
|
||||
const int kLowPriorityThreads = 5;
|
||||
const int kSleepingHighPriThreads = kHighPriorityThreads - 1;
|
||||
const int kSleepingLowPriThreads = kLowPriorityThreads / 3;
|
||||
env->SetBackgroundThreads(kHighPriorityThreads, Env::HIGH);
|
||||
env->SetBackgroundThreads(kLowPriorityThreads, Env::LOW);
|
||||
|
||||
SleepingBackgroundTask sleeping_task(
|
||||
reinterpret_cast<void*>(1234), "sleeping",
|
||||
reinterpret_cast<void*>(5678), "pikachu");
|
||||
|
||||
for (int test = 0; test < kSleepingHighPriThreads; ++test) {
|
||||
env->Schedule(&SleepingBackgroundTask::DoSleepTask,
|
||||
&sleeping_task, Env::Priority::HIGH);
|
||||
}
|
||||
for (int test = 0; test < kSleepingLowPriThreads; ++test) {
|
||||
env->Schedule(&SleepingBackgroundTask::DoSleepTask,
|
||||
&sleeping_task, Env::Priority::LOW);
|
||||
}
|
||||
|
||||
// make sure everything is scheduled.
|
||||
env->SleepForMicroseconds(10000);
|
||||
|
||||
std::vector<ThreadStatus> thread_list;
|
||||
|
||||
// Verify the number of sleeping threads in each pool.
|
||||
GetThreadList(&thread_list);
|
||||
int sleeping_count[ThreadStatus::ThreadType::TOTAL] = {0};
|
||||
for (auto thread_status : thread_list) {
|
||||
if (thread_status.cf_name == "pikachu" &&
|
||||
thread_status.db_name == "sleeping") {
|
||||
sleeping_count[thread_status.thread_type]++;
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(
|
||||
sleeping_count[ThreadStatus::ThreadType::ROCKSDB_HIGH_PRIORITY],
|
||||
kSleepingHighPriThreads);
|
||||
ASSERT_EQ(
|
||||
sleeping_count[ThreadStatus::ThreadType::ROCKSDB_LOW_PRIORITY],
|
||||
kSleepingLowPriThreads);
|
||||
ASSERT_EQ(
|
||||
sleeping_count[ThreadStatus::ThreadType::USER_THREAD], 0);
|
||||
|
||||
sleeping_task.WakeUp();
|
||||
sleeping_task.WaitUntilDone();
|
||||
|
||||
// Verify none of the threads are sleeping
|
||||
GetThreadList(&thread_list);
|
||||
for (int i = 0; i < ThreadStatus::ThreadType::TOTAL; ++i) {
|
||||
sleeping_count[i] = 0;
|
||||
}
|
||||
|
||||
for (auto thread_status : thread_list) {
|
||||
if (thread_status.cf_name == "pikachu" &&
|
||||
thread_status.db_name == "sleeping") {
|
||||
sleeping_count[thread_status.thread_type]++;
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(
|
||||
sleeping_count[ThreadStatus::ThreadType::ROCKSDB_HIGH_PRIORITY], 0);
|
||||
ASSERT_EQ(
|
||||
sleeping_count[ThreadStatus::ThreadType::ROCKSDB_LOW_PRIORITY], 0);
|
||||
ASSERT_EQ(
|
||||
sleeping_count[ThreadStatus::ThreadType::USER_THREAD], 0);
|
||||
}
|
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
return rocksdb::test::RunAllTests();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
@ -1,194 +0,0 @@
|
||||
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
#include "port/likely.h"
|
||||
#include "util/mutexlock.h"
|
||||
#include "util/thread_status_impl.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
__thread ThreadStatusData* ThreadStatusImpl::thread_status_data_ = nullptr;
|
||||
std::mutex ThreadStatusImpl::thread_list_mutex_;
|
||||
std::unordered_set<ThreadStatusData*> ThreadStatusImpl::thread_data_set_;
|
||||
std::unordered_map<const void*, std::unique_ptr<ConstantColumnFamilyInfo>>
|
||||
ThreadStatusImpl::cf_info_map_;
|
||||
std::unordered_map<const void*, std::unordered_set<const void*>>
|
||||
ThreadStatusImpl::db_key_map_;
|
||||
|
||||
ThreadStatusImpl thread_local_status;
|
||||
|
||||
ThreadStatusImpl::~ThreadStatusImpl() {
|
||||
assert(thread_data_set_.size() == 0);
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::UnregisterThread() {
|
||||
if (thread_status_data_ != nullptr) {
|
||||
std::lock_guard<std::mutex> lck(thread_list_mutex_);
|
||||
thread_data_set_.erase(thread_status_data_);
|
||||
delete thread_status_data_;
|
||||
thread_status_data_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::SetThreadType(
|
||||
ThreadStatus::ThreadType ttype) {
|
||||
auto* data = InitAndGet();
|
||||
data->thread_type.store(ttype, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::SetColumnFamilyInfoKey(
|
||||
const void* cf_key) {
|
||||
auto* data = InitAndGet();
|
||||
data->cf_key.store(cf_key, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::SetEventInfoPtr(
|
||||
const ThreadEventInfo* event_info) {
|
||||
auto* data = InitAndGet();
|
||||
data->event_info.store(event_info, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
Status ThreadStatusImpl::GetThreadList(
|
||||
std::vector<ThreadStatus>* thread_list) const {
|
||||
thread_list->clear();
|
||||
std::vector<std::shared_ptr<ThreadStatusData>> valid_list;
|
||||
|
||||
std::lock_guard<std::mutex> lck(thread_list_mutex_);
|
||||
for (auto* thread_data : thread_data_set_) {
|
||||
assert(thread_data);
|
||||
auto thread_type = thread_data->thread_type.load(
|
||||
std::memory_order_relaxed);
|
||||
auto cf_key = thread_data->cf_key.load(
|
||||
std::memory_order_relaxed);
|
||||
auto iter = cf_info_map_.find(cf_key);
|
||||
assert(cf_key == 0 || iter != cf_info_map_.end());
|
||||
auto* cf_info = iter != cf_info_map_.end() ?
|
||||
iter->second.get() : nullptr;
|
||||
auto* event_info = thread_data->event_info.load(
|
||||
std::memory_order_relaxed);
|
||||
const std::string* db_name = nullptr;
|
||||
const std::string* cf_name = nullptr;
|
||||
const std::string* event_name = nullptr;
|
||||
if (cf_info != nullptr) {
|
||||
db_name = &cf_info->db_name;
|
||||
cf_name = &cf_info->cf_name;
|
||||
// display lower-level info only when higher-level info is available.
|
||||
if (event_info != nullptr) {
|
||||
event_name = &event_info->event_name;
|
||||
}
|
||||
}
|
||||
thread_list->emplace_back(
|
||||
thread_data->thread_id, thread_type,
|
||||
db_name ? *db_name : "",
|
||||
cf_name ? *cf_name : "",
|
||||
event_name ? *event_name : "");
|
||||
}
|
||||
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
ThreadStatusData* ThreadStatusImpl::InitAndGet() {
|
||||
if (UNLIKELY(thread_status_data_ == nullptr)) {
|
||||
thread_status_data_ = new ThreadStatusData();
|
||||
thread_status_data_->thread_id = reinterpret_cast<uint64_t>(
|
||||
thread_status_data_);
|
||||
std::lock_guard<std::mutex> lck(thread_list_mutex_);
|
||||
thread_data_set_.insert(thread_status_data_);
|
||||
}
|
||||
return thread_status_data_;
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::NewColumnFamilyInfo(
|
||||
const void* db_key, const std::string& db_name,
|
||||
const void* cf_key, const std::string& cf_name) {
|
||||
std::lock_guard<std::mutex> lck(thread_list_mutex_);
|
||||
|
||||
cf_info_map_[cf_key].reset(
|
||||
new ConstantColumnFamilyInfo(db_key, db_name, cf_name));
|
||||
db_key_map_[db_key].insert(cf_key);
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::EraseColumnFamilyInfo(const void* cf_key) {
|
||||
std::lock_guard<std::mutex> lck(thread_list_mutex_);
|
||||
auto cf_pair = cf_info_map_.find(cf_key);
|
||||
assert(cf_pair != cf_info_map_.end());
|
||||
|
||||
auto* cf_info = cf_pair->second.get();
|
||||
assert(cf_info);
|
||||
|
||||
// Remove its entry from db_key_map_ by the following steps:
|
||||
// 1. Obtain the entry in db_key_map_ whose set contains cf_key
|
||||
// 2. Remove it from the set.
|
||||
auto db_pair = db_key_map_.find(cf_info->db_key);
|
||||
assert(db_pair != db_key_map_.end());
|
||||
size_t result __attribute__((unused)) = db_pair->second.erase(cf_key);
|
||||
assert(result);
|
||||
|
||||
cf_pair->second.reset();
|
||||
result = cf_info_map_.erase(cf_key);
|
||||
assert(result);
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::EraseDatabaseInfo(const void* db_key) {
|
||||
std::lock_guard<std::mutex> lck(thread_list_mutex_);
|
||||
auto db_pair = db_key_map_.find(db_key);
|
||||
if (UNLIKELY(db_pair == db_key_map_.end())) {
|
||||
// In some occasional cases such as DB::Open fails, we won't
|
||||
// register ColumnFamilyInfo for a db.
|
||||
return;
|
||||
}
|
||||
|
||||
size_t result __attribute__((unused)) = 0;
|
||||
for (auto cf_key : db_pair->second) {
|
||||
auto cf_pair = cf_info_map_.find(cf_key);
|
||||
assert(cf_pair != cf_info_map_.end());
|
||||
cf_pair->second.reset();
|
||||
result = cf_info_map_.erase(cf_key);
|
||||
assert(result);
|
||||
}
|
||||
db_key_map_.erase(db_key);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ThreadStatusImpl::~ThreadStatusImpl() {
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::UnregisterThread() {
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::SetThreadType(
|
||||
ThreadStatus::ThreadType ttype) {
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::SetColumnFamilyInfoKey(
|
||||
const void* cf_key) {
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::SetEventInfoPtr(
|
||||
const ThreadEventInfo* event_info) {
|
||||
}
|
||||
|
||||
Status ThreadStatusImpl::GetThreadList(
|
||||
std::vector<ThreadStatus>* thread_list) const {
|
||||
return Status::NotSupported(
|
||||
"GetThreadList is not supported in the current running environment.");
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::NewColumnFamilyInfo(
|
||||
const void* db_key, const std::string& db_name,
|
||||
const void* cf_key, const std::string& cf_name) {
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::EraseColumnFamilyInfo(const void* cf_key) {
|
||||
}
|
||||
|
||||
void ThreadStatusImpl::EraseDatabaseInfo(const void* db_key) {
|
||||
}
|
||||
|
||||
ThreadStatusImpl thread_local_status;
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||
} // namespace rocksdb
|
@ -1,167 +0,0 @@
|
||||
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
//
|
||||
// The implementation of ThreadStatus. It is implemented via combination
|
||||
// of macros and thread-local variables.
|
||||
//
|
||||
// Note that we make get and set access to ThreadStatusData lockless.
|
||||
// As a result, ThreadStatusData as a whole is not atomic. However,
|
||||
// we guarantee consistent ThreadStatusData all the time whenever
|
||||
// user call GetThreadList(). This consistency guarantee is done
|
||||
// by having the following constraint in the internal implementation
|
||||
// of set and get order:
|
||||
//
|
||||
// 1. When reset any information in ThreadStatusData, always start from
|
||||
// clearing up the lower-level information first.
|
||||
// 2. When setting any information in ThreadStatusData, always start from
|
||||
// setting the higher-level information.
|
||||
// 3. When returning ThreadStatusData to the user, fields are fetched from
|
||||
// higher-level to lower-level. In addition, where there's a nullptr
|
||||
// in one field, then all fields that has lower-level than that field
|
||||
// should be ignored.
|
||||
//
|
||||
// The high to low level information would be:
|
||||
// thread_id > thread_type > db > cf > event > event_count > event_details
|
||||
//
|
||||
// This means user might not always get full information, but whenever
|
||||
// returned by the GetThreadList() is guaranteed to be consistent.
|
||||
#pragma once
|
||||
#include <unordered_set>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include "rocksdb/status.h"
|
||||
#include "rocksdb/thread_status.h"
|
||||
#include "port/port_posix.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
class ColumnFamilyHandle;
|
||||
|
||||
// The mutable version of ThreadStatus. It has a static set maintaining
|
||||
// the set of current registered threades.
|
||||
//
|
||||
// Note that it is suggested to call the above macros.
|
||||
struct ConstantColumnFamilyInfo {
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
public:
|
||||
ConstantColumnFamilyInfo(
|
||||
const void* _db_key,
|
||||
const std::string& _db_name,
|
||||
const std::string& _cf_name) :
|
||||
db_key(_db_key), db_name(_db_name), cf_name(_cf_name) {}
|
||||
const void* db_key;
|
||||
const std::string db_name;
|
||||
const std::string cf_name;
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||
};
|
||||
|
||||
struct ThreadEventInfo {
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
public:
|
||||
const std::string event_name;
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||
};
|
||||
|
||||
// the internal data-structure that is used to reflect the current
|
||||
// status of a thread using a set of atomic pointers.
|
||||
struct ThreadStatusData {
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
explicit ThreadStatusData() : thread_id(0) {
|
||||
thread_type.store(ThreadStatus::ThreadType::USER_THREAD);
|
||||
cf_key.store(0);
|
||||
event_info.store(nullptr);
|
||||
}
|
||||
uint64_t thread_id;
|
||||
std::atomic<ThreadStatus::ThreadType> thread_type;
|
||||
std::atomic<const void*> cf_key;
|
||||
std::atomic<const ThreadEventInfo*> event_info;
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||
};
|
||||
|
||||
class ThreadStatusImpl {
|
||||
public:
|
||||
ThreadStatusImpl() {}
|
||||
|
||||
// Releases all ThreadStatusData of all active threads.
|
||||
~ThreadStatusImpl();
|
||||
|
||||
void UnregisterThread();
|
||||
|
||||
// Set the thread type of the current thread.
|
||||
void SetThreadType(ThreadStatus::ThreadType ttype);
|
||||
|
||||
// Update the column-family info of the current thread by setting
|
||||
// its thread-local pointer of ThreadEventInfo to the correct entry.
|
||||
void SetColumnFamilyInfoKey(const void* cf_key);
|
||||
|
||||
// Update the event info of the current thread by setting
|
||||
// its thread-local pointer of ThreadEventInfo to the correct entry.
|
||||
void SetEventInfoPtr(const ThreadEventInfo* event_info);
|
||||
|
||||
Status GetThreadList(
|
||||
std::vector<ThreadStatus>* thread_list) const;
|
||||
|
||||
// Create an entry in the global ColumnFamilyInfo table for the
|
||||
// specified column family. This function should be called only
|
||||
// when the current thread does not hold db_mutex.
|
||||
static void NewColumnFamilyInfo(
|
||||
const void* db_key, const std::string& db_name,
|
||||
const void* cf_key, const std::string& cf_name);
|
||||
|
||||
// Erase all ConstantColumnFamilyInfo that is associated with the
|
||||
// specified db instance. This function should be called only when
|
||||
// the current thread does not hold db_mutex.
|
||||
static void EraseDatabaseInfo(const void* db_key);
|
||||
|
||||
// Erase the ConstantColumnFamilyInfo that is associated with the
|
||||
// specified ColumnFamilyData. This function should be called only
|
||||
// when the current thread does not hold db_mutex.
|
||||
static void EraseColumnFamilyInfo(const void* cf_key);
|
||||
|
||||
// Verifies whether the input ColumnFamilyHandles matches
|
||||
// the information stored in the current cf_info_map.
|
||||
static void TEST_VerifyColumnFamilyInfoMap(
|
||||
const std::vector<ColumnFamilyHandle*>& handles,
|
||||
bool check_exist);
|
||||
|
||||
protected:
|
||||
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
// The thread-local variable for storing thread status.
|
||||
static __thread ThreadStatusData* thread_status_data_;
|
||||
|
||||
// Obtain the pointer to the thread status data. It also performs
|
||||
// initialization when necessary.
|
||||
ThreadStatusData* InitAndGet();
|
||||
|
||||
// The mutex that protects cf_info_map and db_key_map.
|
||||
static std::mutex thread_list_mutex_;
|
||||
|
||||
// The current status data of all active threads.
|
||||
static std::unordered_set<ThreadStatusData*> thread_data_set_;
|
||||
|
||||
// A global map that keeps the column family information. It is stored
|
||||
// globally instead of inside DB is to avoid the situation where DB is
|
||||
// closing while GetThreadList function already get the pointer to its
|
||||
// CopnstantColumnFamilyInfo.
|
||||
static std::unordered_map<
|
||||
const void*, std::unique_ptr<ConstantColumnFamilyInfo>> cf_info_map_;
|
||||
|
||||
// A db_key to cf_key map that allows erasing elements in cf_info_map
|
||||
// associated to the same db_key faster.
|
||||
static std::unordered_map<
|
||||
const void*, std::unordered_set<const void*>> db_key_map_;
|
||||
#else
|
||||
static ThreadStatusData* thread_status_data_;
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
||||
};
|
||||
|
||||
|
||||
extern ThreadStatusImpl thread_local_status;
|
||||
} // namespace rocksdb
|
@ -1,33 +0,0 @@
|
||||
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "util/thread_status_impl.h"
|
||||
#include "db/column_family.h"
|
||||
#if ROCKSDB_USING_THREAD_STATUS
|
||||
|
||||
namespace rocksdb {
|
||||
void ThreadStatusImpl::TEST_VerifyColumnFamilyInfoMap(
|
||||
const std::vector<ColumnFamilyHandle*>& handles,
|
||||
bool check_exist) {
|
||||
std::unique_lock<std::mutex> lock(thread_list_mutex_);
|
||||
if (check_exist) {
|
||||
assert(cf_info_map_.size() == handles.size());
|
||||
}
|
||||
for (auto* handle : handles) {
|
||||
auto* cfd = reinterpret_cast<ColumnFamilyHandleImpl*>(handle)->cfd();
|
||||
auto iter __attribute__((unused)) = cf_info_map_.find(cfd);
|
||||
if (check_exist) {
|
||||
assert(iter != cf_info_map_.end());
|
||||
assert(iter->second);
|
||||
assert(iter->second->cf_name == cfd->GetName());
|
||||
} else {
|
||||
assert(iter == cf_info_map_.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace rocksdb
|
||||
#endif // ROCKSDB_USING_THREAD_STATUS
|
@ -8,7 +8,6 @@
|
||||
#include "db/db_impl.h"
|
||||
#include "db/version_set.h"
|
||||
#include "table/get_context.h"
|
||||
#include "util/thread_status_impl.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
@ -103,7 +102,6 @@ Status CompactedDBImpl::Init(const Options& options) {
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
NewThreadStatusCfInfo(cfd_);
|
||||
version_ = cfd_->GetSuperVersion()->current;
|
||||
user_comparator_ = cfd_->user_comparator();
|
||||
auto* vstorage = version_->storage_info();
|
||||
|
Loading…
Reference in New Issue
Block a user