From 879e45eb998ecaf14548ec626f096be9c7d1dd0f Mon Sep 17 00:00:00 2001 From: Chip Turner Date: Tue, 20 Nov 2012 16:14:04 -0800 Subject: [PATCH] Fix ldb segfault and use static libsnappy for all builds Summary: Link statically against snappy, using the gvfs one for facebook environments, and the bundled one otherwise. In addition, fix a few minor segfaults in ldb when it couldn't open the database, and update .gitignore to include a few other build artifacts. Test Plan: make check Reviewers: dhruba Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D6855 --- .gitignore | 7 +++++++ build_detect_platform | 2 +- fbcode.gcc471.sh | 9 +++++---- util/ldb_cmd.cc | 3 +++ util/ldb_cmd.h | 8 ++++++-- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index f03043056..63c5aacd0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,10 @@ build_config.mk *.so.* *_test db_bench +db_stress +ldb +leveldb_server +leveldb_shell +manifest_dump +sst_dump +util/build_version.cc diff --git a/build_detect_platform b/build_detect_platform index ede941506..dc32c2c44 100755 --- a/build_detect_platform +++ b/build_detect_platform @@ -165,7 +165,7 @@ EOF EOF if [ "$?" = 0 ]; then COMMON_FLAGS="$COMMON_FLAGS -DSNAPPY" - PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lsnappy -L./snappy/libs" + PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS ${SNAPPY_LDFLAGS:-./snappy/libs/libsnappy.a}" fi # Test whether zlib library is installed diff --git a/fbcode.gcc471.sh b/fbcode.gcc471.sh index 77d9f7add..653301bc5 100644 --- a/fbcode.gcc471.sh +++ b/fbcode.gcc471.sh @@ -24,8 +24,8 @@ if test "$USE_HDFS"; then fi # location of snappy headers and libraries -SNAPPY_INCLUDE=" -I ./snappy" -SNAPPY_LIBS=" -L./snappy/libs" +SNAPPY_INCLUDE=" -I $TOOLCHAIN_LIB_BASE/snappy/snappy-1.0.3/7518bbe/include" +SNAPPY_LIBS=" $TOOLCHAIN_LIB_BASE/snappy/snappy-1.0.3/7518bbe/lib/libsnappy.a" # location of boost headers and libraries THRIFT_INCLUDE=" -I $TOOLCHAIN_LIB_BASE/boost/boost-1.48.0/bef9365/include -std=gnu++0x" @@ -37,7 +37,7 @@ if test -z "$USE_SSE"; then export USE_SSE=" -msse -msse4.2 " fi -CC="$TOOLCHAIN_EXECUTABLES/gcc/gcc-4.7.1-glibc-2.14.1/bin/gcc" +CC="$TOOLCHAIN_EXECUTABLES/gcc/gcc-4.7.1-glibc-2.14.1/bin/gcc" CXX="$TOOLCHAIN_EXECUTABLES/gcc/gcc-4.7.1-glibc-2.14.1/bin/g++ $JINCLUDE $SNAPPY_INCLUDE $THRIFT_INCLUDE" AR=$TOOLCHAIN_EXECUTABLES/binutils/binutils-2.21.1/da39a3e/bin/ar RANLIB=$TOOLCHAIN_EXECUTABLES/binutils/binutils-2.21.1/da39a3e/bin/ranlib @@ -49,5 +49,6 @@ EXEC_LDFLAGS=" -Wl,--whole-archive $TOOLCHAIN_LIB_BASE/jemalloc/$TOOL_JEMALLOC/l EXEC_LDFLAGS+="-Wl,--no-whole-archive $TOOLCHAIN_LIB_BASE/libunwind/libunwind-20100812_experimental/91ddd43/lib/libunwind.a" EXEC_LDFLAGS+="$HDFSLIB $SNAPPY_LIBS $THRIFT_LIBS " EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $TOOLCHAIN_LIB_BASE/jemalloc/$TOOL_JEMALLOC/lib/libjemalloc.so" +SNAPPY_LDFLAGS="$SNAPPY_LIBS" -export CC CXX AR RANLIB CFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED +export CC CXX AR RANLIB CFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED SNAPPY_LDFLAGS diff --git a/util/ldb_cmd.cc b/util/ldb_cmd.cc index acbef77ec..fabdda1cb 100644 --- a/util/ldb_cmd.cc +++ b/util/ldb_cmd.cc @@ -315,6 +315,9 @@ void ReduceDBLevels::DoCommand() { old_levels_ = old_level_num; OpenDB(); + if (!db_) { + return; + } // Compact the whole DB to put all files to the highest level. fprintf(stdout, "Compacting the db...\n"); db_->CompactRange(NULL, NULL); diff --git a/util/ldb_cmd.h b/util/ldb_cmd.h index ab56c4d68..a6d664fb8 100644 --- a/util/ldb_cmd.h +++ b/util/ldb_cmd.h @@ -44,10 +44,10 @@ public: case EXEC_SUCCEED: break; case EXEC_FAILED: - ret.append("Failed."); + ret.append("Failed: "); break; case EXEC_NOT_STARTED: - ret.append("Not started."); + ret.append("Not started: "); } if (!message_.empty()) { ret.append(message_); @@ -134,6 +134,10 @@ public: OpenDB(); } + if (!db_) { + return; + } + DoCommand(); if (exec_state_.IsNotStarted()) { exec_state_ = LDBCommandExecuteResult::SUCCEED("");