diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -5,14 +5,26 @@
 
 Bindings to [RocksDB](https://github.com/facebook/rocksdb).
 
-## Dependencies
+## Building
 
-This package builds RocksDB in place and doesn't link with system-wide RocksDB. Requires:
+This package builds RocksDB in place by default. This requires:
 
 * [`cmake`](https://cmake.org/)
 * [`ninja`](http://ninja-build.org/)
 * `awk`
 
-## Windows support
+You can use the `NINJA_J` environment variable to control the number of threads used by `ninja`, e.g. `NINJA_J=2`. This is a hack for building on CI, since `ninja` seems to fail to detect the actual number of CPU cores available.
+
+To skip building and link with system-wide RocksDB, use the `system-rocksdb` Cabal flag. This is not recommended, since this package is only developed with the latest release of RocksDB.
+
+## Using
+
+[`Database.RocksDB.Internals`](src/Database/RocksDB/Internals.hs) contains the raw C bindings. All functions and `enum` values in [`rocksdb/c.h`](rocksdb-5.8/include/rocksdb/c.h) are covered. The opaque types like `rocksdb_t`, `rocksdb_options_t` have corresponding Haskell types like `Rocksdb`, `RocksdbOptions`. They are nullary datatypes and are only used to mark the `Ptr` phantom type.
+
+The higher-level API is being worked on. Using functions like `marshalOptions`, `openDB`, you can obtain a `ForeignPtr` which carries a C resource. The garbage collector can automatically invokes the `ForeignPtr` finalizers, and you can also use `finalizeForeignPtr` with something like `bracket` or `ResourceT` to ensure scoped finalizing. Also, `ByteString`s are used instead of raw buffers.
+
+Some RocksDB functions require passing in a pointer to an error message buffer for error reporting. The higher-level API will obtain the error message and throw it with a `RocksDBException` when present.
+
+## About Windows support
 
 Not working at the moment (builds but crashes when built with mingw-w64 toolchain). May switch to MSVC to fix it.
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,9 +1,11 @@
+{-# LANGUAGE OverloadedStrings #-}
 {-# OPTIONS_GHC -Wall -Wno-deprecations #-}
 
 import Data.Foldable
 import Distribution.Simple
 import Distribution.Simple.LocalBuildInfo
 import Distribution.Simple.Toolkit
+import Distribution.System
 import Distribution.Types.BuildInfo
 import Distribution.Types.GenericPackageDescription
 import Distribution.Types.PackageDescription
@@ -19,48 +21,67 @@
     , confHook =
         \t f -> do
           lbi <- confHook simpleUserHooks t f
-          rocksdb_srcdir <- (</> "rocksdb-5.8") <$> getCurrentDirectory
-          let clbi = getComponentLocalBuildInfo lbi CLibName
-              rocksdb_libname =
-                getHSLibraryName (componentUnitId clbi) ++ "-rocksdb-5.8"
-              rocksdb_builddir = componentBuildDir lbi clbi </> "rocksdb-5.8"
-              lib_installdir =
-                libdir $
-                getComponentInstallDirs
-                  (packageDescription $ fst t)
+          let extra_libs =
+                "stdc++" :
+                (case buildOS of
+                   Windows -> ["rpcrt4"]
+                   _ -> [])
+              [system_rocksdb] =
+                [v | (k, v) <- flagAssignment lbi, k == "system-rocksdb"]
+          if system_rocksdb
+            then pure
+                   lbi
+                   { localPkgDescr =
+                       updatePackageDescription
+                         ( Just
+                             emptyBuildInfo {extraLibs = "rocksdb" : extra_libs}
+                         , []) $
+                       localPkgDescr lbi
+                   }
+            else do
+              rocksdb_srcdir <- (</> "rocksdb-5.8") <$> getCurrentDirectory
+              let clbi = getComponentLocalBuildInfo lbi CLibName
+                  rocksdb_libname =
+                    getHSLibraryName (componentUnitId clbi) ++ "-rocksdb-5.8"
+                  rocksdb_builddir =
+                    componentBuildDir lbi clbi </> "rocksdb-5.8"
+                  lib_installdir =
+                    libdir $
+                    getComponentInstallDirs
+                      (packageDescription $ fst t)
+                      lbi
+                      CLibName
+              for_ [rocksdb_builddir, lib_installdir] $
+                createDirectoryIfMissing True
+              withCurrentDirectory rocksdb_builddir $ do
+                runLBIProgram
                   lbi
-                  CLibName
-          for_ [rocksdb_builddir, lib_installdir] $
-            createDirectoryIfMissing True
-          withCurrentDirectory rocksdb_builddir $ do
-            runLBIProgram
-              lbi
-              cmakeProgram
-              [ rocksdb_srcdir
-              , "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true"
-              , "-G"
-              , "Ninja"
-              ]
-            ninja_extra_args <-
-              do r <- lookupEnv "NINJA_J"
-                 pure $
-                   case r of
-                     Just s -> ["-j", s]
-                     _ -> []
-            runLBIProgram lbi ninjaProgram $
-              ninja_extra_args ++ ["librocksdb.a"]
-            copyFile "librocksdb.a" $
-              lib_installdir </> "lib" ++ rocksdb_libname <.> "a"
-          pure
-            lbi
-            { localPkgDescr =
-                updatePackageDescription
-                  ( Just
-                      emptyBuildInfo
-                      { extraLibs = [rocksdb_libname]
-                      , extraLibDirs = [lib_installdir]
-                      }
-                  , []) $
-                localPkgDescr lbi
-            }
+                  cmakeProgram
+                  [ rocksdb_srcdir
+                  , "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true"
+                  , "-G"
+                  , "Ninja"
+                  ]
+                ninja_extra_args <-
+                  do r <- lookupEnv "NINJA_J"
+                     pure $
+                       case r of
+                         Just s -> ["-j", s]
+                         _ -> []
+                runLBIProgram lbi ninjaProgram $
+                  ninja_extra_args ++ ["librocksdb.a"]
+                copyFile "librocksdb.a" $
+                  lib_installdir </> "lib" ++ rocksdb_libname <.> "a"
+              pure
+                lbi
+                { localPkgDescr =
+                    updatePackageDescription
+                      ( Just
+                          emptyBuildInfo
+                          { extraLibs = rocksdb_libname : extra_libs
+                          , extraLibDirs = [lib_installdir]
+                          }
+                      , []) $
+                    localPkgDescr lbi
+                }
     }
diff --git a/direct-rocksdb.cabal b/direct-rocksdb.cabal
--- a/direct-rocksdb.cabal
+++ b/direct-rocksdb.cabal
@@ -1,9 +1,9 @@
--- This file has been generated from package.yaml by hpack version 0.17.1.
+-- This file has been generated from package.yaml by hpack version 0.19.3.
 --
 -- see: https://github.com/sol/hpack
 
 name:           direct-rocksdb
-version:        0.0.2
+version:        0.0.3
 synopsis:       Bindings to RocksDB.
 category:       Database
 stability:      alpha
@@ -56,12 +56,6 @@
     rocksdb-5.8/cache/lru_cache_test.cc
     rocksdb-5.8/cache/sharded_cache.cc
     rocksdb-5.8/cache/sharded_cache.h
-    rocksdb-5.8/cmake/modules/Findbzip2.cmake
-    rocksdb-5.8/cmake/modules/FindJeMalloc.cmake
-    rocksdb-5.8/cmake/modules/Findlz4.cmake
-    rocksdb-5.8/cmake/modules/Findsnappy.cmake
-    rocksdb-5.8/cmake/modules/Findzlib.cmake
-    rocksdb-5.8/cmake/modules/Findzstd.cmake
     rocksdb-5.8/cmake/RocksDBConfig.cmake.in
     rocksdb-5.8/CMakeLists.txt
     rocksdb-5.8/CONTRIBUTING.md
@@ -1210,34 +1204,34 @@
 
 custom-setup
   setup-depends:
-      base >= 4.10 && < 5
-    , Cabal >= 2.0 && < 2.2
-    , cabal-toolkit >= 0.0.3
+      Cabal >=2.0 && <2.2
+    , base >=4.10 && <5
+    , cabal-toolkit >=0.0.3
     , directory
     , filepath
 
+flag system-rocksdb
+  manual: False
+  default: False
+
 library
   hs-source-dirs:
       src
-  other-extensions: DeriveAnyClass RecordWildCards ScopedTypeVariables
+  other-extensions: DeriveAnyClass InterruptibleFFI RecordWildCards ScopedTypeVariables
   ghc-options: -Wall
-  extra-libraries:
-      stdc++
   build-depends:
-      base >= 4.10 && < 5
+      base >=4.10 && <5
     , bytestring
     , safe-exceptions
-  if os(windows)
-    extra-libraries:
-        rpcrt4
   exposed-modules:
       Database.RocksDB.DB
       Database.RocksDB.Exceptions
       Database.RocksDB.Internals
       Database.RocksDB.Options
       Database.RocksDB.ReadOptions
-      Database.RocksDB.Utils
       Database.RocksDB.WriteOptions
+  other-modules:
+      Database.RocksDB.Utils
   default-language: Haskell2010
 
 test-suite direct-rocksdb-test
@@ -1247,16 +1241,13 @@
       test
   other-extensions: OverloadedStrings
   ghc-options: -Wall -threaded -with-rtsopts=-N
-  extra-libraries:
-      stdc++
   build-depends:
-      base >= 4.10 && < 5
+      base >=4.10 && <5
     , bytestring
-    , safe-exceptions
     , direct-rocksdb
     , directory
     , filepath
-  if os(windows)
-    extra-libraries:
-        rpcrt4
+    , safe-exceptions
+  other-modules:
+      Paths_direct_rocksdb
   default-language: Haskell2010
diff --git a/rocksdb-5.8/CMakeLists.txt b/rocksdb-5.8/CMakeLists.txt
--- a/rocksdb-5.8/CMakeLists.txt
+++ b/rocksdb-5.8/CMakeLists.txt
@@ -1,919 +1,919 @@
-# Prerequisites for Windows:
-#     This cmake build is for Windows 64-bit only.
-#
-# Prerequisites:
-#     You must have at least Visual Studio 2015 Update 3. Start the Developer Command Prompt window that is a part of Visual Studio installation.
-#     Run the build commands from within the Developer Command Prompt window to have paths to the compiler and runtime libraries set.
-#     You must have git.exe in your %PATH% environment variable.
-#
-# To build Rocksdb for Windows is as easy as 1-2-3-4-5:
-#
-# 1. Update paths to third-party libraries in thirdparty.inc file
-# 2. Create a new directory for build artifacts
-#        mkdir build
-#        cd build
-# 3. Run cmake to generate project files for Windows, add more options to enable required third-party libraries.
-#    See thirdparty.inc for more information.
-#        sample command: cmake -G "Visual Studio 14 Win64" -DGFLAGS=1 -DSNAPPY=1 -DJEMALLOC=1 -DJNI=1 ..
-# 4. Then build the project in debug mode (you may want to add /m[:<N>] flag to run msbuild in <N> parallel threads
-#                                          or simply /m ot use all avail cores)
-#        msbuild rocksdb.sln
-#
-#        rocksdb.sln build features exclusions of test only code in Release. If you build ALL_BUILD then everything
-#        will be attempted but test only code does not build in Release mode.
-#
-# 5. And release mode (/m[:<N>] is also supported)
-#        msbuild rocksdb.sln /p:Configuration=Release
-#
-# Linux:
-#
-# 1. Install a recent toolchain such as devtoolset-3 if you're on a older distro. C++11 required.
-# 2. mkdir build; cd build
-# 3. cmake ..
-# 4. make -j
-
-cmake_minimum_required(VERSION 2.6)
-project(rocksdb)
-
-if(POLICY CMP0042)
-  cmake_policy(SET CMP0042 NEW)
-endif()
-
-list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
-
-if(MSVC)
-  include(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty.inc)
-else()
-  option(WITH_JEMALLOC "build with JeMalloc" OFF)
-  if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
-    # FreeBSD has jemaloc as default malloc
-    # but it does not have all the jemalloc files in include/...
-    set(WITH_JEMALLOC ON)
-  else()
-    if(WITH_JEMALLOC)
-      find_package(JeMalloc REQUIRED)
-      add_definitions(-DROCKSDB_JEMALLOC -DJEMALLOC_NO_DEMANGLE)
-      include_directories(${JEMALLOC_INCLUDE_DIR})
-    endif()
-  endif()
-
-  option(WITH_SNAPPY "build with SNAPPY" OFF)
-  if(WITH_SNAPPY)
-    find_package(snappy REQUIRED)
-    add_definitions(-DSNAPPY)
-    include_directories(${SNAPPY_INCLUDE_DIR})
-    list(APPEND THIRDPARTY_LIBS ${SNAPPY_LIBRARIES})
-  endif()
-
-  option(WITH_ZLIB "build with zlib" OFF)
-  if(WITH_ZLIB)
-    find_package(zlib REQUIRED)
-    add_definitions(-DZLIB)
-    include_directories(${ZLIB_INCLUDE_DIR})
-    list(APPEND THIRDPARTY_LIBS ${ZLIB_LIBRARIES})
-  endif()
-
-  option(WITH_BZ2 "build with bzip2" OFF)
-  if(WITH_BZ2)
-    find_package(bzip2 REQUIRED)
-    add_definitions(-DBZIP2)
-    include_directories(${BZIP2_INCLUDE_DIR})
-    list(APPEND THIRDPARTY_LIBS ${BZIP2_LIBRARIES})
-  endif()
-
-  option(WITH_LZ4 "build with lz4" OFF)
-  if(WITH_LZ4)
-    find_package(lz4 REQUIRED)
-    add_definitions(-DLZ4)
-    include_directories(${LZ4_INCLUDE_DIR})
-    list(APPEND THIRDPARTY_LIBS ${LZ4_LIBRARIES})
-  endif()
-
-  option(WITH_ZSTD "build with zstd" OFF)
-  if(WITH_ZSTD)
-    find_package(zstd REQUIRED)
-    add_definitions(-DZSTD)
-    include_directories(${ZSTD_INCLUDE_DIR})
-    list(APPEND THIRDPARTY_LIBS ${ZSTD_LIBRARIES})
-  endif()
-endif()
-
-if(WIN32)
-  execute_process(COMMAND powershell -noprofile -Command "Get-Date -format MM_dd_yyyy" OUTPUT_VARIABLE DATE)
-  execute_process(COMMAND powershell -noprofile -Command "Get-Date -format HH:mm:ss" OUTPUT_VARIABLE TIME)
-  string(REGEX REPLACE "(..)_(..)_..(..).*" "\\1/\\2/\\3" DATE "${DATE}")
-  string(REGEX REPLACE "(..):(.....).*" " \\1:\\2" TIME "${TIME}")
-  set(GIT_DATE_TIME "${DATE} ${TIME}")
-else()
-  execute_process(COMMAND date "+%Y/%m/%d %H:%M:%S" OUTPUT_VARIABLE DATETIME)
-  string(REGEX REPLACE "\n" "" DATETIME ${DATETIME})
-  set(GIT_DATE_TIME "${DATETIME}")
-endif()
-
-find_package(Git)
-
-if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
-  if(WIN32)
-    execute_process(COMMAND $ENV{COMSPEC} /C ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR} rev-parse HEAD OUTPUT_VARIABLE GIT_SHA)
-  else()
-    execute_process(COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR} rev-parse HEAD OUTPUT_VARIABLE GIT_SHA)
-  endif()
-else()
-  set(GIT_SHA 0)
-endif()
-
-string(REGEX REPLACE "[^0-9a-f]+" "" GIT_SHA "${GIT_SHA}")
-
-if(NOT WIN32)
-  execute_process(COMMAND
-      "./build_tools/version.sh" "full"
-      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
-      OUTPUT_VARIABLE ROCKSDB_VERSION
-  )
-  string(STRIP "${ROCKSDB_VERSION}" ROCKSDB_VERSION)
-  execute_process(COMMAND
-      "./build_tools/version.sh" "major"
-      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
-      OUTPUT_VARIABLE ROCKSDB_VERSION_MAJOR
-  )
-  string(STRIP "${ROCKSDB_VERSION_MAJOR}" ROCKSDB_VERSION_MAJOR)
-endif()
-
-option(WITH_MD_LIBRARY "build with MD" ON)
-if(WIN32 AND MSVC)
-  if(WITH_MD_LIBRARY)
-    set(RUNTIME_LIBRARY "MD")
-  else()
-    set(RUNTIME_LIBRARY "MT")
-  endif()
-endif()
-
-set(BUILD_VERSION_CC ${CMAKE_BINARY_DIR}/build_version.cc)
-configure_file(util/build_version.cc.in ${BUILD_VERSION_CC} @ONLY)
-add_library(build_version OBJECT ${BUILD_VERSION_CC})
-target_include_directories(build_version PRIVATE
-  ${CMAKE_CURRENT_SOURCE_DIR}/util)
-if(MSVC)
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W3 /wd4127 /wd4800 /wd4996 /wd4351")
-else()
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers")
-  if(MINGW)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format")
-  endif()
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-  if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fno-omit-frame-pointer")
-    include(CheckCXXCompilerFlag)
-    CHECK_CXX_COMPILER_FLAG("-momit-leaf-frame-pointer" HAVE_OMIT_LEAF_FRAME_POINTER)
-    if(HAVE_OMIT_LEAF_FRAME_POINTER)
-      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -momit-leaf-frame-pointer")
-    endif()
-  endif()
-endif()
-
-option(PORTABLE "build a portable binary" OFF)
-option(FORCE_SSE42 "force building with SSE4.2, even when PORTABLE=ON" OFF)
-if(PORTABLE)
-  # MSVC does not need a separate compiler flag to enable SSE4.2; if nmmintrin.h
-  # is available, it is available by default.
-  if(FORCE_SSE42 AND NOT MSVC)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
-  endif()
-else()
-  if(MSVC)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
-  else()
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
-  endif()
-endif()
-
-set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS})
-include(CheckCXXSourceCompiles)
-CHECK_CXX_SOURCE_COMPILES("
-#include <cstdint>
-#include <nmmintrin.h>
-int main() {
-  volatile uint32_t x = _mm_crc32_u32(0, 0);
-}
-" HAVE_SSE42)
-if(HAVE_SSE42)
-  add_definitions(-DHAVE_SSE42)
-elseif(FORCE_SSE42)
-  message(FATAL_ERROR "FORCE_SSE42=ON but unable to compile with SSE4.2 enabled")
-endif()
-
-CHECK_CXX_SOURCE_COMPILES("
-#if defined(_MSC_VER) && !defined(__thread)
-#define __thread __declspec(thread)
-#endif
-int main() {
-  static __thread int tls;
-}
-" HAVE_THREAD_LOCAL)
-if(HAVE_THREAD_LOCAL)
-  add_definitions(-DROCKSDB_SUPPORT_THREAD_LOCAL)
-endif()
-
-option(FAIL_ON_WARNINGS "Treat compile warnings as errors" ON)
-if(FAIL_ON_WARNINGS)
-  if(MSVC)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
-  else() # assume GCC
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
-  endif()
-endif()
-
-option(WITH_ASAN "build with ASAN" OFF)
-if(WITH_ASAN)
-  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
-  if(WITH_JEMALLOC)
-    message(FATAL "ASAN does not work well with JeMalloc")
-  endif()
-endif()
-
-option(WITH_TSAN "build with TSAN" OFF)
-if(WITH_TSAN)
-  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fPIC")
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fPIC")
-  if(WITH_JEMALLOC)
-    message(FATAL "TSAN does not work well with JeMalloc")
-  endif()
-endif()
-
-option(WITH_UBSAN "build with UBSAN" OFF)
-if(WITH_UBSAN)
-  add_definitions(-DROCKSDB_UBSAN_RUN)
-  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
-  if(WITH_JEMALLOC)
-    message(FATAL "UBSAN does not work well with JeMalloc")
-  endif()
-endif()
-
-# Used to run CI build and tests so we can run faster
-set(OPTIMIZE_DEBUG_DEFAULT 0)        # Debug build is unoptimized by default use -DOPTDBG=1 to optimize
-
-if(DEFINED OPTDBG)
-   set(OPTIMIZE_DEBUG ${OPTDBG})
-else()
-   set(OPTIMIZE_DEBUG ${OPTIMIZE_DEBUG_DEFAULT})
-endif()
-
-if(MSVC)
-  if((${OPTIMIZE_DEBUG} EQUAL 1))
-    message(STATUS "Debug optimization is enabled")
-    set(CMAKE_CXX_FLAGS_DEBUG "/Oxt /${RUNTIME_LIBRARY}d")
-  else()
-    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /RTC1 /Gm /${RUNTIME_LIBRARY}d")
-  endif()
-  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oxt /Zp8 /Gm- /Gy /${RUNTIME_LIBRARY}")
-
-  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG")
-  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
-endif()
-
-if(CMAKE_COMPILER_IS_GNUCXX)
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp")
-endif()
-
-option(ROCKSDB_LITE "Build RocksDBLite version" OFF)
-if(ROCKSDB_LITE)
-  add_definitions(-DROCKSDB_LITE)
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
-endif()
-
-if(CMAKE_SYSTEM_NAME MATCHES "Cygwin")
-  add_definitions(-fno-builtin-memcmp -DCYGWIN)
-elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
-  add_definitions(-DOS_MACOSX)
-  if(CMAKE_SYSTEM_PROCESSOR MATCHES arm)
-    add_definitions(-DIOS_CROSS_COMPILE -DROCKSDB_LITE)
-    # no debug info for IOS, that will make our library big
-    add_definitions(-DNDEBUG)
-  endif()
-elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
-  add_definitions(-DOS_LINUX)
-elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
-  add_definitions(-DOS_SOLARIS)
-elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
-  add_definitions(-DOS_FREEBSD)
-elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
-  add_definitions(-DOS_NETBSD)
-elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
-  add_definitions(-DOS_OPENBSD)
-elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
-  add_definitions(-DOS_DRAGONFLYBSD)
-elseif(CMAKE_SYSTEM_NAME MATCHES "Android")
-  add_definitions(-DOS_ANDROID)
-elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
-  add_definitions(-DWIN32 -DOS_WIN -D_MBCS -DWIN64 -DNOMINMAX)
-  if(MINGW)
-    add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_VISTA)
-  endif()
-endif()
-
-if(NOT WIN32)
-  add_definitions(-DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX)
-endif()
-
-option(WITH_FALLOCATE "build with fallocate" ON)
-
-if(WITH_FALLOCATE)
-  set(CMAKE_REQUIRED_FLAGS ${CMAKE_C_FLAGS})
-  include(CheckCSourceCompiles)
-  CHECK_C_SOURCE_COMPILES("
-#include <fcntl.h>
-#include <linux/falloc.h>
-int main() {
- int fd = open(\"/dev/null\", 0);
- fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, 0, 1024);
-}
-" HAVE_FALLOCATE)
-  if(HAVE_FALLOCATE)
-    add_definitions(-DROCKSDB_FALLOCATE_PRESENT)
-  endif()
-endif()
-
-include(CheckFunctionExists)
-CHECK_FUNCTION_EXISTS(malloc_usable_size HAVE_MALLOC_USABLE_SIZE)
-if(HAVE_MALLOC_USABLE_SIZE)
-  add_definitions(-DROCKSDB_MALLOC_USABLE_SIZE)
-endif()
-
-include_directories(${PROJECT_SOURCE_DIR})
-include_directories(${PROJECT_SOURCE_DIR}/include)
-include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/gtest-1.7.0/fused-src)
-find_package(Threads REQUIRED)
-
-add_subdirectory(third-party/gtest-1.7.0/fused-src/gtest)
-
-# Main library source code
-
-set(SOURCES
-        cache/clock_cache.cc
-        cache/lru_cache.cc
-        cache/sharded_cache.cc
-        db/builder.cc
-        db/c.cc
-        db/column_family.cc
-        db/compacted_db_impl.cc
-        db/compaction.cc
-        db/compaction_iterator.cc
-        db/compaction_job.cc
-        db/compaction_picker.cc
-        db/compaction_picker_universal.cc
-        db/convenience.cc
-        db/db_filesnapshot.cc
-        db/db_impl.cc
-        db/db_impl_write.cc
-        db/db_impl_compaction_flush.cc
-        db/db_impl_files.cc
-        db/db_impl_open.cc
-        db/db_impl_debug.cc
-        db/db_impl_experimental.cc
-        db/db_impl_readonly.cc
-        db/db_info_dumper.cc
-        db/db_iter.cc
-        db/dbformat.cc
-        db/event_helpers.cc
-        db/experimental.cc
-        db/external_sst_file_ingestion_job.cc
-        db/file_indexer.cc
-        db/flush_job.cc
-        db/flush_scheduler.cc
-        db/forward_iterator.cc
-        db/internal_stats.cc
-        db/log_reader.cc
-        db/log_writer.cc
-        db/malloc_stats.cc
-        db/managed_iterator.cc
-        db/memtable.cc
-        db/memtable_list.cc
-        db/merge_helper.cc
-        db/merge_operator.cc
-        db/range_del_aggregator.cc
-        db/repair.cc
-        db/snapshot_impl.cc
-        db/table_cache.cc
-        db/table_properties_collector.cc
-        db/transaction_log_impl.cc
-        db/version_builder.cc
-        db/version_edit.cc
-        db/version_set.cc
-        db/wal_manager.cc
-        db/write_batch.cc
-        db/write_batch_base.cc
-        db/write_controller.cc
-        db/write_thread.cc
-        env/env.cc
-        env/env_chroot.cc
-        env/env_encryption.cc
-        env/env_hdfs.cc
-        env/mock_env.cc
-        memtable/alloc_tracker.cc
-        memtable/hash_cuckoo_rep.cc
-        memtable/hash_linklist_rep.cc
-        memtable/hash_skiplist_rep.cc
-        memtable/skiplistrep.cc
-        memtable/vectorrep.cc
-        memtable/write_buffer_manager.cc
-        monitoring/histogram.cc
-        monitoring/histogram_windowing.cc
-        monitoring/instrumented_mutex.cc
-        monitoring/iostats_context.cc
-        monitoring/perf_context.cc
-        monitoring/perf_level.cc
-        monitoring/statistics.cc
-        monitoring/thread_status_impl.cc
-        monitoring/thread_status_updater.cc
-        monitoring/thread_status_util.cc
-        monitoring/thread_status_util_debug.cc
-        options/cf_options.cc
-        options/db_options.cc
-        options/options.cc
-        options/options_helper.cc
-        options/options_parser.cc
-        options/options_sanity_check.cc
-        port/stack_trace.cc
-        table/adaptive_table_factory.cc
-        table/block.cc
-        table/block_based_filter_block.cc
-        table/block_based_table_builder.cc
-        table/block_based_table_factory.cc
-        table/block_based_table_reader.cc
-        table/block_builder.cc
-        table/block_prefix_index.cc
-        table/bloom_block.cc
-        table/cuckoo_table_builder.cc
-        table/cuckoo_table_factory.cc
-        table/cuckoo_table_reader.cc
-        table/flush_block_policy.cc
-        table/format.cc
-        table/full_filter_block.cc
-        table/get_context.cc
-        table/index_builder.cc
-        table/iterator.cc
-        table/merging_iterator.cc
-        table/meta_blocks.cc
-        table/partitioned_filter_block.cc
-        table/persistent_cache_helper.cc
-        table/plain_table_builder.cc
-        table/plain_table_factory.cc
-        table/plain_table_index.cc
-        table/plain_table_key_coding.cc
-        table/plain_table_reader.cc
-        table/sst_file_writer.cc
-        table/table_properties.cc
-        table/two_level_iterator.cc
-        tools/db_bench_tool.cc
-        tools/dump/db_dump_tool.cc
-        tools/ldb_cmd.cc
-        tools/ldb_tool.cc
-        tools/sst_dump_tool.cc
-        util/arena.cc
-        util/auto_roll_logger.cc
-        util/bloom.cc
-        util/coding.cc
-        util/compaction_job_stats_impl.cc
-        util/comparator.cc
-        util/concurrent_arena.cc
-        util/crc32c.cc
-        util/delete_scheduler.cc
-        util/dynamic_bloom.cc
-        util/event_logger.cc
-        util/file_reader_writer.cc
-        util/file_util.cc
-        util/filename.cc
-        util/filter_policy.cc
-        util/hash.cc
-        util/log_buffer.cc
-        util/murmurhash.cc
-        util/random.cc
-        util/rate_limiter.cc
-        util/slice.cc
-        util/sst_file_manager_impl.cc
-        util/status.cc
-        util/status_message.cc
-        util/string_util.cc
-        util/sync_point.cc
-        util/testutil.cc
-        util/thread_local.cc
-        util/threadpool_imp.cc
-        util/transaction_test_util.cc
-        util/xxhash.cc
-        utilities/backupable/backupable_db.cc
-        utilities/blob_db/blob_db.cc
-        utilities/blob_db/blob_db_impl.cc
-        utilities/blob_db/blob_dump_tool.cc
-        utilities/blob_db/blob_file.cc
-        utilities/blob_db/blob_log_reader.cc
-        utilities/blob_db/blob_log_writer.cc
-        utilities/blob_db/blob_log_format.cc
-        utilities/blob_db/ttl_extractor.cc
-        utilities/cassandra/cassandra_compaction_filter.cc
-        utilities/cassandra/format.cc
-        utilities/cassandra/merge_operator.cc
-        utilities/checkpoint/checkpoint_impl.cc
-        utilities/col_buf_decoder.cc
-        utilities/col_buf_encoder.cc
-        utilities/column_aware_encoding_util.cc
-        utilities/compaction_filters/remove_emptyvalue_compactionfilter.cc
-        utilities/date_tiered/date_tiered_db_impl.cc
-        utilities/debug.cc
-        utilities/document/document_db.cc
-        utilities/document/json_document.cc
-        utilities/document/json_document_builder.cc
-        utilities/env_mirror.cc
-        utilities/env_timed.cc
-        utilities/geodb/geodb_impl.cc
-        utilities/leveldb_options/leveldb_options.cc
-        utilities/lua/rocks_lua_compaction_filter.cc
-        utilities/memory/memory_util.cc
-        utilities/merge_operators/max.cc
-        utilities/merge_operators/put.cc
-        utilities/merge_operators/string_append/stringappend.cc
-        utilities/merge_operators/string_append/stringappend2.cc
-        utilities/merge_operators/uint64add.cc
-        utilities/option_change_migration/option_change_migration.cc
-        utilities/options/options_util.cc
-        utilities/persistent_cache/block_cache_tier.cc
-        utilities/persistent_cache/block_cache_tier_file.cc
-        utilities/persistent_cache/block_cache_tier_metadata.cc
-        utilities/persistent_cache/persistent_cache_tier.cc
-        utilities/persistent_cache/volatile_tier_impl.cc
-        utilities/redis/redis_lists.cc
-        utilities/simulator_cache/sim_cache.cc
-        utilities/spatialdb/spatial_db.cc
-        utilities/table_properties_collectors/compact_on_deletion_collector.cc
-        utilities/transactions/optimistic_transaction_db_impl.cc
-        utilities/transactions/optimistic_transaction.cc
-        utilities/transactions/transaction_base.cc
-        utilities/transactions/pessimistic_transaction_db.cc
-        utilities/transactions/transaction_db_mutex_impl.cc
-        utilities/transactions/pessimistic_transaction.cc
-        utilities/transactions/transaction_lock_mgr.cc
-        utilities/transactions/transaction_util.cc
-        utilities/transactions/write_prepared_txn.cc
-        utilities/ttl/db_ttl_impl.cc
-        utilities/write_batch_with_index/write_batch_with_index.cc
-        utilities/write_batch_with_index/write_batch_with_index_internal.cc
-        $<TARGET_OBJECTS:build_version>)
-
-if(WIN32)
-  list(APPEND SOURCES
-    port/win/io_win.cc
-    port/win/env_win.cc
-    port/win/env_default.cc
-    port/win/port_win.cc
-    port/win/win_logger.cc
-    port/win/win_thread.cc
-    port/win/xpress_win.cc)
-else()
-  list(APPEND SOURCES
-    port/port_posix.cc
-    env/env_posix.cc
-    env/io_posix.cc)
-endif()
-
-set(ROCKSDB_STATIC_LIB rocksdb${ARTIFACT_SUFFIX})
-set(ROCKSDB_SHARED_LIB rocksdb-shared${ARTIFACT_SUFFIX})
-set(ROCKSDB_IMPORT_LIB ${ROCKSDB_SHARED_LIB})
-if(WIN32)
-  set(SYSTEM_LIBS ${SYSTEM_LIBS} Shlwapi.lib Rpcrt4.lib)
-  set(LIBS ${ROCKSDB_STATIC_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
-else()
-  set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
-  set(LIBS ${ROCKSDB_SHARED_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
-
-  add_library(${ROCKSDB_SHARED_LIB} SHARED ${SOURCES})
-  target_link_libraries(${ROCKSDB_SHARED_LIB}
-    ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
-  set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
-                        LINKER_LANGUAGE CXX
-                        VERSION ${ROCKSDB_VERSION}
-                        SOVERSION ${ROCKSDB_VERSION_MAJOR}
-                        CXX_STANDARD 11
-                        OUTPUT_NAME "rocksdb")
-endif()
-
-option(WITH_LIBRADOS "Build with librados" OFF)
-if(WITH_LIBRADOS)
-  list(APPEND SOURCES
-    utilities/env_librados.cc)
-  list(APPEND THIRDPARTY_LIBS rados)
-endif()
-
-add_library(${ROCKSDB_STATIC_LIB} STATIC ${SOURCES})
-target_link_libraries(${ROCKSDB_STATIC_LIB}
-  ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
-
-if(WIN32)
-  add_library(${ROCKSDB_IMPORT_LIB} SHARED ${SOURCES})
-  target_link_libraries(${ROCKSDB_IMPORT_LIB}
-    ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
-  set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES
-    COMPILE_DEFINITIONS "ROCKSDB_DLL;ROCKSDB_LIBRARY_EXPORTS")
-  if(MSVC)
-    set_target_properties(${ROCKSDB_STATIC_LIB} PROPERTIES
-      COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_STATIC_LIB}.pdb")
-    set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES
-      COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_IMPORT_LIB}.pdb")
-  endif()
-endif()
-
-option(WITH_JNI "build with JNI" OFF)
-if(WITH_JNI OR JNI)
-  message(STATUS "JNI library is enabled")
-  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/java)
-else()
-  message(STATUS "JNI library is disabled")
-endif()
-
-# Installation and packaging
-if(WIN32)
-  option(ROCKSDB_INSTALL_ON_WINDOWS "Enable install target on Windows" OFF)
-endif()
-if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
-  if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
-    if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
-      # Change default installation prefix on Linux to /usr
-      set(CMAKE_INSTALL_PREFIX /usr CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
-    endif()
-  endif()
-
-  include(GNUInstallDirs)
-  include(CMakePackageConfigHelpers)
-
-  set(package_config_destination ${CMAKE_INSTALL_LIBDIR}/cmake/rocksdb)
-
-  configure_package_config_file(
-    ${CMAKE_SOURCE_DIR}/cmake/RocksDBConfig.cmake.in RocksDBConfig.cmake
-    INSTALL_DESTINATION ${package_config_destination}
-  )
-
-  write_basic_package_version_file(
-    RocksDBConfigVersion.cmake
-    VERSION ${ROCKSDB_VERSION}
-    COMPATIBILITY SameMajorVersion
-  )
-
-  install(DIRECTORY include/rocksdb COMPONENT devel DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
-
-  install(
-    TARGETS ${ROCKSDB_STATIC_LIB}
-    EXPORT RocksDBTargets
-    COMPONENT devel
-    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
-    INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
-  )
-
-  install(
-    TARGETS ${ROCKSDB_SHARED_LIB}
-    EXPORT RocksDBTargets
-    COMPONENT runtime
-    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
-    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
-    INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
-  )
-
-  install(
-    EXPORT RocksDBTargets
-    COMPONENT devel
-    DESTINATION ${package_config_destination}
-    NAMESPACE RocksDB::
-  )
-
-  install(
-    FILES
-    ${CMAKE_CURRENT_BINARY_DIR}/RocksDBConfig.cmake
-    ${CMAKE_CURRENT_BINARY_DIR}/RocksDBConfigVersion.cmake
-    COMPONENT devel
-    DESTINATION ${package_config_destination}
-  )
-endif()
-
-option(WITH_TESTS "build with tests" ON)
-if(WITH_TESTS)
-  set(TESTS
-        cache/cache_test.cc
-        cache/lru_cache_test.cc
-        db/column_family_test.cc
-        db/compact_files_test.cc
-        db/compaction_iterator_test.cc
-        db/compaction_job_stats_test.cc
-        db/compaction_job_test.cc
-        db/compaction_picker_test.cc
-        db/comparator_db_test.cc
-        db/corruption_test.cc
-        db/cuckoo_table_db_test.cc
-        db/db_basic_test.cc
-        db/db_block_cache_test.cc
-        db/db_bloom_filter_test.cc
-        db/db_compaction_filter_test.cc
-        db/db_compaction_test.cc
-        db/db_dynamic_level_test.cc
-        db/db_flush_test.cc
-        db/db_inplace_update_test.cc
-        db/db_io_failure_test.cc
-        db/db_iter_test.cc
-        db/db_iterator_test.cc
-        db/db_log_iter_test.cc
-        db/db_memtable_test.cc
-        db/db_merge_operator_test.cc
-        db/db_options_test.cc
-        db/db_properties_test.cc
-        db/db_range_del_test.cc
-        db/db_sst_test.cc
-        db/db_statistics_test.cc
-        db/db_table_properties_test.cc
-        db/db_tailing_iter_test.cc
-        db/db_test.cc
-        db/db_test2.cc
-        db/db_universal_compaction_test.cc
-        db/db_wal_test.cc
-        db/db_write_test.cc
-        db/dbformat_test.cc
-        db/deletefile_test.cc
-        db/external_sst_file_basic_test.cc
-        db/external_sst_file_test.cc
-        db/fault_injection_test.cc
-        db/file_indexer_test.cc
-        db/filename_test.cc
-        db/flush_job_test.cc
-        db/listener_test.cc
-        db/log_test.cc
-        db/manual_compaction_test.cc
-        db/memtable_list_test.cc
-        db/merge_helper_test.cc
-        db/merge_test.cc
-        db/options_file_test.cc
-        db/perf_context_test.cc
-        db/plain_table_db_test.cc
-        db/prefix_test.cc
-        db/repair_test.cc
-        db/table_properties_collector_test.cc
-        db/version_builder_test.cc
-        db/version_edit_test.cc
-        db/version_set_test.cc
-        db/wal_manager_test.cc
-        db/write_batch_test.cc
-        db/write_callback_test.cc
-        db/write_controller_test.cc
-        env/env_basic_test.cc
-        env/env_test.cc
-        env/mock_env_test.cc
-        memtable/inlineskiplist_test.cc
-        memtable/skiplist_test.cc
-        memtable/write_buffer_manager_test.cc
-        monitoring/histogram_test.cc
-        monitoring/iostats_context_test.cc
-        monitoring/statistics_test.cc
-        options/options_settable_test.cc
-        options/options_test.cc
-        table/block_based_filter_block_test.cc
-        table/block_test.cc
-        table/cuckoo_table_builder_test.cc
-        table/cuckoo_table_reader_test.cc
-        table/full_filter_block_test.cc
-        table/merger_test.cc
-        table/table_test.cc
-        tools/ldb_cmd_test.cc
-        tools/reduce_levels_test.cc
-        tools/sst_dump_test.cc
-        util/arena_test.cc
-        util/auto_roll_logger_test.cc
-        util/autovector_test.cc
-        util/bloom_test.cc
-        util/coding_test.cc
-        util/crc32c_test.cc
-        util/delete_scheduler_test.cc
-        util/dynamic_bloom_test.cc
-        util/event_logger_test.cc
-        util/file_reader_writer_test.cc
-        util/filelock_test.cc
-        util/hash_test.cc
-        util/heap_test.cc
-        util/rate_limiter_test.cc
-        util/slice_transform_test.cc
-        util/timer_queue_test.cc
-        util/thread_list_test.cc
-        util/thread_local_test.cc
-        utilities/backupable/backupable_db_test.cc
-        utilities/blob_db/blob_db_test.cc
-        utilities/cassandra/cassandra_functional_test.cc
-        utilities/cassandra/cassandra_format_test.cc
-        utilities/cassandra/cassandra_row_merge_test.cc
-        utilities/cassandra/cassandra_serialize_test.cc
-        utilities/checkpoint/checkpoint_test.cc
-        utilities/column_aware_encoding_test.cc
-        utilities/date_tiered/date_tiered_test.cc
-        utilities/document/document_db_test.cc
-        utilities/document/json_document_test.cc
-        utilities/geodb/geodb_test.cc
-        utilities/lua/rocks_lua_test.cc
-        utilities/memory/memory_test.cc
-        utilities/merge_operators/string_append/stringappend_test.cc
-        utilities/object_registry_test.cc
-        utilities/option_change_migration/option_change_migration_test.cc
-        utilities/options/options_util_test.cc
-        utilities/persistent_cache/hash_table_test.cc
-        utilities/persistent_cache/persistent_cache_test.cc
-        utilities/redis/redis_lists_test.cc
-        utilities/spatialdb/spatial_db_test.cc
-        utilities/simulator_cache/sim_cache_test.cc
-        utilities/table_properties_collectors/compact_on_deletion_collector_test.cc
-        utilities/transactions/optimistic_transaction_test.cc
-        utilities/transactions/transaction_test.cc
-        utilities/ttl/ttl_test.cc
-        utilities/write_batch_with_index/write_batch_with_index_test.cc
-  )
-  if(WITH_LIBRADOS)
-    list(APPEND TESTS utilities/env_librados_test.cc)
-  endif()
-
-  set(BENCHMARKS
-    cache/cache_bench.cc
-    memtable/memtablerep_bench.cc
-    tools/db_bench.cc
-    table/table_reader_bench.cc
-    utilities/column_aware_encoding_exp.cc
-    utilities/persistent_cache/hash_table_bench.cc)
-  add_library(testharness OBJECT util/testharness.cc)
-  foreach(sourcefile ${BENCHMARKS})
-    get_filename_component(exename ${sourcefile} NAME_WE)
-    add_executable(${exename}${ARTIFACT_SUFFIX} ${sourcefile}
-      $<TARGET_OBJECTS:testharness>)
-    target_link_libraries(${exename}${ARTIFACT_SUFFIX} gtest ${LIBS})
-  endforeach(sourcefile ${BENCHMARKS})
-
-  # For test util library that is build only in DEBUG mode
-  # and linked to tests. Add test only code that is not #ifdefed for Release here.
-  set(TESTUTIL_SOURCE
-      db/db_test_util.cc
-      monitoring/thread_status_updater_debug.cc
-      table/mock_table.cc
-      util/fault_injection_test_env.cc
-      utilities/cassandra/test_utils.cc
-  )
-  # test utilities are only build in debug
-  enable_testing()
-  add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
-  set(TESTUTILLIB testutillib${ARTIFACT_SUFFIX})
-  add_library(${TESTUTILLIB} STATIC ${TESTUTIL_SOURCE})
-  if(MSVC)
-    set_target_properties(${TESTUTILLIB} PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/testutillib${ARTIFACT_SUFFIX}.pdb")
-  endif()
-  set_target_properties(${TESTUTILLIB}
-        PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1
-        EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
-        EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
-        )
-
-  # Tests are excluded from Release builds
-  set(TEST_EXES ${TESTS})
-
-  foreach(sourcefile ${TEST_EXES})
-      get_filename_component(exename ${sourcefile} NAME_WE)
-      add_executable(${exename}${ARTIFACT_SUFFIX} ${sourcefile}
-        $<TARGET_OBJECTS:testharness>)
-      set_target_properties(${exename}${ARTIFACT_SUFFIX}
-        PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1
-        EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
-        EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
-        )
-      target_link_libraries(${exename}${ARTIFACT_SUFFIX} testutillib${ARTIFACT_SUFFIX} gtest ${LIBS})
-      if(NOT "${exename}" MATCHES "db_sanity_test")
-        add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX})
-        add_dependencies(check ${exename}${ARTIFACT_SUFFIX})
-      endif()
-  endforeach(sourcefile ${TEST_EXES})
-
-  # C executables must link to a shared object
-  set(C_TESTS db/c_test.c)
-  set(C_TEST_EXES ${C_TESTS})
-
-  foreach(sourcefile ${C_TEST_EXES})
-      string(REPLACE ".c" "" exename ${sourcefile})
-      string(REGEX REPLACE "^((.+)/)+" "" exename ${exename})
-      add_executable(${exename}${ARTIFACT_SUFFIX} ${sourcefile})
-      set_target_properties(${exename}${ARTIFACT_SUFFIX}
-        PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1
-        EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
-        EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
-        )
-      target_link_libraries(${exename}${ARTIFACT_SUFFIX} ${ROCKSDB_IMPORT_LIB} testutillib${ARTIFACT_SUFFIX})
-      add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX})
-      add_dependencies(check ${exename}${ARTIFACT_SUFFIX})
-  endforeach(sourcefile ${C_TEST_EXES})
-endif()
-
-option(WITH_TOOLS "build with tools" ON)
-if(WITH_TOOLS)
-  add_subdirectory(tools)
-endif()
+# Prerequisites for Windows:
+#     This cmake build is for Windows 64-bit only.
+#
+# Prerequisites:
+#     You must have at least Visual Studio 2015 Update 3. Start the Developer Command Prompt window that is a part of Visual Studio installation.
+#     Run the build commands from within the Developer Command Prompt window to have paths to the compiler and runtime libraries set.
+#     You must have git.exe in your %PATH% environment variable.
+#
+# To build Rocksdb for Windows is as easy as 1-2-3-4-5:
+#
+# 1. Update paths to third-party libraries in thirdparty.inc file
+# 2. Create a new directory for build artifacts
+#        mkdir build
+#        cd build
+# 3. Run cmake to generate project files for Windows, add more options to enable required third-party libraries.
+#    See thirdparty.inc for more information.
+#        sample command: cmake -G "Visual Studio 14 Win64" -DGFLAGS=1 -DSNAPPY=1 -DJEMALLOC=1 -DJNI=1 ..
+# 4. Then build the project in debug mode (you may want to add /m[:<N>] flag to run msbuild in <N> parallel threads
+#                                          or simply /m ot use all avail cores)
+#        msbuild rocksdb.sln
+#
+#        rocksdb.sln build features exclusions of test only code in Release. If you build ALL_BUILD then everything
+#        will be attempted but test only code does not build in Release mode.
+#
+# 5. And release mode (/m[:<N>] is also supported)
+#        msbuild rocksdb.sln /p:Configuration=Release
+#
+# Linux:
+#
+# 1. Install a recent toolchain such as devtoolset-3 if you're on a older distro. C++11 required.
+# 2. mkdir build; cd build
+# 3. cmake ..
+# 4. make -j
+
+cmake_minimum_required(VERSION 2.6)
+project(rocksdb)
+
+if(POLICY CMP0042)
+  cmake_policy(SET CMP0042 NEW)
+endif()
+
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
+
+if(MSVC)
+  include(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty.inc)
+else()
+  option(WITH_JEMALLOC "build with JeMalloc" OFF)
+  if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+    # FreeBSD has jemaloc as default malloc
+    # but it does not have all the jemalloc files in include/...
+    set(WITH_JEMALLOC ON)
+  else()
+    if(WITH_JEMALLOC)
+      find_package(JeMalloc REQUIRED)
+      add_definitions(-DROCKSDB_JEMALLOC -DJEMALLOC_NO_DEMANGLE)
+      include_directories(${JEMALLOC_INCLUDE_DIR})
+    endif()
+  endif()
+
+  option(WITH_SNAPPY "build with SNAPPY" OFF)
+  if(WITH_SNAPPY)
+    find_package(snappy REQUIRED)
+    add_definitions(-DSNAPPY)
+    include_directories(${SNAPPY_INCLUDE_DIR})
+    list(APPEND THIRDPARTY_LIBS ${SNAPPY_LIBRARIES})
+  endif()
+
+  option(WITH_ZLIB "build with zlib" OFF)
+  if(WITH_ZLIB)
+    find_package(zlib REQUIRED)
+    add_definitions(-DZLIB)
+    include_directories(${ZLIB_INCLUDE_DIR})
+    list(APPEND THIRDPARTY_LIBS ${ZLIB_LIBRARIES})
+  endif()
+
+  option(WITH_BZ2 "build with bzip2" OFF)
+  if(WITH_BZ2)
+    find_package(bzip2 REQUIRED)
+    add_definitions(-DBZIP2)
+    include_directories(${BZIP2_INCLUDE_DIR})
+    list(APPEND THIRDPARTY_LIBS ${BZIP2_LIBRARIES})
+  endif()
+
+  option(WITH_LZ4 "build with lz4" OFF)
+  if(WITH_LZ4)
+    find_package(lz4 REQUIRED)
+    add_definitions(-DLZ4)
+    include_directories(${LZ4_INCLUDE_DIR})
+    list(APPEND THIRDPARTY_LIBS ${LZ4_LIBRARIES})
+  endif()
+
+  option(WITH_ZSTD "build with zstd" OFF)
+  if(WITH_ZSTD)
+    find_package(zstd REQUIRED)
+    add_definitions(-DZSTD)
+    include_directories(${ZSTD_INCLUDE_DIR})
+    list(APPEND THIRDPARTY_LIBS ${ZSTD_LIBRARIES})
+  endif()
+endif()
+
+if(WIN32)
+  execute_process(COMMAND powershell -noprofile -Command "Get-Date -format MM_dd_yyyy" OUTPUT_VARIABLE DATE)
+  execute_process(COMMAND powershell -noprofile -Command "Get-Date -format HH:mm:ss" OUTPUT_VARIABLE TIME)
+  string(REGEX REPLACE "(..)_(..)_..(..).*" "\\1/\\2/\\3" DATE "${DATE}")
+  string(REGEX REPLACE "(..):(.....).*" " \\1:\\2" TIME "${TIME}")
+  set(GIT_DATE_TIME "${DATE} ${TIME}")
+else()
+  execute_process(COMMAND date "+%Y/%m/%d %H:%M:%S" OUTPUT_VARIABLE DATETIME)
+  string(REGEX REPLACE "\n" "" DATETIME ${DATETIME})
+  set(GIT_DATE_TIME "${DATETIME}")
+endif()
+
+find_package(Git)
+
+if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
+  if(WIN32)
+    execute_process(COMMAND $ENV{COMSPEC} /C ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR} rev-parse HEAD OUTPUT_VARIABLE GIT_SHA)
+  else()
+    execute_process(COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR} rev-parse HEAD OUTPUT_VARIABLE GIT_SHA)
+  endif()
+else()
+  set(GIT_SHA 0)
+endif()
+
+string(REGEX REPLACE "[^0-9a-f]+" "" GIT_SHA "${GIT_SHA}")
+
+if(NOT WIN32)
+  execute_process(COMMAND
+      "./build_tools/version.sh" "full"
+      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+      OUTPUT_VARIABLE ROCKSDB_VERSION
+  )
+  string(STRIP "${ROCKSDB_VERSION}" ROCKSDB_VERSION)
+  execute_process(COMMAND
+      "./build_tools/version.sh" "major"
+      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+      OUTPUT_VARIABLE ROCKSDB_VERSION_MAJOR
+  )
+  string(STRIP "${ROCKSDB_VERSION_MAJOR}" ROCKSDB_VERSION_MAJOR)
+endif()
+
+option(WITH_MD_LIBRARY "build with MD" ON)
+if(WIN32 AND MSVC)
+  if(WITH_MD_LIBRARY)
+    set(RUNTIME_LIBRARY "MD")
+  else()
+    set(RUNTIME_LIBRARY "MT")
+  endif()
+endif()
+
+set(BUILD_VERSION_CC ${CMAKE_BINARY_DIR}/build_version.cc)
+configure_file(util/build_version.cc.in ${BUILD_VERSION_CC} @ONLY)
+add_library(build_version OBJECT ${BUILD_VERSION_CC})
+target_include_directories(build_version PRIVATE
+  ${CMAKE_CURRENT_SOURCE_DIR}/util)
+if(MSVC)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W3 /wd4127 /wd4800 /wd4996 /wd4351")
+else()
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers")
+  if(MINGW)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format")
+  endif()
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+  if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fno-omit-frame-pointer")
+    include(CheckCXXCompilerFlag)
+    CHECK_CXX_COMPILER_FLAG("-momit-leaf-frame-pointer" HAVE_OMIT_LEAF_FRAME_POINTER)
+    if(HAVE_OMIT_LEAF_FRAME_POINTER)
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -momit-leaf-frame-pointer")
+    endif()
+  endif()
+endif()
+
+option(PORTABLE "build a portable binary" OFF)
+option(FORCE_SSE42 "force building with SSE4.2, even when PORTABLE=ON" OFF)
+if(PORTABLE)
+  # MSVC does not need a separate compiler flag to enable SSE4.2; if nmmintrin.h
+  # is available, it is available by default.
+  if(FORCE_SSE42 AND NOT MSVC)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
+  endif()
+else()
+  if(MSVC)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
+  else()
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
+  endif()
+endif()
+
+set(CMAKE_REQUIRED_FLAGS ${CMAKE_CXX_FLAGS})
+include(CheckCXXSourceCompiles)
+CHECK_CXX_SOURCE_COMPILES("
+#include <cstdint>
+#include <nmmintrin.h>
+int main() {
+  volatile uint32_t x = _mm_crc32_u32(0, 0);
+}
+" HAVE_SSE42)
+if(HAVE_SSE42)
+  add_definitions(-DHAVE_SSE42)
+elseif(FORCE_SSE42)
+  message(FATAL_ERROR "FORCE_SSE42=ON but unable to compile with SSE4.2 enabled")
+endif()
+
+CHECK_CXX_SOURCE_COMPILES("
+#if defined(_MSC_VER) && !defined(__thread)
+#define __thread __declspec(thread)
+#endif
+int main() {
+  static __thread int tls;
+}
+" HAVE_THREAD_LOCAL)
+if(HAVE_THREAD_LOCAL)
+  add_definitions(-DROCKSDB_SUPPORT_THREAD_LOCAL)
+endif()
+
+option(FAIL_ON_WARNINGS "Treat compile warnings as errors" ON)
+if(FAIL_ON_WARNINGS)
+  if(MSVC)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
+  else() # assume GCC
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+  endif()
+endif()
+
+option(WITH_ASAN "build with ASAN" OFF)
+if(WITH_ASAN)
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
+  if(WITH_JEMALLOC)
+    message(FATAL "ASAN does not work well with JeMalloc")
+  endif()
+endif()
+
+option(WITH_TSAN "build with TSAN" OFF)
+if(WITH_TSAN)
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fPIC")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fPIC")
+  if(WITH_JEMALLOC)
+    message(FATAL "TSAN does not work well with JeMalloc")
+  endif()
+endif()
+
+option(WITH_UBSAN "build with UBSAN" OFF)
+if(WITH_UBSAN)
+  add_definitions(-DROCKSDB_UBSAN_RUN)
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
+  if(WITH_JEMALLOC)
+    message(FATAL "UBSAN does not work well with JeMalloc")
+  endif()
+endif()
+
+# Used to run CI build and tests so we can run faster
+set(OPTIMIZE_DEBUG_DEFAULT 0)        # Debug build is unoptimized by default use -DOPTDBG=1 to optimize
+
+if(DEFINED OPTDBG)
+   set(OPTIMIZE_DEBUG ${OPTDBG})
+else()
+   set(OPTIMIZE_DEBUG ${OPTIMIZE_DEBUG_DEFAULT})
+endif()
+
+if(MSVC)
+  if((${OPTIMIZE_DEBUG} EQUAL 1))
+    message(STATUS "Debug optimization is enabled")
+    set(CMAKE_CXX_FLAGS_DEBUG "/Oxt /${RUNTIME_LIBRARY}d")
+  else()
+    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /RTC1 /Gm /${RUNTIME_LIBRARY}d")
+  endif()
+  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oxt /Zp8 /Gm- /Gy /${RUNTIME_LIBRARY}")
+
+  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG")
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
+endif()
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp")
+endif()
+
+option(ROCKSDB_LITE "Build RocksDBLite version" OFF)
+if(ROCKSDB_LITE)
+  add_definitions(-DROCKSDB_LITE)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
+endif()
+
+if(CMAKE_SYSTEM_NAME MATCHES "Cygwin")
+  add_definitions(-fno-builtin-memcmp -DCYGWIN)
+elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+  add_definitions(-DOS_MACOSX)
+  if(CMAKE_SYSTEM_PROCESSOR MATCHES arm)
+    add_definitions(-DIOS_CROSS_COMPILE -DROCKSDB_LITE)
+    # no debug info for IOS, that will make our library big
+    add_definitions(-DNDEBUG)
+  endif()
+elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
+  add_definitions(-DOS_LINUX)
+elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
+  add_definitions(-DOS_SOLARIS)
+elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+  add_definitions(-DOS_FREEBSD)
+elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
+  add_definitions(-DOS_NETBSD)
+elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
+  add_definitions(-DOS_OPENBSD)
+elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
+  add_definitions(-DOS_DRAGONFLYBSD)
+elseif(CMAKE_SYSTEM_NAME MATCHES "Android")
+  add_definitions(-DOS_ANDROID)
+elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
+  add_definitions(-DWIN32 -DOS_WIN -D_MBCS -DWIN64 -DNOMINMAX)
+  if(MINGW)
+    add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_VISTA)
+  endif()
+endif()
+
+if(NOT WIN32)
+  add_definitions(-DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX)
+endif()
+
+option(WITH_FALLOCATE "build with fallocate" ON)
+
+if(WITH_FALLOCATE)
+  set(CMAKE_REQUIRED_FLAGS ${CMAKE_C_FLAGS})
+  include(CheckCSourceCompiles)
+  CHECK_C_SOURCE_COMPILES("
+#include <fcntl.h>
+#include <linux/falloc.h>
+int main() {
+ int fd = open(\"/dev/null\", 0);
+ fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, 0, 1024);
+}
+" HAVE_FALLOCATE)
+  if(HAVE_FALLOCATE)
+    add_definitions(-DROCKSDB_FALLOCATE_PRESENT)
+  endif()
+endif()
+
+include(CheckFunctionExists)
+CHECK_FUNCTION_EXISTS(malloc_usable_size HAVE_MALLOC_USABLE_SIZE)
+if(HAVE_MALLOC_USABLE_SIZE)
+  add_definitions(-DROCKSDB_MALLOC_USABLE_SIZE)
+endif()
+
+include_directories(${PROJECT_SOURCE_DIR})
+include_directories(${PROJECT_SOURCE_DIR}/include)
+include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/gtest-1.7.0/fused-src)
+find_package(Threads REQUIRED)
+
+add_subdirectory(third-party/gtest-1.7.0/fused-src/gtest)
+
+# Main library source code
+
+set(SOURCES
+        cache/clock_cache.cc
+        cache/lru_cache.cc
+        cache/sharded_cache.cc
+        db/builder.cc
+        db/c.cc
+        db/column_family.cc
+        db/compacted_db_impl.cc
+        db/compaction.cc
+        db/compaction_iterator.cc
+        db/compaction_job.cc
+        db/compaction_picker.cc
+        db/compaction_picker_universal.cc
+        db/convenience.cc
+        db/db_filesnapshot.cc
+        db/db_impl.cc
+        db/db_impl_write.cc
+        db/db_impl_compaction_flush.cc
+        db/db_impl_files.cc
+        db/db_impl_open.cc
+        db/db_impl_debug.cc
+        db/db_impl_experimental.cc
+        db/db_impl_readonly.cc
+        db/db_info_dumper.cc
+        db/db_iter.cc
+        db/dbformat.cc
+        db/event_helpers.cc
+        db/experimental.cc
+        db/external_sst_file_ingestion_job.cc
+        db/file_indexer.cc
+        db/flush_job.cc
+        db/flush_scheduler.cc
+        db/forward_iterator.cc
+        db/internal_stats.cc
+        db/log_reader.cc
+        db/log_writer.cc
+        db/malloc_stats.cc
+        db/managed_iterator.cc
+        db/memtable.cc
+        db/memtable_list.cc
+        db/merge_helper.cc
+        db/merge_operator.cc
+        db/range_del_aggregator.cc
+        db/repair.cc
+        db/snapshot_impl.cc
+        db/table_cache.cc
+        db/table_properties_collector.cc
+        db/transaction_log_impl.cc
+        db/version_builder.cc
+        db/version_edit.cc
+        db/version_set.cc
+        db/wal_manager.cc
+        db/write_batch.cc
+        db/write_batch_base.cc
+        db/write_controller.cc
+        db/write_thread.cc
+        env/env.cc
+        env/env_chroot.cc
+        env/env_encryption.cc
+        env/env_hdfs.cc
+        env/mock_env.cc
+        memtable/alloc_tracker.cc
+        memtable/hash_cuckoo_rep.cc
+        memtable/hash_linklist_rep.cc
+        memtable/hash_skiplist_rep.cc
+        memtable/skiplistrep.cc
+        memtable/vectorrep.cc
+        memtable/write_buffer_manager.cc
+        monitoring/histogram.cc
+        monitoring/histogram_windowing.cc
+        monitoring/instrumented_mutex.cc
+        monitoring/iostats_context.cc
+        monitoring/perf_context.cc
+        monitoring/perf_level.cc
+        monitoring/statistics.cc
+        monitoring/thread_status_impl.cc
+        monitoring/thread_status_updater.cc
+        monitoring/thread_status_util.cc
+        monitoring/thread_status_util_debug.cc
+        options/cf_options.cc
+        options/db_options.cc
+        options/options.cc
+        options/options_helper.cc
+        options/options_parser.cc
+        options/options_sanity_check.cc
+        port/stack_trace.cc
+        table/adaptive_table_factory.cc
+        table/block.cc
+        table/block_based_filter_block.cc
+        table/block_based_table_builder.cc
+        table/block_based_table_factory.cc
+        table/block_based_table_reader.cc
+        table/block_builder.cc
+        table/block_prefix_index.cc
+        table/bloom_block.cc
+        table/cuckoo_table_builder.cc
+        table/cuckoo_table_factory.cc
+        table/cuckoo_table_reader.cc
+        table/flush_block_policy.cc
+        table/format.cc
+        table/full_filter_block.cc
+        table/get_context.cc
+        table/index_builder.cc
+        table/iterator.cc
+        table/merging_iterator.cc
+        table/meta_blocks.cc
+        table/partitioned_filter_block.cc
+        table/persistent_cache_helper.cc
+        table/plain_table_builder.cc
+        table/plain_table_factory.cc
+        table/plain_table_index.cc
+        table/plain_table_key_coding.cc
+        table/plain_table_reader.cc
+        table/sst_file_writer.cc
+        table/table_properties.cc
+        table/two_level_iterator.cc
+        tools/db_bench_tool.cc
+        tools/dump/db_dump_tool.cc
+        tools/ldb_cmd.cc
+        tools/ldb_tool.cc
+        tools/sst_dump_tool.cc
+        util/arena.cc
+        util/auto_roll_logger.cc
+        util/bloom.cc
+        util/coding.cc
+        util/compaction_job_stats_impl.cc
+        util/comparator.cc
+        util/concurrent_arena.cc
+        util/crc32c.cc
+        util/delete_scheduler.cc
+        util/dynamic_bloom.cc
+        util/event_logger.cc
+        util/file_reader_writer.cc
+        util/file_util.cc
+        util/filename.cc
+        util/filter_policy.cc
+        util/hash.cc
+        util/log_buffer.cc
+        util/murmurhash.cc
+        util/random.cc
+        util/rate_limiter.cc
+        util/slice.cc
+        util/sst_file_manager_impl.cc
+        util/status.cc
+        util/status_message.cc
+        util/string_util.cc
+        util/sync_point.cc
+        util/testutil.cc
+        util/thread_local.cc
+        util/threadpool_imp.cc
+        util/transaction_test_util.cc
+        util/xxhash.cc
+        utilities/backupable/backupable_db.cc
+        utilities/blob_db/blob_db.cc
+        utilities/blob_db/blob_db_impl.cc
+        utilities/blob_db/blob_dump_tool.cc
+        utilities/blob_db/blob_file.cc
+        utilities/blob_db/blob_log_reader.cc
+        utilities/blob_db/blob_log_writer.cc
+        utilities/blob_db/blob_log_format.cc
+        utilities/blob_db/ttl_extractor.cc
+        utilities/cassandra/cassandra_compaction_filter.cc
+        utilities/cassandra/format.cc
+        utilities/cassandra/merge_operator.cc
+        utilities/checkpoint/checkpoint_impl.cc
+        utilities/col_buf_decoder.cc
+        utilities/col_buf_encoder.cc
+        utilities/column_aware_encoding_util.cc
+        utilities/compaction_filters/remove_emptyvalue_compactionfilter.cc
+        utilities/date_tiered/date_tiered_db_impl.cc
+        utilities/debug.cc
+        utilities/document/document_db.cc
+        utilities/document/json_document.cc
+        utilities/document/json_document_builder.cc
+        utilities/env_mirror.cc
+        utilities/env_timed.cc
+        utilities/geodb/geodb_impl.cc
+        utilities/leveldb_options/leveldb_options.cc
+        utilities/lua/rocks_lua_compaction_filter.cc
+        utilities/memory/memory_util.cc
+        utilities/merge_operators/max.cc
+        utilities/merge_operators/put.cc
+        utilities/merge_operators/string_append/stringappend.cc
+        utilities/merge_operators/string_append/stringappend2.cc
+        utilities/merge_operators/uint64add.cc
+        utilities/option_change_migration/option_change_migration.cc
+        utilities/options/options_util.cc
+        utilities/persistent_cache/block_cache_tier.cc
+        utilities/persistent_cache/block_cache_tier_file.cc
+        utilities/persistent_cache/block_cache_tier_metadata.cc
+        utilities/persistent_cache/persistent_cache_tier.cc
+        utilities/persistent_cache/volatile_tier_impl.cc
+        utilities/redis/redis_lists.cc
+        utilities/simulator_cache/sim_cache.cc
+        utilities/spatialdb/spatial_db.cc
+        utilities/table_properties_collectors/compact_on_deletion_collector.cc
+        utilities/transactions/optimistic_transaction_db_impl.cc
+        utilities/transactions/optimistic_transaction.cc
+        utilities/transactions/transaction_base.cc
+        utilities/transactions/pessimistic_transaction_db.cc
+        utilities/transactions/transaction_db_mutex_impl.cc
+        utilities/transactions/pessimistic_transaction.cc
+        utilities/transactions/transaction_lock_mgr.cc
+        utilities/transactions/transaction_util.cc
+        utilities/transactions/write_prepared_txn.cc
+        utilities/ttl/db_ttl_impl.cc
+        utilities/write_batch_with_index/write_batch_with_index.cc
+        utilities/write_batch_with_index/write_batch_with_index_internal.cc
+        $<TARGET_OBJECTS:build_version>)
+
+if(WIN32)
+  list(APPEND SOURCES
+    port/win/io_win.cc
+    port/win/env_win.cc
+    port/win/env_default.cc
+    port/win/port_win.cc
+    port/win/win_logger.cc
+    port/win/win_thread.cc
+    port/win/xpress_win.cc)
+else()
+  list(APPEND SOURCES
+    port/port_posix.cc
+    env/env_posix.cc
+    env/io_posix.cc)
+endif()
+
+set(ROCKSDB_STATIC_LIB rocksdb${ARTIFACT_SUFFIX})
+set(ROCKSDB_SHARED_LIB rocksdb-shared${ARTIFACT_SUFFIX})
+set(ROCKSDB_IMPORT_LIB ${ROCKSDB_SHARED_LIB})
+if(WIN32)
+  set(SYSTEM_LIBS ${SYSTEM_LIBS} Shlwapi.lib Rpcrt4.lib)
+  set(LIBS ${ROCKSDB_STATIC_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
+else()
+  set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
+  set(LIBS ${ROCKSDB_SHARED_LIB} ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
+
+  add_library(${ROCKSDB_SHARED_LIB} SHARED ${SOURCES})
+  target_link_libraries(${ROCKSDB_SHARED_LIB}
+    ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
+  set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES
+                        LINKER_LANGUAGE CXX
+                        VERSION ${ROCKSDB_VERSION}
+                        SOVERSION ${ROCKSDB_VERSION_MAJOR}
+                        CXX_STANDARD 11
+                        OUTPUT_NAME "rocksdb")
+endif()
+
+option(WITH_LIBRADOS "Build with librados" OFF)
+if(WITH_LIBRADOS)
+  list(APPEND SOURCES
+    utilities/env_librados.cc)
+  list(APPEND THIRDPARTY_LIBS rados)
+endif()
+
+add_library(${ROCKSDB_STATIC_LIB} STATIC ${SOURCES})
+target_link_libraries(${ROCKSDB_STATIC_LIB}
+  ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
+
+if(WIN32)
+  add_library(${ROCKSDB_IMPORT_LIB} SHARED ${SOURCES})
+  target_link_libraries(${ROCKSDB_IMPORT_LIB}
+    ${THIRDPARTY_LIBS} ${SYSTEM_LIBS})
+  set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES
+    COMPILE_DEFINITIONS "ROCKSDB_DLL;ROCKSDB_LIBRARY_EXPORTS")
+  if(MSVC)
+    set_target_properties(${ROCKSDB_STATIC_LIB} PROPERTIES
+      COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_STATIC_LIB}.pdb")
+    set_target_properties(${ROCKSDB_IMPORT_LIB} PROPERTIES
+      COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/${ROCKSDB_IMPORT_LIB}.pdb")
+  endif()
+endif()
+
+option(WITH_JNI "build with JNI" OFF)
+if(WITH_JNI OR JNI)
+  message(STATUS "JNI library is enabled")
+  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/java)
+else()
+  message(STATUS "JNI library is disabled")
+endif()
+
+# Installation and packaging
+if(WIN32)
+  option(ROCKSDB_INSTALL_ON_WINDOWS "Enable install target on Windows" OFF)
+endif()
+if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS)
+  if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+    if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+      # Change default installation prefix on Linux to /usr
+      set(CMAKE_INSTALL_PREFIX /usr CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
+    endif()
+  endif()
+
+  include(GNUInstallDirs)
+  include(CMakePackageConfigHelpers)
+
+  set(package_config_destination ${CMAKE_INSTALL_LIBDIR}/cmake/rocksdb)
+
+  configure_package_config_file(
+    ${CMAKE_SOURCE_DIR}/cmake/RocksDBConfig.cmake.in RocksDBConfig.cmake
+    INSTALL_DESTINATION ${package_config_destination}
+  )
+
+  write_basic_package_version_file(
+    RocksDBConfigVersion.cmake
+    VERSION ${ROCKSDB_VERSION}
+    COMPATIBILITY SameMajorVersion
+  )
+
+  install(DIRECTORY include/rocksdb COMPONENT devel DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+
+  install(
+    TARGETS ${ROCKSDB_STATIC_LIB}
+    EXPORT RocksDBTargets
+    COMPONENT devel
+    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+    INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+  )
+
+  install(
+    TARGETS ${ROCKSDB_SHARED_LIB}
+    EXPORT RocksDBTargets
+    COMPONENT runtime
+    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+    INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+  )
+
+  install(
+    EXPORT RocksDBTargets
+    COMPONENT devel
+    DESTINATION ${package_config_destination}
+    NAMESPACE RocksDB::
+  )
+
+  install(
+    FILES
+    ${CMAKE_CURRENT_BINARY_DIR}/RocksDBConfig.cmake
+    ${CMAKE_CURRENT_BINARY_DIR}/RocksDBConfigVersion.cmake
+    COMPONENT devel
+    DESTINATION ${package_config_destination}
+  )
+endif()
+
+option(WITH_TESTS "build with tests" ON)
+if(WITH_TESTS)
+  set(TESTS
+        cache/cache_test.cc
+        cache/lru_cache_test.cc
+        db/column_family_test.cc
+        db/compact_files_test.cc
+        db/compaction_iterator_test.cc
+        db/compaction_job_stats_test.cc
+        db/compaction_job_test.cc
+        db/compaction_picker_test.cc
+        db/comparator_db_test.cc
+        db/corruption_test.cc
+        db/cuckoo_table_db_test.cc
+        db/db_basic_test.cc
+        db/db_block_cache_test.cc
+        db/db_bloom_filter_test.cc
+        db/db_compaction_filter_test.cc
+        db/db_compaction_test.cc
+        db/db_dynamic_level_test.cc
+        db/db_flush_test.cc
+        db/db_inplace_update_test.cc
+        db/db_io_failure_test.cc
+        db/db_iter_test.cc
+        db/db_iterator_test.cc
+        db/db_log_iter_test.cc
+        db/db_memtable_test.cc
+        db/db_merge_operator_test.cc
+        db/db_options_test.cc
+        db/db_properties_test.cc
+        db/db_range_del_test.cc
+        db/db_sst_test.cc
+        db/db_statistics_test.cc
+        db/db_table_properties_test.cc
+        db/db_tailing_iter_test.cc
+        db/db_test.cc
+        db/db_test2.cc
+        db/db_universal_compaction_test.cc
+        db/db_wal_test.cc
+        db/db_write_test.cc
+        db/dbformat_test.cc
+        db/deletefile_test.cc
+        db/external_sst_file_basic_test.cc
+        db/external_sst_file_test.cc
+        db/fault_injection_test.cc
+        db/file_indexer_test.cc
+        db/filename_test.cc
+        db/flush_job_test.cc
+        db/listener_test.cc
+        db/log_test.cc
+        db/manual_compaction_test.cc
+        db/memtable_list_test.cc
+        db/merge_helper_test.cc
+        db/merge_test.cc
+        db/options_file_test.cc
+        db/perf_context_test.cc
+        db/plain_table_db_test.cc
+        db/prefix_test.cc
+        db/repair_test.cc
+        db/table_properties_collector_test.cc
+        db/version_builder_test.cc
+        db/version_edit_test.cc
+        db/version_set_test.cc
+        db/wal_manager_test.cc
+        db/write_batch_test.cc
+        db/write_callback_test.cc
+        db/write_controller_test.cc
+        env/env_basic_test.cc
+        env/env_test.cc
+        env/mock_env_test.cc
+        memtable/inlineskiplist_test.cc
+        memtable/skiplist_test.cc
+        memtable/write_buffer_manager_test.cc
+        monitoring/histogram_test.cc
+        monitoring/iostats_context_test.cc
+        monitoring/statistics_test.cc
+        options/options_settable_test.cc
+        options/options_test.cc
+        table/block_based_filter_block_test.cc
+        table/block_test.cc
+        table/cuckoo_table_builder_test.cc
+        table/cuckoo_table_reader_test.cc
+        table/full_filter_block_test.cc
+        table/merger_test.cc
+        table/table_test.cc
+        tools/ldb_cmd_test.cc
+        tools/reduce_levels_test.cc
+        tools/sst_dump_test.cc
+        util/arena_test.cc
+        util/auto_roll_logger_test.cc
+        util/autovector_test.cc
+        util/bloom_test.cc
+        util/coding_test.cc
+        util/crc32c_test.cc
+        util/delete_scheduler_test.cc
+        util/dynamic_bloom_test.cc
+        util/event_logger_test.cc
+        util/file_reader_writer_test.cc
+        util/filelock_test.cc
+        util/hash_test.cc
+        util/heap_test.cc
+        util/rate_limiter_test.cc
+        util/slice_transform_test.cc
+        util/timer_queue_test.cc
+        util/thread_list_test.cc
+        util/thread_local_test.cc
+        utilities/backupable/backupable_db_test.cc
+        utilities/blob_db/blob_db_test.cc
+        utilities/cassandra/cassandra_functional_test.cc
+        utilities/cassandra/cassandra_format_test.cc
+        utilities/cassandra/cassandra_row_merge_test.cc
+        utilities/cassandra/cassandra_serialize_test.cc
+        utilities/checkpoint/checkpoint_test.cc
+        utilities/column_aware_encoding_test.cc
+        utilities/date_tiered/date_tiered_test.cc
+        utilities/document/document_db_test.cc
+        utilities/document/json_document_test.cc
+        utilities/geodb/geodb_test.cc
+        utilities/lua/rocks_lua_test.cc
+        utilities/memory/memory_test.cc
+        utilities/merge_operators/string_append/stringappend_test.cc
+        utilities/object_registry_test.cc
+        utilities/option_change_migration/option_change_migration_test.cc
+        utilities/options/options_util_test.cc
+        utilities/persistent_cache/hash_table_test.cc
+        utilities/persistent_cache/persistent_cache_test.cc
+        utilities/redis/redis_lists_test.cc
+        utilities/spatialdb/spatial_db_test.cc
+        utilities/simulator_cache/sim_cache_test.cc
+        utilities/table_properties_collectors/compact_on_deletion_collector_test.cc
+        utilities/transactions/optimistic_transaction_test.cc
+        utilities/transactions/transaction_test.cc
+        utilities/ttl/ttl_test.cc
+        utilities/write_batch_with_index/write_batch_with_index_test.cc
+  )
+  if(WITH_LIBRADOS)
+    list(APPEND TESTS utilities/env_librados_test.cc)
+  endif()
+
+  set(BENCHMARKS
+    cache/cache_bench.cc
+    memtable/memtablerep_bench.cc
+    tools/db_bench.cc
+    table/table_reader_bench.cc
+    utilities/column_aware_encoding_exp.cc
+    utilities/persistent_cache/hash_table_bench.cc)
+  add_library(testharness OBJECT util/testharness.cc)
+  foreach(sourcefile ${BENCHMARKS})
+    get_filename_component(exename ${sourcefile} NAME_WE)
+    add_executable(${exename}${ARTIFACT_SUFFIX} ${sourcefile}
+      $<TARGET_OBJECTS:testharness>)
+    target_link_libraries(${exename}${ARTIFACT_SUFFIX} gtest ${LIBS})
+  endforeach(sourcefile ${BENCHMARKS})
+
+  # For test util library that is build only in DEBUG mode
+  # and linked to tests. Add test only code that is not #ifdefed for Release here.
+  set(TESTUTIL_SOURCE
+      db/db_test_util.cc
+      monitoring/thread_status_updater_debug.cc
+      table/mock_table.cc
+      util/fault_injection_test_env.cc
+      utilities/cassandra/test_utils.cc
+  )
+  # test utilities are only build in debug
+  enable_testing()
+  add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
+  set(TESTUTILLIB testutillib${ARTIFACT_SUFFIX})
+  add_library(${TESTUTILLIB} STATIC ${TESTUTIL_SOURCE})
+  if(MSVC)
+    set_target_properties(${TESTUTILLIB} PROPERTIES COMPILE_FLAGS "/Fd${CMAKE_CFG_INTDIR}/testutillib${ARTIFACT_SUFFIX}.pdb")
+  endif()
+  set_target_properties(${TESTUTILLIB}
+        PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1
+        EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
+        EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
+        )
+
+  # Tests are excluded from Release builds
+  set(TEST_EXES ${TESTS})
+
+  foreach(sourcefile ${TEST_EXES})
+      get_filename_component(exename ${sourcefile} NAME_WE)
+      add_executable(${exename}${ARTIFACT_SUFFIX} ${sourcefile}
+        $<TARGET_OBJECTS:testharness>)
+      set_target_properties(${exename}${ARTIFACT_SUFFIX}
+        PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1
+        EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
+        EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
+        )
+      target_link_libraries(${exename}${ARTIFACT_SUFFIX} testutillib${ARTIFACT_SUFFIX} gtest ${LIBS})
+      if(NOT "${exename}" MATCHES "db_sanity_test")
+        add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX})
+        add_dependencies(check ${exename}${ARTIFACT_SUFFIX})
+      endif()
+  endforeach(sourcefile ${TEST_EXES})
+
+  # C executables must link to a shared object
+  set(C_TESTS db/c_test.c)
+  set(C_TEST_EXES ${C_TESTS})
+
+  foreach(sourcefile ${C_TEST_EXES})
+      string(REPLACE ".c" "" exename ${sourcefile})
+      string(REGEX REPLACE "^((.+)/)+" "" exename ${exename})
+      add_executable(${exename}${ARTIFACT_SUFFIX} ${sourcefile})
+      set_target_properties(${exename}${ARTIFACT_SUFFIX}
+        PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1
+        EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
+        EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
+        )
+      target_link_libraries(${exename}${ARTIFACT_SUFFIX} ${ROCKSDB_IMPORT_LIB} testutillib${ARTIFACT_SUFFIX})
+      add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX})
+      add_dependencies(check ${exename}${ARTIFACT_SUFFIX})
+  endforeach(sourcefile ${C_TEST_EXES})
+endif()
+
+option(WITH_TOOLS "build with tools" ON)
+if(WITH_TOOLS)
+  add_subdirectory(tools)
+endif()
diff --git a/rocksdb-5.8/build_tools/cont_integration.sh b/rocksdb-5.8/build_tools/cont_integration.sh
--- a/rocksdb-5.8/build_tools/cont_integration.sh
+++ b/rocksdb-5.8/build_tools/cont_integration.sh
@@ -1,135 +1,135 @@
-#!/usr/bin/env bash
-#
-# Copyright (c) 2016, Facebook. All rights reserved.
-#
-# Overall wrapper script for RocksDB continuous builds. The implementation is a
-# trivial pulling scheme. We loop infinitely, check if any new changes have been
-# committed, if yes then trigger a Sandcastle run, and finally go to sleep again
-# for a certain interval.
-#
-
-SRC_GIT_REPO=/data/git/rocksdb-public
-error=0
-
-function log {
-  DATE=`date +%Y-%m-%d:%H:%M:%S`
-  echo $DATE $@
-}
-
-function log_err {
-  log "ERROR: $@ Error code: $error."
-}
-
-function update_repo_status {
-  # Update the parent first.
-  pushd $SRC_GIT_REPO
-
-  # This is a fatal error. Something in the environment isn't right and we will
-  # terminate the execution.
-  error=$?
-  if [ ! $error -eq 0 ]; then
-    log_err "Where is $SRC_GIT_REPO?"
-    exit $error
-  fi
-
-  HTTPS_PROXY=fwdproxy:8080 git fetch -f
-
-  error=$?
-  if [ ! $error -eq 0 ]; then
-    log_err "git fetch -f failed."
-    popd
-    return $error
-  fi
-
-  git update-ref refs/heads/master refs/remotes/origin/master
-
-  error=$?
-  if [ ! $error -eq 0 ]; then
-    log_err "git update-ref failed."
-    popd
-    return $error
-  fi
-
-  popd
-
-  # We're back in an instance-specific directory. Get the latest changes.
-  git pull --rebase
-
-  error=$?
-  if [ ! $error -eq 0 ]; then
-    log_err "git pull --rebase failed."
-    return $error
-  fi
-}
-
-#
-# Execution starts here.
-#
-
-# Path to the determinator from the root of the RocksDB repo.
-CONTRUN_DETERMINATOR=./build_tools/RocksDBCommonHelper.php
-
-# Value of the previous commit.
-PREV_COMMIT=
-
-log "Starting to monitor for new RocksDB changes ..."
-log "Running under `pwd` as `whoami`."
-
-# Paranoia. Make sure that we're using the right branch.
-git checkout master
-
-error=$?
-if [ ! $error -eq 0 ]; then
-  log_err "This is not good. Can't checkout master. Bye-bye!"
-  exit 1
-fi
-
-# We'll run forever and let the execution environment terminate us if we'll
-# exceed whatever timeout is set for the job.
-while true;
-do
-  # Get the latest changes committed.
-  update_repo_status
-
-  error=$?
-  if [  $error -eq 0 ]; then
-    LAST_COMMIT=`git log -1 | head -1 | grep commit | awk '{ print $2; }'`
-
-    log "Last commit is '$LAST_COMMIT', previous commit is '$PREV_COMMIT'."
-
-    if [ "$PREV_COMMIT" == "$LAST_COMMIT" ]; then
-      log "There were no changes since the last time I checked. Going to sleep."
-    else
-      if [ ! -z "$LAST_COMMIT" ]; then
-        log "New code has been committed or previous commit not known. " \
-            "Will trigger the tests."
-
-        PREV_COMMIT=$LAST_COMMIT
-        log "Updated previous commit to '$PREV_COMMIT'."
-
-        #
-        # This is where we'll trigger the Sandcastle run. The values for
-        # HTTPS_APP_VALUE and HTTPS_APP_VALUE will be set in the container we're
-        # running in.
-        #
-        POST_RECEIVE_HOOK=1 php $CONTRUN_DETERMINATOR
-
-        error=$?
-        if [ $error -eq 0 ]; then
-          log "Sandcastle run successfully triggered."
-        else
-          log_err "Failed to trigger Sandcastle run."
-        fi
-      else
-        log_err "Previous commit not updated. Don't know what the last one is."
-      fi
-    fi
-  else
-    log_err "Getting latest changes failed. Will skip running tests for now."
-  fi
-
-  # Always sleep, even if errors happens while trying to determine the latest
-  # commit. This will prevent us terminating in case of transient errors.
-  log "Will go to sleep for 5 minutes."
-  sleep 5m
-done
+#!/usr/bin/env bash
+#
+# Copyright (c) 2016, Facebook. All rights reserved.
+#
+# Overall wrapper script for RocksDB continuous builds. The implementation is a
+# trivial pulling scheme. We loop infinitely, check if any new changes have been
+# committed, if yes then trigger a Sandcastle run, and finally go to sleep again
+# for a certain interval.
+#
+
+SRC_GIT_REPO=/data/git/rocksdb-public
+error=0
+
+function log {
+  DATE=`date +%Y-%m-%d:%H:%M:%S`
+  echo $DATE $@
+}
+
+function log_err {
+  log "ERROR: $@ Error code: $error."
+}
+
+function update_repo_status {
+  # Update the parent first.
+  pushd $SRC_GIT_REPO
+
+  # This is a fatal error. Something in the environment isn't right and we will
+  # terminate the execution.
+  error=$?
+  if [ ! $error -eq 0 ]; then
+    log_err "Where is $SRC_GIT_REPO?"
+    exit $error
+  fi
+
+  HTTPS_PROXY=fwdproxy:8080 git fetch -f
+
+  error=$?
+  if [ ! $error -eq 0 ]; then
+    log_err "git fetch -f failed."
+    popd
+    return $error
+  fi
+
+  git update-ref refs/heads/master refs/remotes/origin/master
+
+  error=$?
+  if [ ! $error -eq 0 ]; then
+    log_err "git update-ref failed."
+    popd
+    return $error
+  fi
+
+  popd
+
+  # We're back in an instance-specific directory. Get the latest changes.
+  git pull --rebase
+
+  error=$?
+  if [ ! $error -eq 0 ]; then
+    log_err "git pull --rebase failed."
+    return $error
+  fi
+}
+
+#
+# Execution starts here.
+#
+
+# Path to the determinator from the root of the RocksDB repo.
+CONTRUN_DETERMINATOR=./build_tools/RocksDBCommonHelper.php
+
+# Value of the previous commit.
+PREV_COMMIT=
+
+log "Starting to monitor for new RocksDB changes ..."
+log "Running under `pwd` as `whoami`."
+
+# Paranoia. Make sure that we're using the right branch.
+git checkout master
+
+error=$?
+if [ ! $error -eq 0 ]; then
+  log_err "This is not good. Can't checkout master. Bye-bye!"
+  exit 1
+fi
+
+# We'll run forever and let the execution environment terminate us if we'll
+# exceed whatever timeout is set for the job.
+while true;
+do
+  # Get the latest changes committed.
+  update_repo_status
+
+  error=$?
+  if [  $error -eq 0 ]; then
+    LAST_COMMIT=`git log -1 | head -1 | grep commit | awk '{ print $2; }'`
+
+    log "Last commit is '$LAST_COMMIT', previous commit is '$PREV_COMMIT'."
+
+    if [ "$PREV_COMMIT" == "$LAST_COMMIT" ]; then
+      log "There were no changes since the last time I checked. Going to sleep."
+    else
+      if [ ! -z "$LAST_COMMIT" ]; then
+        log "New code has been committed or previous commit not known. " \
+            "Will trigger the tests."
+
+        PREV_COMMIT=$LAST_COMMIT
+        log "Updated previous commit to '$PREV_COMMIT'."
+
+        #
+        # This is where we'll trigger the Sandcastle run. The values for
+        # HTTPS_APP_VALUE and HTTPS_APP_VALUE will be set in the container we're
+        # running in.
+        #
+        POST_RECEIVE_HOOK=1 php $CONTRUN_DETERMINATOR
+
+        error=$?
+        if [ $error -eq 0 ]; then
+          log "Sandcastle run successfully triggered."
+        else
+          log_err "Failed to trigger Sandcastle run."
+        fi
+      else
+        log_err "Previous commit not updated. Don't know what the last one is."
+      fi
+    fi
+  else
+    log_err "Getting latest changes failed. Will skip running tests for now."
+  fi
+
+  # Always sleep, even if errors happens while trying to determine the latest
+  # commit. This will prevent us terminating in case of transient errors.
+  log "Will go to sleep for 5 minutes."
+  sleep 5m
+done
diff --git a/rocksdb-5.8/build_tools/dependencies.sh b/rocksdb-5.8/build_tools/dependencies.sh
--- a/rocksdb-5.8/build_tools/dependencies.sh
+++ b/rocksdb-5.8/build_tools/dependencies.sh
@@ -1,18 +1,18 @@
-GCC_BASE=/mnt/gvfs/third-party2/gcc/2928bb3ed95bf64f5b388ee88c30dc74710c3b35/5.x/centos6-native/f4950a1
-CLANG_BASE=/mnt/gvfs/third-party2/llvm-fb/a5fea028cb7ba43498976e1f8054b0b2e790c295/stable/centos6-native/6aaf4de
-LIBGCC_BASE=/mnt/gvfs/third-party2/libgcc/7a9099f6587ee4378c0b1fa32bb8934019d30ca4/5.x/gcc-5-glibc-2.23/339d858
-GLIBC_BASE=/mnt/gvfs/third-party2/glibc/3b7c6469854dfc7832a1c3cc5b86919a84e5f865/2.23/gcc-5-glibc-2.23/ca1d1c0
-SNAPPY_BASE=/mnt/gvfs/third-party2/snappy/8c38a4c1e52b4c2cc8a9cdc31b9c947ed7dbfcb4/1.1.3/gcc-5-glibc-2.23/9bc6787
-ZLIB_BASE=/mnt/gvfs/third-party2/zlib/d7861abe6f0e27ab98c9303b95a662f0e4cdedb5/1.2.8/gcc-5-glibc-2.23/9bc6787
-BZIP2_BASE=/mnt/gvfs/third-party2/bzip2/740325875f6729f42d28deaa2147b0854f3a347e/1.0.6/gcc-5-glibc-2.23/9bc6787
-LZ4_BASE=/mnt/gvfs/third-party2/lz4/0815d59804160c96caac5f27ca004f51af893dc6/r131/gcc-5-glibc-2.23/9bc6787
-ZSTD_BASE=/mnt/gvfs/third-party2/zstd/c15a4f5f619a2930478d01e2e34dc1e0652b0873/1.1.4/gcc-5-glibc-2.23/03859b5
-GFLAGS_BASE=/mnt/gvfs/third-party2/gflags/f905a5e1032fb30c05db3d3752319857388c0c49/2.2.0/gcc-5-glibc-2.23/9bc6787
-JEMALLOC_BASE=/mnt/gvfs/third-party2/jemalloc/8d60633d822a2a55849c73db24e74a25e52b71db/master/gcc-5-glibc-2.23/1c32b4b
-NUMA_BASE=/mnt/gvfs/third-party2/numa/17c514c4d102a25ca15f4558be564eeed76f4b6a/2.0.8/gcc-5-glibc-2.23/9bc6787
-LIBUNWIND_BASE=/mnt/gvfs/third-party2/libunwind/8db74270cd6d0212ac92d69e7fc7beefe617d772/trunk/gcc-5-glibc-2.23/b1847cb
-TBB_BASE=/mnt/gvfs/third-party2/tbb/9d9a554877d0c5bef330fe818ab7178806dd316a/4.0_update2/gcc-5-glibc-2.23/9bc6787
-KERNEL_HEADERS_BASE=/mnt/gvfs/third-party2/kernel-headers/90c9734afc5579c9d1db529fa788d09f97763b85/4.0.9-36_fbk5_2933_gd092e3f/gcc-5-glibc-2.23/da39a3e
-BINUTILS_BASE=/mnt/gvfs/third-party2/binutils/9e829389ef61b92c62de8748c80169aaf25ce1f0/2.26.1/centos6-native/da39a3e
-VALGRIND_BASE=/mnt/gvfs/third-party2/valgrind/d7f4d4d86674a57668e3a96f76f0e17dd0eb8765/3.11.0/gcc-5-glibc-2.23/9bc6787
-LUA_BASE=/mnt/gvfs/third-party2/lua/61e4abf5813bbc39bc4f548757ccfcadde175a48/5.2.3/gcc-5-glibc-2.23/65372bd
+GCC_BASE=/mnt/gvfs/third-party2/gcc/2928bb3ed95bf64f5b388ee88c30dc74710c3b35/5.x/centos6-native/f4950a1
+CLANG_BASE=/mnt/gvfs/third-party2/llvm-fb/a5fea028cb7ba43498976e1f8054b0b2e790c295/stable/centos6-native/6aaf4de
+LIBGCC_BASE=/mnt/gvfs/third-party2/libgcc/7a9099f6587ee4378c0b1fa32bb8934019d30ca4/5.x/gcc-5-glibc-2.23/339d858
+GLIBC_BASE=/mnt/gvfs/third-party2/glibc/3b7c6469854dfc7832a1c3cc5b86919a84e5f865/2.23/gcc-5-glibc-2.23/ca1d1c0
+SNAPPY_BASE=/mnt/gvfs/third-party2/snappy/8c38a4c1e52b4c2cc8a9cdc31b9c947ed7dbfcb4/1.1.3/gcc-5-glibc-2.23/9bc6787
+ZLIB_BASE=/mnt/gvfs/third-party2/zlib/d7861abe6f0e27ab98c9303b95a662f0e4cdedb5/1.2.8/gcc-5-glibc-2.23/9bc6787
+BZIP2_BASE=/mnt/gvfs/third-party2/bzip2/740325875f6729f42d28deaa2147b0854f3a347e/1.0.6/gcc-5-glibc-2.23/9bc6787
+LZ4_BASE=/mnt/gvfs/third-party2/lz4/0815d59804160c96caac5f27ca004f51af893dc6/r131/gcc-5-glibc-2.23/9bc6787
+ZSTD_BASE=/mnt/gvfs/third-party2/zstd/c15a4f5f619a2930478d01e2e34dc1e0652b0873/1.1.4/gcc-5-glibc-2.23/03859b5
+GFLAGS_BASE=/mnt/gvfs/third-party2/gflags/f905a5e1032fb30c05db3d3752319857388c0c49/2.2.0/gcc-5-glibc-2.23/9bc6787
+JEMALLOC_BASE=/mnt/gvfs/third-party2/jemalloc/8d60633d822a2a55849c73db24e74a25e52b71db/master/gcc-5-glibc-2.23/1c32b4b
+NUMA_BASE=/mnt/gvfs/third-party2/numa/17c514c4d102a25ca15f4558be564eeed76f4b6a/2.0.8/gcc-5-glibc-2.23/9bc6787
+LIBUNWIND_BASE=/mnt/gvfs/third-party2/libunwind/8db74270cd6d0212ac92d69e7fc7beefe617d772/trunk/gcc-5-glibc-2.23/b1847cb
+TBB_BASE=/mnt/gvfs/third-party2/tbb/9d9a554877d0c5bef330fe818ab7178806dd316a/4.0_update2/gcc-5-glibc-2.23/9bc6787
+KERNEL_HEADERS_BASE=/mnt/gvfs/third-party2/kernel-headers/90c9734afc5579c9d1db529fa788d09f97763b85/4.0.9-36_fbk5_2933_gd092e3f/gcc-5-glibc-2.23/da39a3e
+BINUTILS_BASE=/mnt/gvfs/third-party2/binutils/9e829389ef61b92c62de8748c80169aaf25ce1f0/2.26.1/centos6-native/da39a3e
+VALGRIND_BASE=/mnt/gvfs/third-party2/valgrind/d7f4d4d86674a57668e3a96f76f0e17dd0eb8765/3.11.0/gcc-5-glibc-2.23/9bc6787
+LUA_BASE=/mnt/gvfs/third-party2/lua/61e4abf5813bbc39bc4f548757ccfcadde175a48/5.2.3/gcc-5-glibc-2.23/65372bd
diff --git a/rocksdb-5.8/build_tools/dependencies_4.8.1.sh b/rocksdb-5.8/build_tools/dependencies_4.8.1.sh
--- a/rocksdb-5.8/build_tools/dependencies_4.8.1.sh
+++ b/rocksdb-5.8/build_tools/dependencies_4.8.1.sh
@@ -1,18 +1,18 @@
-GCC_BASE=/mnt/gvfs/third-party2/gcc/cf7d14c625ce30bae1a4661c2319c5a283e4dd22/4.8.1/centos6-native/cc6c9dc
-CLANG_BASE=/mnt/gvfs/third-party2/llvm-fb/8598c375b0e94e1448182eb3df034704144a838d/stable/centos6-native/3f16ddd
-LIBGCC_BASE=/mnt/gvfs/third-party2/libgcc/d6e0a7da6faba45f5e5b1638f9edd7afc2f34e7d/4.8.1/gcc-4.8.1-glibc-2.17/8aac7fc
-GLIBC_BASE=/mnt/gvfs/third-party2/glibc/d282e6e8f3d20f4e40a516834847bdc038e07973/2.17/gcc-4.8.1-glibc-2.17/99df8fc
-SNAPPY_BASE=/mnt/gvfs/third-party2/snappy/8c38a4c1e52b4c2cc8a9cdc31b9c947ed7dbfcb4/1.1.3/gcc-4.8.1-glibc-2.17/c3f970a
-ZLIB_BASE=/mnt/gvfs/third-party2/zlib/0882df3713c7a84f15abe368dc004581f20b39d7/1.2.8/gcc-4.8.1-glibc-2.17/c3f970a
-BZIP2_BASE=/mnt/gvfs/third-party2/bzip2/740325875f6729f42d28deaa2147b0854f3a347e/1.0.6/gcc-4.8.1-glibc-2.17/c3f970a
-LZ4_BASE=/mnt/gvfs/third-party2/lz4/0e790b441e2d9acd68d51e1d2e028f88c6a79ddf/r131/gcc-4.8.1-glibc-2.17/c3f970a
-ZSTD_BASE=/mnt/gvfs/third-party2/zstd/9455f75ff7f4831dc9fda02a6a0f8c68922fad8f/1.0.0/gcc-4.8.1-glibc-2.17/c3f970a
-GFLAGS_BASE=/mnt/gvfs/third-party2/gflags/f001a51b2854957676d07306ef3abf67186b5c8b/2.1.1/gcc-4.8.1-glibc-2.17/c3f970a
-JEMALLOC_BASE=/mnt/gvfs/third-party2/jemalloc/fc8a13ca1fffa4d0765c716c5a0b49f0c107518f/master/gcc-4.8.1-glibc-2.17/8d31e51
-NUMA_BASE=/mnt/gvfs/third-party2/numa/17c514c4d102a25ca15f4558be564eeed76f4b6a/2.0.8/gcc-4.8.1-glibc-2.17/c3f970a
-LIBUNWIND_BASE=/mnt/gvfs/third-party2/libunwind/ad576de2a1ea560c4d3434304f0fc4e079bede42/trunk/gcc-4.8.1-glibc-2.17/675d945
-TBB_BASE=/mnt/gvfs/third-party2/tbb/9d9a554877d0c5bef330fe818ab7178806dd316a/4.0_update2/gcc-4.8.1-glibc-2.17/c3f970a
-KERNEL_HEADERS_BASE=/mnt/gvfs/third-party2/kernel-headers/7c111ff27e0c466235163f00f280a9d617c3d2ec/4.0.9-36_fbk5_2933_gd092e3f/gcc-4.8.1-glibc-2.17/da39a3e
-BINUTILS_BASE=/mnt/gvfs/third-party2/binutils/b7fd454c4b10c6a81015d4524ed06cdeab558490/2.26/centos6-native/da39a3e
-VALGRIND_BASE=/mnt/gvfs/third-party2/valgrind/d7f4d4d86674a57668e3a96f76f0e17dd0eb8765/3.8.1/gcc-4.8.1-glibc-2.17/c3f970a
-LUA_BASE=/mnt/gvfs/third-party2/lua/61e4abf5813bbc39bc4f548757ccfcadde175a48/5.2.3/centos6-native/730f94e
+GCC_BASE=/mnt/gvfs/third-party2/gcc/cf7d14c625ce30bae1a4661c2319c5a283e4dd22/4.8.1/centos6-native/cc6c9dc
+CLANG_BASE=/mnt/gvfs/third-party2/llvm-fb/8598c375b0e94e1448182eb3df034704144a838d/stable/centos6-native/3f16ddd
+LIBGCC_BASE=/mnt/gvfs/third-party2/libgcc/d6e0a7da6faba45f5e5b1638f9edd7afc2f34e7d/4.8.1/gcc-4.8.1-glibc-2.17/8aac7fc
+GLIBC_BASE=/mnt/gvfs/third-party2/glibc/d282e6e8f3d20f4e40a516834847bdc038e07973/2.17/gcc-4.8.1-glibc-2.17/99df8fc
+SNAPPY_BASE=/mnt/gvfs/third-party2/snappy/8c38a4c1e52b4c2cc8a9cdc31b9c947ed7dbfcb4/1.1.3/gcc-4.8.1-glibc-2.17/c3f970a
+ZLIB_BASE=/mnt/gvfs/third-party2/zlib/0882df3713c7a84f15abe368dc004581f20b39d7/1.2.8/gcc-4.8.1-glibc-2.17/c3f970a
+BZIP2_BASE=/mnt/gvfs/third-party2/bzip2/740325875f6729f42d28deaa2147b0854f3a347e/1.0.6/gcc-4.8.1-glibc-2.17/c3f970a
+LZ4_BASE=/mnt/gvfs/third-party2/lz4/0e790b441e2d9acd68d51e1d2e028f88c6a79ddf/r131/gcc-4.8.1-glibc-2.17/c3f970a
+ZSTD_BASE=/mnt/gvfs/third-party2/zstd/9455f75ff7f4831dc9fda02a6a0f8c68922fad8f/1.0.0/gcc-4.8.1-glibc-2.17/c3f970a
+GFLAGS_BASE=/mnt/gvfs/third-party2/gflags/f001a51b2854957676d07306ef3abf67186b5c8b/2.1.1/gcc-4.8.1-glibc-2.17/c3f970a
+JEMALLOC_BASE=/mnt/gvfs/third-party2/jemalloc/fc8a13ca1fffa4d0765c716c5a0b49f0c107518f/master/gcc-4.8.1-glibc-2.17/8d31e51
+NUMA_BASE=/mnt/gvfs/third-party2/numa/17c514c4d102a25ca15f4558be564eeed76f4b6a/2.0.8/gcc-4.8.1-glibc-2.17/c3f970a
+LIBUNWIND_BASE=/mnt/gvfs/third-party2/libunwind/ad576de2a1ea560c4d3434304f0fc4e079bede42/trunk/gcc-4.8.1-glibc-2.17/675d945
+TBB_BASE=/mnt/gvfs/third-party2/tbb/9d9a554877d0c5bef330fe818ab7178806dd316a/4.0_update2/gcc-4.8.1-glibc-2.17/c3f970a
+KERNEL_HEADERS_BASE=/mnt/gvfs/third-party2/kernel-headers/7c111ff27e0c466235163f00f280a9d617c3d2ec/4.0.9-36_fbk5_2933_gd092e3f/gcc-4.8.1-glibc-2.17/da39a3e
+BINUTILS_BASE=/mnt/gvfs/third-party2/binutils/b7fd454c4b10c6a81015d4524ed06cdeab558490/2.26/centos6-native/da39a3e
+VALGRIND_BASE=/mnt/gvfs/third-party2/valgrind/d7f4d4d86674a57668e3a96f76f0e17dd0eb8765/3.8.1/gcc-4.8.1-glibc-2.17/c3f970a
+LUA_BASE=/mnt/gvfs/third-party2/lua/61e4abf5813bbc39bc4f548757ccfcadde175a48/5.2.3/centos6-native/730f94e
diff --git a/rocksdb-5.8/build_tools/dockerbuild.sh b/rocksdb-5.8/build_tools/dockerbuild.sh
--- a/rocksdb-5.8/build_tools/dockerbuild.sh
+++ b/rocksdb-5.8/build_tools/dockerbuild.sh
@@ -1,2 +1,2 @@
-#!/usr/bin/env bash
-docker run -v $PWD:/rocks -w /rocks buildpack-deps make
+#!/usr/bin/env bash
+docker run -v $PWD:/rocks -w /rocks buildpack-deps make
diff --git a/rocksdb-5.8/build_tools/fb_compile_mongo.sh b/rocksdb-5.8/build_tools/fb_compile_mongo.sh
--- a/rocksdb-5.8/build_tools/fb_compile_mongo.sh
+++ b/rocksdb-5.8/build_tools/fb_compile_mongo.sh
@@ -1,55 +1,55 @@
-#!/bin/sh
-
-# fail early
-set -e
-
-if test -z $ROCKSDB_PATH; then
-  ROCKSDB_PATH=~/rocksdb
-fi
-source $ROCKSDB_PATH/build_tools/fbcode_config4.8.1.sh
-
-EXTRA_LDFLAGS=""
-
-if test -z $ALLOC; then
-  # default
-  ALLOC=tcmalloc
-elif [[ $ALLOC == "jemalloc" ]]; then
-  ALLOC=system
-  EXTRA_LDFLAGS+=" -Wl,--whole-archive $JEMALLOC_LIB -Wl,--no-whole-archive"
-fi
-
-# we need to force mongo to use static library, not shared
-STATIC_LIB_DEP_DIR='build/static_library_dependencies'
-test -d $STATIC_LIB_DEP_DIR || mkdir $STATIC_LIB_DEP_DIR
-test -h $STATIC_LIB_DEP_DIR/`basename $SNAPPY_LIBS` || ln -s $SNAPPY_LIBS $STATIC_LIB_DEP_DIR
-test -h $STATIC_LIB_DEP_DIR/`basename $LZ4_LIBS` || ln -s $LZ4_LIBS $STATIC_LIB_DEP_DIR
-
-EXTRA_LDFLAGS+=" -L $STATIC_LIB_DEP_DIR"
-
-set -x
-
-EXTRA_CMD=""
-if ! test -e version.json; then
-  # this is Mongo 3.0
-  EXTRA_CMD="--rocksdb \
-    --variant-dir=linux2/norm
-    --cxx=${CXX} \
-    --cc=${CC} \
-    --use-system-zlib"  # add this line back to normal code path
-                        # when https://jira.mongodb.org/browse/SERVER-19123 is resolved
-fi
-
-scons \
-  LINKFLAGS="$EXTRA_LDFLAGS $EXEC_LDFLAGS $PLATFORM_LDFLAGS" \
-  CCFLAGS="$CXXFLAGS -L $STATIC_LIB_DEP_DIR" \
-  LIBS="lz4 gcc stdc++" \
-  LIBPATH="$ROCKSDB_PATH" \
-  CPPPATH="$ROCKSDB_PATH/include" \
-  -j32 \
-  --allocator=$ALLOC \
-  --nostrip \
-  --opt=on \
-  --disable-minimum-compiler-version-enforcement \
-  --use-system-snappy \
-  --disable-warnings-as-errors \
-  $EXTRA_CMD $*
+#!/bin/sh
+
+# fail early
+set -e
+
+if test -z $ROCKSDB_PATH; then
+  ROCKSDB_PATH=~/rocksdb
+fi
+source $ROCKSDB_PATH/build_tools/fbcode_config4.8.1.sh
+
+EXTRA_LDFLAGS=""
+
+if test -z $ALLOC; then
+  # default
+  ALLOC=tcmalloc
+elif [[ $ALLOC == "jemalloc" ]]; then
+  ALLOC=system
+  EXTRA_LDFLAGS+=" -Wl,--whole-archive $JEMALLOC_LIB -Wl,--no-whole-archive"
+fi
+
+# we need to force mongo to use static library, not shared
+STATIC_LIB_DEP_DIR='build/static_library_dependencies'
+test -d $STATIC_LIB_DEP_DIR || mkdir $STATIC_LIB_DEP_DIR
+test -h $STATIC_LIB_DEP_DIR/`basename $SNAPPY_LIBS` || ln -s $SNAPPY_LIBS $STATIC_LIB_DEP_DIR
+test -h $STATIC_LIB_DEP_DIR/`basename $LZ4_LIBS` || ln -s $LZ4_LIBS $STATIC_LIB_DEP_DIR
+
+EXTRA_LDFLAGS+=" -L $STATIC_LIB_DEP_DIR"
+
+set -x
+
+EXTRA_CMD=""
+if ! test -e version.json; then
+  # this is Mongo 3.0
+  EXTRA_CMD="--rocksdb \
+    --variant-dir=linux2/norm
+    --cxx=${CXX} \
+    --cc=${CC} \
+    --use-system-zlib"  # add this line back to normal code path
+                        # when https://jira.mongodb.org/browse/SERVER-19123 is resolved
+fi
+
+scons \
+  LINKFLAGS="$EXTRA_LDFLAGS $EXEC_LDFLAGS $PLATFORM_LDFLAGS" \
+  CCFLAGS="$CXXFLAGS -L $STATIC_LIB_DEP_DIR" \
+  LIBS="lz4 gcc stdc++" \
+  LIBPATH="$ROCKSDB_PATH" \
+  CPPPATH="$ROCKSDB_PATH/include" \
+  -j32 \
+  --allocator=$ALLOC \
+  --nostrip \
+  --opt=on \
+  --disable-minimum-compiler-version-enforcement \
+  --use-system-snappy \
+  --disable-warnings-as-errors \
+  $EXTRA_CMD $*
diff --git a/rocksdb-5.8/build_tools/fbcode_config.sh b/rocksdb-5.8/build_tools/fbcode_config.sh
--- a/rocksdb-5.8/build_tools/fbcode_config.sh
+++ b/rocksdb-5.8/build_tools/fbcode_config.sh
@@ -1,156 +1,156 @@
-#!/bin/sh
-#
-# Set environment variables so that we can compile rocksdb using
-# 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
-
-
-BASEDIR=`dirname $BASH_SOURCE`
-source "$BASEDIR/dependencies.sh"
-
-CFLAGS=""
-
-# libgcc
-LIBGCC_INCLUDE="$LIBGCC_BASE/include"
-LIBGCC_LIBS=" -L $LIBGCC_BASE/lib"
-
-# glibc
-GLIBC_INCLUDE="$GLIBC_BASE/include"
-GLIBC_LIBS=" -L $GLIBC_BASE/lib"
-
-# 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 $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 $JEMALLOC_BASE/include/"
-JEMALLOC_LIB=" $JEMALLOC_BASE/lib/libjemalloc.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="$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=1
-
-BINUTILS="$BINUTILS_BASE/bin"
-AR="$BINUTILS/ar"
-
-DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP_INCLUDE $LZ4_INCLUDE $ZSTD_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE $TBB_INCLUDE"
-
-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"
-  CFLAGS+=" -isystem $GLIBC_INCLUDE"
-  CFLAGS+=" -isystem $LIBGCC_INCLUDE"
-  JEMALLOC=1
-else
-  # clang
-  CLANG_INCLUDE="$CLANG_LIB/clang/stable/include"
-  CC="$CLANG_BIN/clang"
-  CXX="$CLANG_BIN/clang++"
-
-  KERNEL_HEADERS_INCLUDE="$KERNEL_HEADERS_BASE/include"
-
-  CFLAGS+=" -B$BINUTILS/gold -nostdinc -nostdlib"
-  CFLAGS+=" -isystem $LIBGCC_BASE/include/c++/5.x "
-  CFLAGS+=" -isystem $LIBGCC_BASE/include/c++/5.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_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 $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS"
-EXEC_LDFLAGS+=" -B$BINUTILS/gold"
-EXEC_LDFLAGS+=" -Wl,--dynamic-linker,/usr/local/fbcode/gcc-5-glibc-2.23/lib/ld.so"
-EXEC_LDFLAGS+=" $LIBUNWIND"
-EXEC_LDFLAGS+=" -Wl,-rpath=/usr/local/fbcode/gcc-5-glibc-2.23/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 $ZSTD_LIBS $GFLAGS_LIBS $TBB_LIBS"
-
-VALGRIND_VER="$VALGRIND_BASE/bin/"
-
-LUA_PATH="$LUA_BASE"
-
-if test -z $PIC_BUILD; then
-  LUA_LIB=" $LUA_PATH/lib/liblua.a"
-else
-  LUA_LIB=" $LUA_PATH/lib/liblua_pic.a"
-fi
-
-export CC CXX AR CFLAGS CXXFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED VALGRIND_VER JEMALLOC_LIB JEMALLOC_INCLUDE CLANG_ANALYZER CLANG_SCAN_BUILD LUA_PATH LUA_LIB
+#!/bin/sh
+#
+# Set environment variables so that we can compile rocksdb using
+# 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
+
+
+BASEDIR=`dirname $BASH_SOURCE`
+source "$BASEDIR/dependencies.sh"
+
+CFLAGS=""
+
+# libgcc
+LIBGCC_INCLUDE="$LIBGCC_BASE/include"
+LIBGCC_LIBS=" -L $LIBGCC_BASE/lib"
+
+# glibc
+GLIBC_INCLUDE="$GLIBC_BASE/include"
+GLIBC_LIBS=" -L $GLIBC_BASE/lib"
+
+# 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 $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 $JEMALLOC_BASE/include/"
+JEMALLOC_LIB=" $JEMALLOC_BASE/lib/libjemalloc.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="$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=1
+
+BINUTILS="$BINUTILS_BASE/bin"
+AR="$BINUTILS/ar"
+
+DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP_INCLUDE $LZ4_INCLUDE $ZSTD_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE $TBB_INCLUDE"
+
+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"
+  CFLAGS+=" -isystem $GLIBC_INCLUDE"
+  CFLAGS+=" -isystem $LIBGCC_INCLUDE"
+  JEMALLOC=1
+else
+  # clang
+  CLANG_INCLUDE="$CLANG_LIB/clang/stable/include"
+  CC="$CLANG_BIN/clang"
+  CXX="$CLANG_BIN/clang++"
+
+  KERNEL_HEADERS_INCLUDE="$KERNEL_HEADERS_BASE/include"
+
+  CFLAGS+=" -B$BINUTILS/gold -nostdinc -nostdlib"
+  CFLAGS+=" -isystem $LIBGCC_BASE/include/c++/5.x "
+  CFLAGS+=" -isystem $LIBGCC_BASE/include/c++/5.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_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 $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS"
+EXEC_LDFLAGS+=" -B$BINUTILS/gold"
+EXEC_LDFLAGS+=" -Wl,--dynamic-linker,/usr/local/fbcode/gcc-5-glibc-2.23/lib/ld.so"
+EXEC_LDFLAGS+=" $LIBUNWIND"
+EXEC_LDFLAGS+=" -Wl,-rpath=/usr/local/fbcode/gcc-5-glibc-2.23/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 $ZSTD_LIBS $GFLAGS_LIBS $TBB_LIBS"
+
+VALGRIND_VER="$VALGRIND_BASE/bin/"
+
+LUA_PATH="$LUA_BASE"
+
+if test -z $PIC_BUILD; then
+  LUA_LIB=" $LUA_PATH/lib/liblua.a"
+else
+  LUA_LIB=" $LUA_PATH/lib/liblua_pic.a"
+fi
+
+export CC CXX AR CFLAGS CXXFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED VALGRIND_VER JEMALLOC_LIB JEMALLOC_INCLUDE CLANG_ANALYZER CLANG_SCAN_BUILD LUA_PATH LUA_LIB
diff --git a/rocksdb-5.8/build_tools/fbcode_config4.8.1.sh b/rocksdb-5.8/build_tools/fbcode_config4.8.1.sh
--- a/rocksdb-5.8/build_tools/fbcode_config4.8.1.sh
+++ b/rocksdb-5.8/build_tools/fbcode_config4.8.1.sh
@@ -1,115 +1,115 @@
-#!/bin/sh
-#
-# Set environment variables so that we can compile rocksdb using
-# fbcode settings.  It uses the latest g++ compiler and also
-# uses jemalloc
-
-BASEDIR=`dirname $BASH_SOURCE`
-source "$BASEDIR/dependencies_4.8.1.sh"
-
-# location of libgcc
-LIBGCC_INCLUDE="$LIBGCC_BASE/include"
-LIBGCC_LIBS=" -L $LIBGCC_BASE/lib"
-
-# location of glibc
-GLIBC_INCLUDE="$GLIBC_BASE/include"
-GLIBC_LIBS=" -L $GLIBC_BASE/lib"
-
-# location of snappy headers and libraries
-SNAPPY_INCLUDE=" -I $SNAPPY_BASE/include"
-SNAPPY_LIBS=" $SNAPPY_BASE/lib/libsnappy.a"
-
-# location of zlib headers and libraries
-ZLIB_INCLUDE=" -I $ZLIB_BASE/include"
-ZLIB_LIBS=" $ZLIB_BASE/lib/libz.a"
-
-# location of bzip headers and libraries
-BZIP2_INCLUDE=" -I $BZIP2_BASE/include/"
-BZIP2_LIBS=" $BZIP2_BASE/lib/libbz2.a"
-
-LZ4_INCLUDE=" -I $LZ4_BASE/include"
-LZ4_LIBS=" $LZ4_BASE/lib/liblz4.a"
-
-ZSTD_INCLUDE=" -I $ZSTD_BASE/include"
-ZSTD_LIBS=" $ZSTD_BASE/lib/libzstd.a"
-
-# location of gflags headers and libraries
-GFLAGS_INCLUDE=" -I $GFLAGS_BASE/include/"
-GFLAGS_LIBS=" $GFLAGS_BASE/lib/libgflags.a"
-
-# location of jemalloc
-JEMALLOC_INCLUDE=" -I $JEMALLOC_BASE/include"
-JEMALLOC_LIB="$JEMALLOC_BASE/lib/libjemalloc.a"
-
-# location of numa
-NUMA_INCLUDE=" -I $NUMA_BASE/include/"
-NUMA_LIB=" $NUMA_BASE/lib/libnuma.a"
-
-# location of libunwind
-LIBUNWIND="$LIBUNWIND_BASE/lib/libunwind.a"
-
-# location of tbb
-TBB_INCLUDE=" -isystem $TBB_BASE/include/"
-TBB_LIBS="$TBB_BASE/lib/libtbb.a"
-
-# use Intel SSE support for checksum calculations
-export USE_SSE=1
-
-BINUTILS="$BINUTILS_BASE/bin"
-AR="$BINUTILS/ar"
-
-DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP2_INCLUDE $LZ4_INCLUDE $ZSTD_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE $TBB_INCLUDE"
-
-STDLIBS="-L $GCC_BASE/lib64"
-
-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+=" -isystem $LIBGCC_INCLUDE"
-  JEMALLOC=1
-else
-  # clang
-  CLANG_BIN="$CLANG_BASE/bin"
-  CLANG_LIB="$CLANG_BASE/lib"
-  CLANG_INCLUDE="$CLANG_LIB/clang/*/include"
-  CC="$CLANG_BIN/clang"
-  CXX="$CLANG_BIN/clang++"
-
-  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+=" -isystem $GLIBC_INCLUDE"
-  CFLAGS+=" -isystem $LIBGCC_INCLUDE"
-  CFLAGS+=" -isystem $CLANG_INCLUDE"
-  CFLAGS+=" -isystem $KERNEL_HEADERS_INCLUDE/linux "
-  CFLAGS+=" -isystem $KERNEL_HEADERS_INCLUDE "
-  CXXFLAGS="-nostdinc++"
-fi
-
-CFLAGS+=" $DEPS_INCLUDE"
-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"
-CFLAGS+=" -DSNAPPY -DGFLAGS=google -DZLIB -DBZIP2 -DLZ4 -DZSTD -DNUMA -DTBB"
-CXXFLAGS+=" $CFLAGS"
-
-EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP2_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS"
-EXEC_LDFLAGS+=" -Wl,--dynamic-linker,/usr/local/fbcode/gcc-4.8.1-glibc-2.17/lib/ld.so"
-EXEC_LDFLAGS+=" $LIBUNWIND"
-EXEC_LDFLAGS+=" -Wl,-rpath=/usr/local/fbcode/gcc-4.8.1-glibc-2.17/lib"
-# required by libtbb
-EXEC_LDFLAGS+=" -ldl"
-
-PLATFORM_LDFLAGS="$LIBGCC_LIBS $GLIBC_LIBS $STDLIBS -lgcc -lstdc++"
-
-EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $ZLIB_LIBS $BZIP2_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS"
-
-VALGRIND_VER="$VALGRIND_BASE/bin/"
-
-LUA_PATH="$LUA_BASE"
-
-export CC CXX AR CFLAGS CXXFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED VALGRIND_VER JEMALLOC_LIB JEMALLOC_INCLUDE LUA_PATH
+#!/bin/sh
+#
+# Set environment variables so that we can compile rocksdb using
+# fbcode settings.  It uses the latest g++ compiler and also
+# uses jemalloc
+
+BASEDIR=`dirname $BASH_SOURCE`
+source "$BASEDIR/dependencies_4.8.1.sh"
+
+# location of libgcc
+LIBGCC_INCLUDE="$LIBGCC_BASE/include"
+LIBGCC_LIBS=" -L $LIBGCC_BASE/lib"
+
+# location of glibc
+GLIBC_INCLUDE="$GLIBC_BASE/include"
+GLIBC_LIBS=" -L $GLIBC_BASE/lib"
+
+# location of snappy headers and libraries
+SNAPPY_INCLUDE=" -I $SNAPPY_BASE/include"
+SNAPPY_LIBS=" $SNAPPY_BASE/lib/libsnappy.a"
+
+# location of zlib headers and libraries
+ZLIB_INCLUDE=" -I $ZLIB_BASE/include"
+ZLIB_LIBS=" $ZLIB_BASE/lib/libz.a"
+
+# location of bzip headers and libraries
+BZIP2_INCLUDE=" -I $BZIP2_BASE/include/"
+BZIP2_LIBS=" $BZIP2_BASE/lib/libbz2.a"
+
+LZ4_INCLUDE=" -I $LZ4_BASE/include"
+LZ4_LIBS=" $LZ4_BASE/lib/liblz4.a"
+
+ZSTD_INCLUDE=" -I $ZSTD_BASE/include"
+ZSTD_LIBS=" $ZSTD_BASE/lib/libzstd.a"
+
+# location of gflags headers and libraries
+GFLAGS_INCLUDE=" -I $GFLAGS_BASE/include/"
+GFLAGS_LIBS=" $GFLAGS_BASE/lib/libgflags.a"
+
+# location of jemalloc
+JEMALLOC_INCLUDE=" -I $JEMALLOC_BASE/include"
+JEMALLOC_LIB="$JEMALLOC_BASE/lib/libjemalloc.a"
+
+# location of numa
+NUMA_INCLUDE=" -I $NUMA_BASE/include/"
+NUMA_LIB=" $NUMA_BASE/lib/libnuma.a"
+
+# location of libunwind
+LIBUNWIND="$LIBUNWIND_BASE/lib/libunwind.a"
+
+# location of tbb
+TBB_INCLUDE=" -isystem $TBB_BASE/include/"
+TBB_LIBS="$TBB_BASE/lib/libtbb.a"
+
+# use Intel SSE support for checksum calculations
+export USE_SSE=1
+
+BINUTILS="$BINUTILS_BASE/bin"
+AR="$BINUTILS/ar"
+
+DEPS_INCLUDE="$SNAPPY_INCLUDE $ZLIB_INCLUDE $BZIP2_INCLUDE $LZ4_INCLUDE $ZSTD_INCLUDE $GFLAGS_INCLUDE $NUMA_INCLUDE $TBB_INCLUDE"
+
+STDLIBS="-L $GCC_BASE/lib64"
+
+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+=" -isystem $LIBGCC_INCLUDE"
+  JEMALLOC=1
+else
+  # clang
+  CLANG_BIN="$CLANG_BASE/bin"
+  CLANG_LIB="$CLANG_BASE/lib"
+  CLANG_INCLUDE="$CLANG_LIB/clang/*/include"
+  CC="$CLANG_BIN/clang"
+  CXX="$CLANG_BIN/clang++"
+
+  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+=" -isystem $GLIBC_INCLUDE"
+  CFLAGS+=" -isystem $LIBGCC_INCLUDE"
+  CFLAGS+=" -isystem $CLANG_INCLUDE"
+  CFLAGS+=" -isystem $KERNEL_HEADERS_INCLUDE/linux "
+  CFLAGS+=" -isystem $KERNEL_HEADERS_INCLUDE "
+  CXXFLAGS="-nostdinc++"
+fi
+
+CFLAGS+=" $DEPS_INCLUDE"
+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"
+CFLAGS+=" -DSNAPPY -DGFLAGS=google -DZLIB -DBZIP2 -DLZ4 -DZSTD -DNUMA -DTBB"
+CXXFLAGS+=" $CFLAGS"
+
+EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP2_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS"
+EXEC_LDFLAGS+=" -Wl,--dynamic-linker,/usr/local/fbcode/gcc-4.8.1-glibc-2.17/lib/ld.so"
+EXEC_LDFLAGS+=" $LIBUNWIND"
+EXEC_LDFLAGS+=" -Wl,-rpath=/usr/local/fbcode/gcc-4.8.1-glibc-2.17/lib"
+# required by libtbb
+EXEC_LDFLAGS+=" -ldl"
+
+PLATFORM_LDFLAGS="$LIBGCC_LIBS $GLIBC_LIBS $STDLIBS -lgcc -lstdc++"
+
+EXEC_LDFLAGS_SHARED="$SNAPPY_LIBS $ZLIB_LIBS $BZIP2_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS"
+
+VALGRIND_VER="$VALGRIND_BASE/bin/"
+
+LUA_PATH="$LUA_BASE"
+
+export CC CXX AR CFLAGS CXXFLAGS EXEC_LDFLAGS EXEC_LDFLAGS_SHARED VALGRIND_VER JEMALLOC_LIB JEMALLOC_INCLUDE LUA_PATH
diff --git a/rocksdb-5.8/build_tools/format-diff.sh b/rocksdb-5.8/build_tools/format-diff.sh
--- a/rocksdb-5.8/build_tools/format-diff.sh
+++ b/rocksdb-5.8/build_tools/format-diff.sh
@@ -1,122 +1,122 @@
-#!/usr/bin/env bash
-# If clang_format_diff.py command is not specfied, we assume we are able to
-# access directly without any path.
-if [ -z $CLANG_FORMAT_DIFF ]
-then
-CLANG_FORMAT_DIFF="clang-format-diff.py"
-fi
-
-# Check clang-format-diff.py
-if ! which $CLANG_FORMAT_DIFF &> /dev/null
-then
-  echo "You didn't have clang-format-diff.py and/or clang-format available in your computer!"
-  echo "You can download clang-format-diff.py by running: "
-  echo "    curl --location http://goo.gl/iUW1u2 -o ${CLANG_FORMAT_DIFF}"
-  echo "You can download clang-format by running: "
-  echo "    brew install clang-format"
-  echo "Then, move both files (i.e. ${CLANG_FORMAT_DIFF} and clang-format) to some directory within PATH=${PATH}"
-  exit 128
-fi
-
-# Check argparse, a library that clang-format-diff.py requires.
-python 2>/dev/null << EOF
-import argparse
-EOF
-
-if [ "$?" != 0 ]
-then
-  echo "To run clang-format-diff.py, we'll need the library "argparse" to be"
-  echo "installed. You can try either of the follow ways to install it:"
-  echo "  1. Manually download argparse: https://pypi.python.org/pypi/argparse"
-  echo "  2. easy_install argparse (if you have easy_install)"
-  echo "  3. pip install argparse (if you have pip)"
-  exit 129
-fi
-
-# TODO(kailiu) following work is not complete since we still need to figure
-# out how to add the modified files done pre-commit hook to git's commit index.
-#
-# Check if this script has already been added to pre-commit hook.
-# Will suggest user to add this script to pre-commit hook if their pre-commit
-# is empty.
-# PRE_COMMIT_SCRIPT_PATH="`git rev-parse --show-toplevel`/.git/hooks/pre-commit"
-# if ! ls $PRE_COMMIT_SCRIPT_PATH &> /dev/null
-# then
-#   echo "Would you like to add this script to pre-commit hook, which will do "
-#   echo -n "the format check for all the affected lines before you check in (y/n):"
-#   read add_to_hook
-#   if [ "$add_to_hook" == "y" ]
-#   then
-#     ln -s `git rev-parse --show-toplevel`/build_tools/format-diff.sh $PRE_COMMIT_SCRIPT_PATH
-#   fi
-# fi
-set -e
-
-uncommitted_code=`git diff HEAD`
-LAST_MASTER=`git merge-base master HEAD`
-
-# If there's no uncommitted changes, we assume user are doing post-commit
-# format check, in which case we'll check the modified lines since last commit
-# from master. Otherwise, we'll check format of the uncommitted code only.
-if [ -z "$uncommitted_code" ]
-then
-  # Check the format of last commit
-  diffs=$(git diff -U0 $LAST_MASTER^ | $CLANG_FORMAT_DIFF -p 1)
-else
-  # Check the format of uncommitted lines,
-  diffs=$(git diff -U0 HEAD | $CLANG_FORMAT_DIFF -p 1)
-fi
-
-if [ -z "$diffs" ]
-then
-  echo "Nothing needs to be reformatted!"
-  exit 0
-fi
-
-# Highlight the insertion/deletion from the clang-format-diff.py's output
-COLOR_END="\033[0m"
-COLOR_RED="\033[0;31m" 
-COLOR_GREEN="\033[0;32m" 
-
-echo -e "Detect lines that doesn't follow the format rules:\r"
-# Add the color to the diff. lines added will be green; lines removed will be red.
-echo "$diffs" | 
-  sed -e "s/\(^-.*$\)/`echo -e \"$COLOR_RED\1$COLOR_END\"`/" |
-  sed -e "s/\(^+.*$\)/`echo -e \"$COLOR_GREEN\1$COLOR_END\"`/"
-
-if [[ "$OPT" == *"-DTRAVIS"* ]]
-then
-  exit 1
-fi
-
-echo -e "Would you like to fix the format automatically (y/n): \c"
-
-# Make sure under any mode, we can read user input.
-exec < /dev/tty
-read to_fix
-
-if [ "$to_fix" != "y" ]
-then
-  exit 1
-fi
-
-# Do in-place format adjustment.
-if [ -z "$uncommitted_code" ]
-then
-  git diff -U0 $LAST_MASTER^ | $CLANG_FORMAT_DIFF -i -p 1
-else
-  git diff -U0 HEAD^ | $CLANG_FORMAT_DIFF -i -p 1
-fi
-echo "Files reformatted!"
-
-# Amend to last commit if user do the post-commit format check
-if [ -z "$uncommitted_code" ]; then
-  echo -e "Would you like to amend the changes to last commit (`git log HEAD --oneline | head -1`)? (y/n): \c"
-  read to_amend
-
-  if [ "$to_amend" == "y" ]
-  then
-    git commit -a --amend --reuse-message HEAD
-    echo "Amended to last commit"
-  fi
-fi
+#!/usr/bin/env bash
+# If clang_format_diff.py command is not specfied, we assume we are able to
+# access directly without any path.
+if [ -z $CLANG_FORMAT_DIFF ]
+then
+CLANG_FORMAT_DIFF="clang-format-diff.py"
+fi
+
+# Check clang-format-diff.py
+if ! which $CLANG_FORMAT_DIFF &> /dev/null
+then
+  echo "You didn't have clang-format-diff.py and/or clang-format available in your computer!"
+  echo "You can download clang-format-diff.py by running: "
+  echo "    curl --location http://goo.gl/iUW1u2 -o ${CLANG_FORMAT_DIFF}"
+  echo "You can download clang-format by running: "
+  echo "    brew install clang-format"
+  echo "Then, move both files (i.e. ${CLANG_FORMAT_DIFF} and clang-format) to some directory within PATH=${PATH}"
+  exit 128
+fi
+
+# Check argparse, a library that clang-format-diff.py requires.
+python 2>/dev/null << EOF
+import argparse
+EOF
+
+if [ "$?" != 0 ]
+then
+  echo "To run clang-format-diff.py, we'll need the library "argparse" to be"
+  echo "installed. You can try either of the follow ways to install it:"
+  echo "  1. Manually download argparse: https://pypi.python.org/pypi/argparse"
+  echo "  2. easy_install argparse (if you have easy_install)"
+  echo "  3. pip install argparse (if you have pip)"
+  exit 129
+fi
+
+# TODO(kailiu) following work is not complete since we still need to figure
+# out how to add the modified files done pre-commit hook to git's commit index.
+#
+# Check if this script has already been added to pre-commit hook.
+# Will suggest user to add this script to pre-commit hook if their pre-commit
+# is empty.
+# PRE_COMMIT_SCRIPT_PATH="`git rev-parse --show-toplevel`/.git/hooks/pre-commit"
+# if ! ls $PRE_COMMIT_SCRIPT_PATH &> /dev/null
+# then
+#   echo "Would you like to add this script to pre-commit hook, which will do "
+#   echo -n "the format check for all the affected lines before you check in (y/n):"
+#   read add_to_hook
+#   if [ "$add_to_hook" == "y" ]
+#   then
+#     ln -s `git rev-parse --show-toplevel`/build_tools/format-diff.sh $PRE_COMMIT_SCRIPT_PATH
+#   fi
+# fi
+set -e
+
+uncommitted_code=`git diff HEAD`
+LAST_MASTER=`git merge-base master HEAD`
+
+# If there's no uncommitted changes, we assume user are doing post-commit
+# format check, in which case we'll check the modified lines since last commit
+# from master. Otherwise, we'll check format of the uncommitted code only.
+if [ -z "$uncommitted_code" ]
+then
+  # Check the format of last commit
+  diffs=$(git diff -U0 $LAST_MASTER^ | $CLANG_FORMAT_DIFF -p 1)
+else
+  # Check the format of uncommitted lines,
+  diffs=$(git diff -U0 HEAD | $CLANG_FORMAT_DIFF -p 1)
+fi
+
+if [ -z "$diffs" ]
+then
+  echo "Nothing needs to be reformatted!"
+  exit 0
+fi
+
+# Highlight the insertion/deletion from the clang-format-diff.py's output
+COLOR_END="\033[0m"
+COLOR_RED="\033[0;31m" 
+COLOR_GREEN="\033[0;32m" 
+
+echo -e "Detect lines that doesn't follow the format rules:\r"
+# Add the color to the diff. lines added will be green; lines removed will be red.
+echo "$diffs" | 
+  sed -e "s/\(^-.*$\)/`echo -e \"$COLOR_RED\1$COLOR_END\"`/" |
+  sed -e "s/\(^+.*$\)/`echo -e \"$COLOR_GREEN\1$COLOR_END\"`/"
+
+if [[ "$OPT" == *"-DTRAVIS"* ]]
+then
+  exit 1
+fi
+
+echo -e "Would you like to fix the format automatically (y/n): \c"
+
+# Make sure under any mode, we can read user input.
+exec < /dev/tty
+read to_fix
+
+if [ "$to_fix" != "y" ]
+then
+  exit 1
+fi
+
+# Do in-place format adjustment.
+if [ -z "$uncommitted_code" ]
+then
+  git diff -U0 $LAST_MASTER^ | $CLANG_FORMAT_DIFF -i -p 1
+else
+  git diff -U0 HEAD^ | $CLANG_FORMAT_DIFF -i -p 1
+fi
+echo "Files reformatted!"
+
+# Amend to last commit if user do the post-commit format check
+if [ -z "$uncommitted_code" ]; then
+  echo -e "Would you like to amend the changes to last commit (`git log HEAD --oneline | head -1`)? (y/n): \c"
+  read to_amend
+
+  if [ "$to_amend" == "y" ]
+  then
+    git commit -a --amend --reuse-message HEAD
+    echo "Amended to last commit"
+  fi
+fi
diff --git a/rocksdb-5.8/build_tools/make_package.sh b/rocksdb-5.8/build_tools/make_package.sh
--- a/rocksdb-5.8/build_tools/make_package.sh
+++ b/rocksdb-5.8/build_tools/make_package.sh
@@ -1,128 +1,128 @@
-#/usr/bin/env bash
-
-set -e
-
-function log() {
-  echo "[+] $1"
-}
-
-function fatal() {
-  echo "[!] $1"
-  exit 1
-}
-
-function platform() {
-  local  __resultvar=$1
-  if [[ -f "/etc/yum.conf" ]]; then
-    eval $__resultvar="centos"
-  elif [[ -f "/etc/dpkg/dpkg.cfg" ]]; then
-    eval $__resultvar="ubuntu"
-  else
-    fatal "Unknwon operating system"
-  fi
-}
-platform OS
-
-function package() {
-  if [[ $OS = "ubuntu" ]]; then
-    if dpkg --get-selections | grep --quiet $1; then
-      log "$1 is already installed. skipping."
-    else
-      apt-get install $@ -y
-    fi
-  elif [[ $OS = "centos" ]]; then
-    if rpm -qa | grep --quiet $1; then
-      log "$1 is already installed. skipping."
-    else
-      yum install $@ -y
-    fi
-  fi
-}
-
-function detect_fpm_output() {
-  if [[ $OS = "ubuntu" ]]; then
-    export FPM_OUTPUT=deb
-  elif [[ $OS = "centos" ]]; then
-    export FPM_OUTPUT=rpm
-  fi
-}
-detect_fpm_output
-
-function gem_install() {
-  if gem list | grep --quiet $1; then
-    log "$1 is already installed. skipping."
-  else
-    gem install $@
-  fi
-}
-
-function main() {
-  if [[ $# -ne 1 ]]; then
-    fatal "Usage: $0 <rocksdb_version>"
-  else
-    log "using rocksdb version: $1"
-  fi
-
-  if [[ -d /vagrant ]]; then
-    if [[ $OS = "ubuntu" ]]; then
-      package g++-4.8
-      export CXX=g++-4.8
-
-      # the deb would depend on libgflags2, but the static lib is the only thing
-      # installed by make install
-      package libgflags-dev
-
-      package ruby-all-dev
-    elif [[ $OS = "centos" ]]; then
-      pushd /etc/yum.repos.d
-      if [[ ! -f /etc/yum.repos.d/devtools-1.1.repo ]]; then
-        wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo
-      fi
-      package devtoolset-1.1-gcc --enablerepo=testing-1.1-devtools-6
-      package devtoolset-1.1-gcc-c++ --enablerepo=testing-1.1-devtools-6
-      export CC=/opt/centos/devtoolset-1.1/root/usr/bin/gcc
-      export CPP=/opt/centos/devtoolset-1.1/root/usr/bin/cpp
-      export CXX=/opt/centos/devtoolset-1.1/root/usr/bin/c++
-      export PATH=$PATH:/opt/centos/devtoolset-1.1/root/usr/bin
-      popd
-      if ! rpm -qa | grep --quiet gflags; then
-        rpm -i https://github.com/schuhschuh/gflags/releases/download/v2.1.0/gflags-devel-2.1.0-1.amd64.rpm
-      fi
-
-      package ruby
-      package ruby-devel
-      package rubygems
-      package rpm-build
-    fi
-  fi
-  gem_install fpm
-
-  make static_lib
-  make install INSTALL_PATH=package
-
-  cd package
-
-  LIB_DIR=lib
-  if [[ -z "$ARCH" ]]; then
-      ARCH=$(getconf LONG_BIT)
-  fi
-  if [[ ("$FPM_OUTPUT" = "rpm") && ($ARCH -eq 64) ]]; then
-      mv lib lib64
-      LIB_DIR=lib64
-  fi
-
-  fpm \
-    -s dir \
-    -t $FPM_OUTPUT \
-    -n rocksdb \
-    -v $1 \
-    --prefix /usr \
-    --url http://rocksdb.org/ \
-    -m rocksdb@fb.com \
-    --license BSD \
-    --vendor Facebook \
-    --description "RocksDB is an embeddable persistent key-value store for fast storage." \
-    include $LIB_DIR
-}
-
-main $@
+#/usr/bin/env bash
+
+set -e
+
+function log() {
+  echo "[+] $1"
+}
+
+function fatal() {
+  echo "[!] $1"
+  exit 1
+}
+
+function platform() {
+  local  __resultvar=$1
+  if [[ -f "/etc/yum.conf" ]]; then
+    eval $__resultvar="centos"
+  elif [[ -f "/etc/dpkg/dpkg.cfg" ]]; then
+    eval $__resultvar="ubuntu"
+  else
+    fatal "Unknwon operating system"
+  fi
+}
+platform OS
+
+function package() {
+  if [[ $OS = "ubuntu" ]]; then
+    if dpkg --get-selections | grep --quiet $1; then
+      log "$1 is already installed. skipping."
+    else
+      apt-get install $@ -y
+    fi
+  elif [[ $OS = "centos" ]]; then
+    if rpm -qa | grep --quiet $1; then
+      log "$1 is already installed. skipping."
+    else
+      yum install $@ -y
+    fi
+  fi
+}
+
+function detect_fpm_output() {
+  if [[ $OS = "ubuntu" ]]; then
+    export FPM_OUTPUT=deb
+  elif [[ $OS = "centos" ]]; then
+    export FPM_OUTPUT=rpm
+  fi
+}
+detect_fpm_output
+
+function gem_install() {
+  if gem list | grep --quiet $1; then
+    log "$1 is already installed. skipping."
+  else
+    gem install $@
+  fi
+}
+
+function main() {
+  if [[ $# -ne 1 ]]; then
+    fatal "Usage: $0 <rocksdb_version>"
+  else
+    log "using rocksdb version: $1"
+  fi
+
+  if [[ -d /vagrant ]]; then
+    if [[ $OS = "ubuntu" ]]; then
+      package g++-4.8
+      export CXX=g++-4.8
+
+      # the deb would depend on libgflags2, but the static lib is the only thing
+      # installed by make install
+      package libgflags-dev
+
+      package ruby-all-dev
+    elif [[ $OS = "centos" ]]; then
+      pushd /etc/yum.repos.d
+      if [[ ! -f /etc/yum.repos.d/devtools-1.1.repo ]]; then
+        wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo
+      fi
+      package devtoolset-1.1-gcc --enablerepo=testing-1.1-devtools-6
+      package devtoolset-1.1-gcc-c++ --enablerepo=testing-1.1-devtools-6
+      export CC=/opt/centos/devtoolset-1.1/root/usr/bin/gcc
+      export CPP=/opt/centos/devtoolset-1.1/root/usr/bin/cpp
+      export CXX=/opt/centos/devtoolset-1.1/root/usr/bin/c++
+      export PATH=$PATH:/opt/centos/devtoolset-1.1/root/usr/bin
+      popd
+      if ! rpm -qa | grep --quiet gflags; then
+        rpm -i https://github.com/schuhschuh/gflags/releases/download/v2.1.0/gflags-devel-2.1.0-1.amd64.rpm
+      fi
+
+      package ruby
+      package ruby-devel
+      package rubygems
+      package rpm-build
+    fi
+  fi
+  gem_install fpm
+
+  make static_lib
+  make install INSTALL_PATH=package
+
+  cd package
+
+  LIB_DIR=lib
+  if [[ -z "$ARCH" ]]; then
+      ARCH=$(getconf LONG_BIT)
+  fi
+  if [[ ("$FPM_OUTPUT" = "rpm") && ($ARCH -eq 64) ]]; then
+      mv lib lib64
+      LIB_DIR=lib64
+  fi
+
+  fpm \
+    -s dir \
+    -t $FPM_OUTPUT \
+    -n rocksdb \
+    -v $1 \
+    --prefix /usr \
+    --url http://rocksdb.org/ \
+    -m rocksdb@fb.com \
+    --license BSD \
+    --vendor Facebook \
+    --description "RocksDB is an embeddable persistent key-value store for fast storage." \
+    include $LIB_DIR
+}
+
+main $@
diff --git a/rocksdb-5.8/build_tools/regression_build_test.sh b/rocksdb-5.8/build_tools/regression_build_test.sh
--- a/rocksdb-5.8/build_tools/regression_build_test.sh
+++ b/rocksdb-5.8/build_tools/regression_build_test.sh
@@ -1,413 +1,413 @@
-#!/usr/bin/env bash
-
-set -e
-
-NUM=10000000
-
-if [ $# -eq 1 ];then
-  DATA_DIR=$1
-elif [ $# -eq 2 ];then
-  DATA_DIR=$1
-  STAT_FILE=$2
-fi
-
-# On the production build servers, set data and stat
-# files/directories not in /tmp or else the tempdir cleaning
-# scripts will make you very unhappy.
-DATA_DIR=${DATA_DIR:-$(mktemp -t -d rocksdb_XXXX)}
-STAT_FILE=${STAT_FILE:-$(mktemp -t -u rocksdb_test_stats_XXXX)}
-
-function cleanup {
-  rm -rf $DATA_DIR
-  rm -f $STAT_FILE.fillseq
-  rm -f $STAT_FILE.readrandom
-  rm -f $STAT_FILE.overwrite
-  rm -f $STAT_FILE.memtablefillreadrandom
-}
-
-trap cleanup EXIT
-
-if [ -z $GIT_BRANCH ]; then
-  git_br=`git rev-parse --abbrev-ref HEAD`
-else
-  git_br=$(basename $GIT_BRANCH)
-fi
-
-if [ $git_br == "master" ]; then
-  git_br=""
-else
-  git_br="."$git_br
-fi
-
-make release
-
-# measure fillseq + fill up the DB for overwrite benchmark
-./db_bench \
-    --benchmarks=fillseq \
-    --db=$DATA_DIR \
-    --use_existing_db=0 \
-    --bloom_bits=10 \
-    --num=$NUM \
-    --writes=$NUM \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0  > ${STAT_FILE}.fillseq
-
-# measure overwrite performance
-./db_bench \
-    --benchmarks=overwrite \
-    --db=$DATA_DIR \
-    --use_existing_db=1 \
-    --bloom_bits=10 \
-    --num=$NUM \
-    --writes=$((NUM / 10)) \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6  \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=8 > ${STAT_FILE}.overwrite
-
-# fill up the db for readrandom benchmark (1GB total size)
-./db_bench \
-    --benchmarks=fillseq \
-    --db=$DATA_DIR \
-    --use_existing_db=0 \
-    --bloom_bits=10 \
-    --num=$NUM \
-    --writes=$NUM \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=1 > /dev/null
-
-# measure readrandom with 6GB block cache
-./db_bench \
-    --benchmarks=readrandom \
-    --db=$DATA_DIR \
-    --use_existing_db=1 \
-    --bloom_bits=10 \
-    --num=$NUM \
-    --reads=$((NUM / 5)) \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=16 > ${STAT_FILE}.readrandom
-
-# measure readrandom with 6GB block cache and tailing iterator
-./db_bench \
-    --benchmarks=readrandom \
-    --db=$DATA_DIR \
-    --use_existing_db=1 \
-    --bloom_bits=10 \
-    --num=$NUM \
-    --reads=$((NUM / 5)) \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --use_tailing_iterator=1 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=16 > ${STAT_FILE}.readrandomtailing
-
-# measure readrandom with 100MB block cache
-./db_bench \
-    --benchmarks=readrandom \
-    --db=$DATA_DIR \
-    --use_existing_db=1 \
-    --bloom_bits=10 \
-    --num=$NUM \
-    --reads=$((NUM / 5)) \
-    --cache_size=104857600 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=16 > ${STAT_FILE}.readrandomsmallblockcache
-
-# measure readrandom with 8k data in memtable
-./db_bench \
-    --benchmarks=overwrite,readrandom \
-    --db=$DATA_DIR \
-    --use_existing_db=1 \
-    --bloom_bits=10 \
-    --num=$NUM \
-    --reads=$((NUM / 5)) \
-    --writes=512 \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --write_buffer_size=1000000000 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=16 > ${STAT_FILE}.readrandom_mem_sst
-
-
-# fill up the db for readrandom benchmark with filluniquerandom (1GB total size)
-./db_bench \
-    --benchmarks=filluniquerandom \
-    --db=$DATA_DIR \
-    --use_existing_db=0 \
-    --bloom_bits=10 \
-    --num=$((NUM / 4)) \
-    --writes=$((NUM / 4)) \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=1 > /dev/null
-
-# dummy test just to compact the data
-./db_bench \
-    --benchmarks=readrandom \
-    --db=$DATA_DIR \
-    --use_existing_db=1 \
-    --bloom_bits=10 \
-    --num=$((NUM / 1000)) \
-    --reads=$((NUM / 1000)) \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=16 > /dev/null
-
-# measure readrandom after load with filluniquerandom with 6GB block cache
-./db_bench \
-    --benchmarks=readrandom \
-    --db=$DATA_DIR \
-    --use_existing_db=1 \
-    --bloom_bits=10 \
-    --num=$((NUM / 4)) \
-    --reads=$((NUM / 4)) \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --disable_auto_compactions=1 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=16 > ${STAT_FILE}.readrandom_filluniquerandom
-
-# measure readwhilewriting after load with filluniquerandom with 6GB block cache
-./db_bench \
-    --benchmarks=readwhilewriting \
-    --db=$DATA_DIR \
-    --use_existing_db=1 \
-    --bloom_bits=10 \
-    --num=$((NUM / 4)) \
-    --reads=$((NUM / 4)) \
-    --benchmark_write_rate_limit=$(( 110 * 1024 )) \
-    --write_buffer_size=100000000 \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=16 > ${STAT_FILE}.readwhilewriting
-
-# measure memtable performance -- none of the data gets flushed to disk
-./db_bench \
-    --benchmarks=fillrandom,readrandom, \
-    --db=$DATA_DIR \
-    --use_existing_db=0 \
-    --num=$((NUM / 10)) \
-    --reads=$NUM \
-    --cache_size=6442450944 \
-    --cache_numshardbits=6 \
-    --table_cache_numshardbits=4 \
-    --write_buffer_size=1000000000 \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --value_size=10 \
-    --threads=16 > ${STAT_FILE}.memtablefillreadrandom
-
-common_in_mem_args="--db=/dev/shm/rocksdb \
-    --num_levels=6 \
-    --key_size=20 \
-    --prefix_size=12 \
-    --keys_per_prefix=10 \
-    --value_size=100 \
-    --compression_type=none \
-    --compression_ratio=1 \
-    --hard_rate_limit=2 \
-    --write_buffer_size=134217728 \
-    --max_write_buffer_number=4 \
-    --level0_file_num_compaction_trigger=8 \
-    --level0_slowdown_writes_trigger=16 \
-    --level0_stop_writes_trigger=24 \
-    --target_file_size_base=134217728 \
-    --max_bytes_for_level_base=1073741824 \
-    --disable_wal=0 \
-    --wal_dir=/dev/shm/rocksdb \
-    --sync=0 \
-    --verify_checksum=1 \
-    --delete_obsolete_files_period_micros=314572800 \
-    --max_grandparent_overlap_factor=10 \
-    --use_plain_table=1 \
-    --open_files=-1 \
-    --mmap_read=1 \
-    --mmap_write=0 \
-    --memtablerep=prefix_hash \
-    --bloom_bits=10 \
-    --bloom_locality=1 \
-    --perf_level=0"
-
-# prepare a in-memory DB with 50M keys, total DB size is ~6G
-./db_bench \
-    $common_in_mem_args \
-    --statistics=0 \
-    --max_background_compactions=16 \
-    --max_background_flushes=16 \
-    --benchmarks=filluniquerandom \
-    --use_existing_db=0 \
-    --num=52428800 \
-    --threads=1 > /dev/null
-
-# Readwhilewriting
-./db_bench \
-    $common_in_mem_args \
-    --statistics=1 \
-    --max_background_compactions=4 \
-    --max_background_flushes=0 \
-    --benchmarks=readwhilewriting\
-    --use_existing_db=1 \
-    --duration=600 \
-    --threads=32 \
-    --benchmark_write_rate_limit=9502720 > ${STAT_FILE}.readwhilewriting_in_ram
-
-# Seekrandomwhilewriting
-./db_bench \
-    $common_in_mem_args \
-    --statistics=1 \
-    --max_background_compactions=4 \
-    --max_background_flushes=0 \
-    --benchmarks=seekrandomwhilewriting \
-    --use_existing_db=1 \
-    --use_tailing_iterator=1 \
-    --duration=600 \
-    --threads=32 \
-    --benchmark_write_rate_limit=9502720 > ${STAT_FILE}.seekwhilewriting_in_ram
-
-# measure fillseq with bunch of column families
-./db_bench \
-    --benchmarks=fillseq \
-    --num_column_families=500 \
-    --write_buffer_size=1048576 \
-    --db=$DATA_DIR \
-    --use_existing_db=0 \
-    --num=$NUM \
-    --writes=$NUM \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0  > ${STAT_FILE}.fillseq_lots_column_families
-
-# measure overwrite performance with bunch of column families
-./db_bench \
-    --benchmarks=overwrite \
-    --num_column_families=500 \
-    --write_buffer_size=1048576 \
-    --db=$DATA_DIR \
-    --use_existing_db=1 \
-    --num=$NUM \
-    --writes=$((NUM / 10)) \
-    --open_files=55000 \
-    --statistics=1 \
-    --histogram=1 \
-    --disable_wal=1 \
-    --sync=0 \
-    --threads=8 > ${STAT_FILE}.overwrite_lots_column_families
-
-# send data to ods
-function send_to_ods {
-  key="$1"
-  value="$2"
-
-  if [ -z $JENKINS_HOME ]; then
-    # running on devbox, just print out the values
-    echo $1 $2
-    return
-  fi
-
-  if [ -z "$value" ];then
-    echo >&2 "ERROR: Key $key doesn't have a value."
-    return
-  fi
-  curl -s "https://www.intern.facebook.com/intern/agent/ods_set.php?entity=rocksdb_build$git_br&key=$key&value=$value" \
-    --connect-timeout 60
-}
-
-function send_benchmark_to_ods {
-  bench="$1"
-  bench_key="$2"
-  file="$3"
-
-  QPS=$(grep $bench $file | awk '{print $5}')
-  P50_MICROS=$(grep $bench $file -A 6 | grep "Percentiles" | awk '{print $3}' )
-  P75_MICROS=$(grep $bench $file -A 6 | grep "Percentiles" | awk '{print $5}' )
-  P99_MICROS=$(grep $bench $file -A 6 | grep "Percentiles" | awk '{print $7}' )
-
-  send_to_ods rocksdb.build.$bench_key.qps $QPS
-  send_to_ods rocksdb.build.$bench_key.p50_micros $P50_MICROS
-  send_to_ods rocksdb.build.$bench_key.p75_micros $P75_MICROS
-  send_to_ods rocksdb.build.$bench_key.p99_micros $P99_MICROS
-}
-
-send_benchmark_to_ods overwrite overwrite $STAT_FILE.overwrite
-send_benchmark_to_ods fillseq fillseq $STAT_FILE.fillseq
-send_benchmark_to_ods readrandom readrandom $STAT_FILE.readrandom
-send_benchmark_to_ods readrandom readrandom_tailing $STAT_FILE.readrandomtailing
-send_benchmark_to_ods readrandom readrandom_smallblockcache $STAT_FILE.readrandomsmallblockcache
-send_benchmark_to_ods readrandom readrandom_memtable_sst $STAT_FILE.readrandom_mem_sst
-send_benchmark_to_ods readrandom readrandom_fillunique_random $STAT_FILE.readrandom_filluniquerandom
-send_benchmark_to_ods fillrandom memtablefillrandom $STAT_FILE.memtablefillreadrandom
-send_benchmark_to_ods readrandom memtablereadrandom $STAT_FILE.memtablefillreadrandom
-send_benchmark_to_ods readwhilewriting readwhilewriting $STAT_FILE.readwhilewriting
-send_benchmark_to_ods readwhilewriting readwhilewriting_in_ram ${STAT_FILE}.readwhilewriting_in_ram
-send_benchmark_to_ods seekrandomwhilewriting seekwhilewriting_in_ram ${STAT_FILE}.seekwhilewriting_in_ram
-send_benchmark_to_ods fillseq fillseq_lots_column_families ${STAT_FILE}.fillseq_lots_column_families
-send_benchmark_to_ods overwrite overwrite_lots_column_families ${STAT_FILE}.overwrite_lots_column_families
+#!/usr/bin/env bash
+
+set -e
+
+NUM=10000000
+
+if [ $# -eq 1 ];then
+  DATA_DIR=$1
+elif [ $# -eq 2 ];then
+  DATA_DIR=$1
+  STAT_FILE=$2
+fi
+
+# On the production build servers, set data and stat
+# files/directories not in /tmp or else the tempdir cleaning
+# scripts will make you very unhappy.
+DATA_DIR=${DATA_DIR:-$(mktemp -t -d rocksdb_XXXX)}
+STAT_FILE=${STAT_FILE:-$(mktemp -t -u rocksdb_test_stats_XXXX)}
+
+function cleanup {
+  rm -rf $DATA_DIR
+  rm -f $STAT_FILE.fillseq
+  rm -f $STAT_FILE.readrandom
+  rm -f $STAT_FILE.overwrite
+  rm -f $STAT_FILE.memtablefillreadrandom
+}
+
+trap cleanup EXIT
+
+if [ -z $GIT_BRANCH ]; then
+  git_br=`git rev-parse --abbrev-ref HEAD`
+else
+  git_br=$(basename $GIT_BRANCH)
+fi
+
+if [ $git_br == "master" ]; then
+  git_br=""
+else
+  git_br="."$git_br
+fi
+
+make release
+
+# measure fillseq + fill up the DB for overwrite benchmark
+./db_bench \
+    --benchmarks=fillseq \
+    --db=$DATA_DIR \
+    --use_existing_db=0 \
+    --bloom_bits=10 \
+    --num=$NUM \
+    --writes=$NUM \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0  > ${STAT_FILE}.fillseq
+
+# measure overwrite performance
+./db_bench \
+    --benchmarks=overwrite \
+    --db=$DATA_DIR \
+    --use_existing_db=1 \
+    --bloom_bits=10 \
+    --num=$NUM \
+    --writes=$((NUM / 10)) \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6  \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=8 > ${STAT_FILE}.overwrite
+
+# fill up the db for readrandom benchmark (1GB total size)
+./db_bench \
+    --benchmarks=fillseq \
+    --db=$DATA_DIR \
+    --use_existing_db=0 \
+    --bloom_bits=10 \
+    --num=$NUM \
+    --writes=$NUM \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=1 > /dev/null
+
+# measure readrandom with 6GB block cache
+./db_bench \
+    --benchmarks=readrandom \
+    --db=$DATA_DIR \
+    --use_existing_db=1 \
+    --bloom_bits=10 \
+    --num=$NUM \
+    --reads=$((NUM / 5)) \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=16 > ${STAT_FILE}.readrandom
+
+# measure readrandom with 6GB block cache and tailing iterator
+./db_bench \
+    --benchmarks=readrandom \
+    --db=$DATA_DIR \
+    --use_existing_db=1 \
+    --bloom_bits=10 \
+    --num=$NUM \
+    --reads=$((NUM / 5)) \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --use_tailing_iterator=1 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=16 > ${STAT_FILE}.readrandomtailing
+
+# measure readrandom with 100MB block cache
+./db_bench \
+    --benchmarks=readrandom \
+    --db=$DATA_DIR \
+    --use_existing_db=1 \
+    --bloom_bits=10 \
+    --num=$NUM \
+    --reads=$((NUM / 5)) \
+    --cache_size=104857600 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=16 > ${STAT_FILE}.readrandomsmallblockcache
+
+# measure readrandom with 8k data in memtable
+./db_bench \
+    --benchmarks=overwrite,readrandom \
+    --db=$DATA_DIR \
+    --use_existing_db=1 \
+    --bloom_bits=10 \
+    --num=$NUM \
+    --reads=$((NUM / 5)) \
+    --writes=512 \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --write_buffer_size=1000000000 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=16 > ${STAT_FILE}.readrandom_mem_sst
+
+
+# fill up the db for readrandom benchmark with filluniquerandom (1GB total size)
+./db_bench \
+    --benchmarks=filluniquerandom \
+    --db=$DATA_DIR \
+    --use_existing_db=0 \
+    --bloom_bits=10 \
+    --num=$((NUM / 4)) \
+    --writes=$((NUM / 4)) \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=1 > /dev/null
+
+# dummy test just to compact the data
+./db_bench \
+    --benchmarks=readrandom \
+    --db=$DATA_DIR \
+    --use_existing_db=1 \
+    --bloom_bits=10 \
+    --num=$((NUM / 1000)) \
+    --reads=$((NUM / 1000)) \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=16 > /dev/null
+
+# measure readrandom after load with filluniquerandom with 6GB block cache
+./db_bench \
+    --benchmarks=readrandom \
+    --db=$DATA_DIR \
+    --use_existing_db=1 \
+    --bloom_bits=10 \
+    --num=$((NUM / 4)) \
+    --reads=$((NUM / 4)) \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --disable_auto_compactions=1 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=16 > ${STAT_FILE}.readrandom_filluniquerandom
+
+# measure readwhilewriting after load with filluniquerandom with 6GB block cache
+./db_bench \
+    --benchmarks=readwhilewriting \
+    --db=$DATA_DIR \
+    --use_existing_db=1 \
+    --bloom_bits=10 \
+    --num=$((NUM / 4)) \
+    --reads=$((NUM / 4)) \
+    --benchmark_write_rate_limit=$(( 110 * 1024 )) \
+    --write_buffer_size=100000000 \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=16 > ${STAT_FILE}.readwhilewriting
+
+# measure memtable performance -- none of the data gets flushed to disk
+./db_bench \
+    --benchmarks=fillrandom,readrandom, \
+    --db=$DATA_DIR \
+    --use_existing_db=0 \
+    --num=$((NUM / 10)) \
+    --reads=$NUM \
+    --cache_size=6442450944 \
+    --cache_numshardbits=6 \
+    --table_cache_numshardbits=4 \
+    --write_buffer_size=1000000000 \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --value_size=10 \
+    --threads=16 > ${STAT_FILE}.memtablefillreadrandom
+
+common_in_mem_args="--db=/dev/shm/rocksdb \
+    --num_levels=6 \
+    --key_size=20 \
+    --prefix_size=12 \
+    --keys_per_prefix=10 \
+    --value_size=100 \
+    --compression_type=none \
+    --compression_ratio=1 \
+    --hard_rate_limit=2 \
+    --write_buffer_size=134217728 \
+    --max_write_buffer_number=4 \
+    --level0_file_num_compaction_trigger=8 \
+    --level0_slowdown_writes_trigger=16 \
+    --level0_stop_writes_trigger=24 \
+    --target_file_size_base=134217728 \
+    --max_bytes_for_level_base=1073741824 \
+    --disable_wal=0 \
+    --wal_dir=/dev/shm/rocksdb \
+    --sync=0 \
+    --verify_checksum=1 \
+    --delete_obsolete_files_period_micros=314572800 \
+    --max_grandparent_overlap_factor=10 \
+    --use_plain_table=1 \
+    --open_files=-1 \
+    --mmap_read=1 \
+    --mmap_write=0 \
+    --memtablerep=prefix_hash \
+    --bloom_bits=10 \
+    --bloom_locality=1 \
+    --perf_level=0"
+
+# prepare a in-memory DB with 50M keys, total DB size is ~6G
+./db_bench \
+    $common_in_mem_args \
+    --statistics=0 \
+    --max_background_compactions=16 \
+    --max_background_flushes=16 \
+    --benchmarks=filluniquerandom \
+    --use_existing_db=0 \
+    --num=52428800 \
+    --threads=1 > /dev/null
+
+# Readwhilewriting
+./db_bench \
+    $common_in_mem_args \
+    --statistics=1 \
+    --max_background_compactions=4 \
+    --max_background_flushes=0 \
+    --benchmarks=readwhilewriting\
+    --use_existing_db=1 \
+    --duration=600 \
+    --threads=32 \
+    --benchmark_write_rate_limit=9502720 > ${STAT_FILE}.readwhilewriting_in_ram
+
+# Seekrandomwhilewriting
+./db_bench \
+    $common_in_mem_args \
+    --statistics=1 \
+    --max_background_compactions=4 \
+    --max_background_flushes=0 \
+    --benchmarks=seekrandomwhilewriting \
+    --use_existing_db=1 \
+    --use_tailing_iterator=1 \
+    --duration=600 \
+    --threads=32 \
+    --benchmark_write_rate_limit=9502720 > ${STAT_FILE}.seekwhilewriting_in_ram
+
+# measure fillseq with bunch of column families
+./db_bench \
+    --benchmarks=fillseq \
+    --num_column_families=500 \
+    --write_buffer_size=1048576 \
+    --db=$DATA_DIR \
+    --use_existing_db=0 \
+    --num=$NUM \
+    --writes=$NUM \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0  > ${STAT_FILE}.fillseq_lots_column_families
+
+# measure overwrite performance with bunch of column families
+./db_bench \
+    --benchmarks=overwrite \
+    --num_column_families=500 \
+    --write_buffer_size=1048576 \
+    --db=$DATA_DIR \
+    --use_existing_db=1 \
+    --num=$NUM \
+    --writes=$((NUM / 10)) \
+    --open_files=55000 \
+    --statistics=1 \
+    --histogram=1 \
+    --disable_wal=1 \
+    --sync=0 \
+    --threads=8 > ${STAT_FILE}.overwrite_lots_column_families
+
+# send data to ods
+function send_to_ods {
+  key="$1"
+  value="$2"
+
+  if [ -z $JENKINS_HOME ]; then
+    # running on devbox, just print out the values
+    echo $1 $2
+    return
+  fi
+
+  if [ -z "$value" ];then
+    echo >&2 "ERROR: Key $key doesn't have a value."
+    return
+  fi
+  curl -s "https://www.intern.facebook.com/intern/agent/ods_set.php?entity=rocksdb_build$git_br&key=$key&value=$value" \
+    --connect-timeout 60
+}
+
+function send_benchmark_to_ods {
+  bench="$1"
+  bench_key="$2"
+  file="$3"
+
+  QPS=$(grep $bench $file | awk '{print $5}')
+  P50_MICROS=$(grep $bench $file -A 6 | grep "Percentiles" | awk '{print $3}' )
+  P75_MICROS=$(grep $bench $file -A 6 | grep "Percentiles" | awk '{print $5}' )
+  P99_MICROS=$(grep $bench $file -A 6 | grep "Percentiles" | awk '{print $7}' )
+
+  send_to_ods rocksdb.build.$bench_key.qps $QPS
+  send_to_ods rocksdb.build.$bench_key.p50_micros $P50_MICROS
+  send_to_ods rocksdb.build.$bench_key.p75_micros $P75_MICROS
+  send_to_ods rocksdb.build.$bench_key.p99_micros $P99_MICROS
+}
+
+send_benchmark_to_ods overwrite overwrite $STAT_FILE.overwrite
+send_benchmark_to_ods fillseq fillseq $STAT_FILE.fillseq
+send_benchmark_to_ods readrandom readrandom $STAT_FILE.readrandom
+send_benchmark_to_ods readrandom readrandom_tailing $STAT_FILE.readrandomtailing
+send_benchmark_to_ods readrandom readrandom_smallblockcache $STAT_FILE.readrandomsmallblockcache
+send_benchmark_to_ods readrandom readrandom_memtable_sst $STAT_FILE.readrandom_mem_sst
+send_benchmark_to_ods readrandom readrandom_fillunique_random $STAT_FILE.readrandom_filluniquerandom
+send_benchmark_to_ods fillrandom memtablefillrandom $STAT_FILE.memtablefillreadrandom
+send_benchmark_to_ods readrandom memtablereadrandom $STAT_FILE.memtablefillreadrandom
+send_benchmark_to_ods readwhilewriting readwhilewriting $STAT_FILE.readwhilewriting
+send_benchmark_to_ods readwhilewriting readwhilewriting_in_ram ${STAT_FILE}.readwhilewriting_in_ram
+send_benchmark_to_ods seekrandomwhilewriting seekwhilewriting_in_ram ${STAT_FILE}.seekwhilewriting_in_ram
+send_benchmark_to_ods fillseq fillseq_lots_column_families ${STAT_FILE}.fillseq_lots_column_families
+send_benchmark_to_ods overwrite overwrite_lots_column_families ${STAT_FILE}.overwrite_lots_column_families
diff --git a/rocksdb-5.8/build_tools/update_dependencies.sh b/rocksdb-5.8/build_tools/update_dependencies.sh
--- a/rocksdb-5.8/build_tools/update_dependencies.sh
+++ b/rocksdb-5.8/build_tools/update_dependencies.sh
@@ -1,131 +1,131 @@
-#!/bin/sh
-#
-# Update dependencies.sh file with the latest avaliable versions
-
-BASEDIR=$(dirname $0)
-OUTPUT=""
-
-function log_variable()
-{
-  echo "$1=${!1}" >> "$OUTPUT"
-}
-
-
-TP2_LATEST="/mnt/vol/engshare/fbcode/third-party2"
-## $1 => lib name
-## $2 => lib version (if not provided, will try to pick latest)
-## $3 => platform (if not provided, will try to pick latest gcc)
-##
-## get_lib_base will set a variable named ${LIB_NAME}_BASE to the lib location
-function get_lib_base()
-{
-  local lib_name=$1
-  local lib_version=$2
-  local lib_platform=$3
-
-  local result="$TP2_LATEST/$lib_name/"
-  
-  # Lib Version
-  if [ -z "$lib_version" ] || [ "$lib_version" = "LATEST" ]; then
-    # version is not provided, use latest
-    result=`ls -dr1v $result/*/ | head -n1`
-  else
-    result="$result/$lib_version/"
-  fi
-  
-  # Lib Platform
-  if [ -z "$lib_platform" ]; then
-    # platform is not provided, use latest gcc
-    result=`ls -dr1v $result/gcc-*[^fb]/ | head -n1`
-  else
-    result="$result/$lib_platform/"
-  fi
-  
-  result=`ls -1d $result/*/ | head -n1`
-  
-  # lib_name => LIB_NAME_BASE
-  local __res_var=${lib_name^^}"_BASE"
-  __res_var=`echo $__res_var | tr - _`
-  # LIB_NAME_BASE=$result
-  eval $__res_var=`readlink -f $result`
-  
-  log_variable $__res_var
-}
-
-###########################################################
-#                   5.x dependencies                      #
-###########################################################
-
-OUTPUT="$BASEDIR/dependencies.sh"
-
-rm -f "$OUTPUT"
-touch "$OUTPUT"
-
-echo "Writing dependencies to $OUTPUT"
-
-# Compilers locations
-GCC_BASE=`readlink -f $TP2_LATEST/gcc/5.x/centos6-native/*/`
-CLANG_BASE=`readlink -f $TP2_LATEST/llvm-fb/stable/centos6-native/*/`
-
-log_variable GCC_BASE
-log_variable CLANG_BASE
-
-# Libraries locations
-get_lib_base libgcc     5.x
-get_lib_base glibc      2.23
-get_lib_base snappy     LATEST gcc-5-glibc-2.23
-get_lib_base zlib       LATEST
-get_lib_base bzip2      LATEST
-get_lib_base lz4        LATEST
-get_lib_base zstd       LATEST
-get_lib_base gflags     LATEST
-get_lib_base jemalloc   LATEST
-get_lib_base numa       LATEST
-get_lib_base libunwind  LATEST
-get_lib_base tbb        4.0_update2 gcc-5-glibc-2.23
-
-get_lib_base kernel-headers LATEST 
-get_lib_base binutils   LATEST centos6-native 
-get_lib_base valgrind   3.10.0 gcc-5-glibc-2.23
-get_lib_base lua        5.2.3 gcc-5-glibc-2.23
-
-git diff $OUTPUT
-
-###########################################################
-#                   4.8.1 dependencies                    #
-###########################################################
-
-OUTPUT="$BASEDIR/dependencies_4.8.1.sh"
-
-rm -f "$OUTPUT"
-touch "$OUTPUT"
-
-echo "Writing 4.8.1 dependencies to $OUTPUT"
-
-# Compilers locations
-GCC_BASE=`readlink -f $TP2_LATEST/gcc/4.8.1/centos6-native/*/`
-CLANG_BASE=`readlink -f $TP2_LATEST/llvm-fb/stable/centos6-native/*/`
-
-log_variable GCC_BASE
-log_variable CLANG_BASE
-
-# Libraries locations
-get_lib_base libgcc     4.8.1  gcc-4.8.1-glibc-2.17
-get_lib_base glibc      2.17   gcc-4.8.1-glibc-2.17  
-get_lib_base snappy     LATEST gcc-4.8.1-glibc-2.17
-get_lib_base zlib       LATEST gcc-4.8.1-glibc-2.17
-get_lib_base bzip2      LATEST gcc-4.8.1-glibc-2.17
-get_lib_base lz4        LATEST gcc-4.8.1-glibc-2.17
-get_lib_base zstd       LATEST gcc-4.8.1-glibc-2.17
-get_lib_base gflags     LATEST gcc-4.8.1-glibc-2.17
-get_lib_base jemalloc   LATEST gcc-4.8.1-glibc-2.17
-get_lib_base numa       LATEST gcc-4.8.1-glibc-2.17
-get_lib_base libunwind  LATEST gcc-4.8.1-glibc-2.17
-get_lib_base tbb        4.0_update2 gcc-4.8.1-glibc-2.17
-
-get_lib_base kernel-headers LATEST gcc-4.8.1-glibc-2.17 
-get_lib_base binutils   LATEST centos6-native 
-get_lib_base valgrind   3.8.1  gcc-4.8.1-glibc-2.17
-get_lib_base lua        5.2.3 centos6-native
-
-git diff $OUTPUT
+#!/bin/sh
+#
+# Update dependencies.sh file with the latest avaliable versions
+
+BASEDIR=$(dirname $0)
+OUTPUT=""
+
+function log_variable()
+{
+  echo "$1=${!1}" >> "$OUTPUT"
+}
+
+
+TP2_LATEST="/mnt/vol/engshare/fbcode/third-party2"
+## $1 => lib name
+## $2 => lib version (if not provided, will try to pick latest)
+## $3 => platform (if not provided, will try to pick latest gcc)
+##
+## get_lib_base will set a variable named ${LIB_NAME}_BASE to the lib location
+function get_lib_base()
+{
+  local lib_name=$1
+  local lib_version=$2
+  local lib_platform=$3
+
+  local result="$TP2_LATEST/$lib_name/"
+  
+  # Lib Version
+  if [ -z "$lib_version" ] || [ "$lib_version" = "LATEST" ]; then
+    # version is not provided, use latest
+    result=`ls -dr1v $result/*/ | head -n1`
+  else
+    result="$result/$lib_version/"
+  fi
+  
+  # Lib Platform
+  if [ -z "$lib_platform" ]; then
+    # platform is not provided, use latest gcc
+    result=`ls -dr1v $result/gcc-*[^fb]/ | head -n1`
+  else
+    result="$result/$lib_platform/"
+  fi
+  
+  result=`ls -1d $result/*/ | head -n1`
+  
+  # lib_name => LIB_NAME_BASE
+  local __res_var=${lib_name^^}"_BASE"
+  __res_var=`echo $__res_var | tr - _`
+  # LIB_NAME_BASE=$result
+  eval $__res_var=`readlink -f $result`
+  
+  log_variable $__res_var
+}
+
+###########################################################
+#                   5.x dependencies                      #
+###########################################################
+
+OUTPUT="$BASEDIR/dependencies.sh"
+
+rm -f "$OUTPUT"
+touch "$OUTPUT"
+
+echo "Writing dependencies to $OUTPUT"
+
+# Compilers locations
+GCC_BASE=`readlink -f $TP2_LATEST/gcc/5.x/centos6-native/*/`
+CLANG_BASE=`readlink -f $TP2_LATEST/llvm-fb/stable/centos6-native/*/`
+
+log_variable GCC_BASE
+log_variable CLANG_BASE
+
+# Libraries locations
+get_lib_base libgcc     5.x
+get_lib_base glibc      2.23
+get_lib_base snappy     LATEST gcc-5-glibc-2.23
+get_lib_base zlib       LATEST
+get_lib_base bzip2      LATEST
+get_lib_base lz4        LATEST
+get_lib_base zstd       LATEST
+get_lib_base gflags     LATEST
+get_lib_base jemalloc   LATEST
+get_lib_base numa       LATEST
+get_lib_base libunwind  LATEST
+get_lib_base tbb        4.0_update2 gcc-5-glibc-2.23
+
+get_lib_base kernel-headers LATEST 
+get_lib_base binutils   LATEST centos6-native 
+get_lib_base valgrind   3.10.0 gcc-5-glibc-2.23
+get_lib_base lua        5.2.3 gcc-5-glibc-2.23
+
+git diff $OUTPUT
+
+###########################################################
+#                   4.8.1 dependencies                    #
+###########################################################
+
+OUTPUT="$BASEDIR/dependencies_4.8.1.sh"
+
+rm -f "$OUTPUT"
+touch "$OUTPUT"
+
+echo "Writing 4.8.1 dependencies to $OUTPUT"
+
+# Compilers locations
+GCC_BASE=`readlink -f $TP2_LATEST/gcc/4.8.1/centos6-native/*/`
+CLANG_BASE=`readlink -f $TP2_LATEST/llvm-fb/stable/centos6-native/*/`
+
+log_variable GCC_BASE
+log_variable CLANG_BASE
+
+# Libraries locations
+get_lib_base libgcc     4.8.1  gcc-4.8.1-glibc-2.17
+get_lib_base glibc      2.17   gcc-4.8.1-glibc-2.17  
+get_lib_base snappy     LATEST gcc-4.8.1-glibc-2.17
+get_lib_base zlib       LATEST gcc-4.8.1-glibc-2.17
+get_lib_base bzip2      LATEST gcc-4.8.1-glibc-2.17
+get_lib_base lz4        LATEST gcc-4.8.1-glibc-2.17
+get_lib_base zstd       LATEST gcc-4.8.1-glibc-2.17
+get_lib_base gflags     LATEST gcc-4.8.1-glibc-2.17
+get_lib_base jemalloc   LATEST gcc-4.8.1-glibc-2.17
+get_lib_base numa       LATEST gcc-4.8.1-glibc-2.17
+get_lib_base libunwind  LATEST gcc-4.8.1-glibc-2.17
+get_lib_base tbb        4.0_update2 gcc-4.8.1-glibc-2.17
+
+get_lib_base kernel-headers LATEST gcc-4.8.1-glibc-2.17 
+get_lib_base binutils   LATEST centos6-native 
+get_lib_base valgrind   3.8.1  gcc-4.8.1-glibc-2.17
+get_lib_base lua        5.2.3 centos6-native
+
+git diff $OUTPUT
diff --git a/rocksdb-5.8/build_tools/version.sh b/rocksdb-5.8/build_tools/version.sh
--- a/rocksdb-5.8/build_tools/version.sh
+++ b/rocksdb-5.8/build_tools/version.sh
@@ -1,22 +1,22 @@
-#!/bin/sh
-if [ "$#" = "0" ]; then
-  echo "Usage: $0 major|minor|patch|full"
-  exit 1
-fi
-
-if [ "$1" = "major" ]; then
-  cat include/rocksdb/version.h  | grep MAJOR | head -n1 | awk '{print $3}'
-fi
-if [ "$1" = "minor" ]; then
-  cat include/rocksdb/version.h  | grep MINOR | head -n1 | awk '{print $3}'
-fi
-if [ "$1" = "patch" ]; then
-  cat include/rocksdb/version.h  | grep PATCH | head -n1 | awk '{print $3}'
-fi
-if [ "$1" = "full" ]; then
-  awk '/#define ROCKSDB/ { env[$2] = $3 }
-       END { printf "%s.%s.%s\n", env["ROCKSDB_MAJOR"],
-                                  env["ROCKSDB_MINOR"],
-                                  env["ROCKSDB_PATCH"] }'  \
-      include/rocksdb/version.h
-fi
+#!/bin/sh
+if [ "$#" = "0" ]; then
+  echo "Usage: $0 major|minor|patch|full"
+  exit 1
+fi
+
+if [ "$1" = "major" ]; then
+  cat include/rocksdb/version.h  | grep MAJOR | head -n1 | awk '{print $3}'
+fi
+if [ "$1" = "minor" ]; then
+  cat include/rocksdb/version.h  | grep MINOR | head -n1 | awk '{print $3}'
+fi
+if [ "$1" = "patch" ]; then
+  cat include/rocksdb/version.h  | grep PATCH | head -n1 | awk '{print $3}'
+fi
+if [ "$1" = "full" ]; then
+  awk '/#define ROCKSDB/ { env[$2] = $3 }
+       END { printf "%s.%s.%s\n", env["ROCKSDB_MAJOR"],
+                                  env["ROCKSDB_MINOR"],
+                                  env["ROCKSDB_PATCH"] }'  \
+      include/rocksdb/version.h
+fi
diff --git a/rocksdb-5.8/cmake/modules/FindJeMalloc.cmake b/rocksdb-5.8/cmake/modules/FindJeMalloc.cmake
deleted file mode 100644
--- a/rocksdb-5.8/cmake/modules/FindJeMalloc.cmake
+++ /dev/null
@@ -1,21 +0,0 @@
-# - Find JeMalloc library
-# Find the native JeMalloc includes and library
-#
-# JEMALLOC_INCLUDE_DIR - where to find jemalloc.h, etc.
-# JEMALLOC_LIBRARIES - List of libraries when using jemalloc.
-# JEMALLOC_FOUND - True if jemalloc found.
-
-find_path(JEMALLOC_INCLUDE_DIR
-  NAMES jemalloc/jemalloc.h
-  HINTS ${JEMALLOC_ROOT_DIR}/include)
-
-find_library(JEMALLOC_LIBRARIES
-  NAMES jemalloc
-  HINTS ${JEMALLOC_ROOT_DIR}/lib)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(jemalloc DEFAULT_MSG JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR)
-
-mark_as_advanced(
-  JEMALLOC_LIBRARIES
-  JEMALLOC_INCLUDE_DIR)
diff --git a/rocksdb-5.8/cmake/modules/Findbzip2.cmake b/rocksdb-5.8/cmake/modules/Findbzip2.cmake
deleted file mode 100644
--- a/rocksdb-5.8/cmake/modules/Findbzip2.cmake
+++ /dev/null
@@ -1,21 +0,0 @@
-# - Find Bzip2
-# Find the bzip2 compression library and includes
-#
-# BZIP2_INCLUDE_DIR - where to find bzlib.h, etc.
-# BZIP2_LIBRARIES - List of libraries when using bzip2.
-# BZIP2_FOUND - True if bzip2 found.
-
-find_path(BZIP2_INCLUDE_DIR
-  NAMES bzlib.h
-  HINTS ${BZIP2_ROOT_DIR}/include)
-
-find_library(BZIP2_LIBRARIES
-  NAMES bz2
-  HINTS ${BZIP2_ROOT_DIR}/lib)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(bzip2 DEFAULT_MSG BZIP2_LIBRARIES BZIP2_INCLUDE_DIR)
-
-mark_as_advanced(
-  BZIP2_LIBRARIES
-  BZIP2_INCLUDE_DIR)
diff --git a/rocksdb-5.8/cmake/modules/Findlz4.cmake b/rocksdb-5.8/cmake/modules/Findlz4.cmake
deleted file mode 100644
--- a/rocksdb-5.8/cmake/modules/Findlz4.cmake
+++ /dev/null
@@ -1,21 +0,0 @@
-# - Find Lz4
-# Find the lz4 compression library and includes
-#
-# LZ4_INCLUDE_DIR - where to find lz4.h, etc.
-# LZ4_LIBRARIES - List of libraries when using lz4.
-# LZ4_FOUND - True if lz4 found.
-
-find_path(LZ4_INCLUDE_DIR
-  NAMES lz4.h
-  HINTS ${LZ4_ROOT_DIR}/include)
-
-find_library(LZ4_LIBRARIES
-  NAMES lz4
-  HINTS ${LZ4_ROOT_DIR}/lib)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(lz4 DEFAULT_MSG LZ4_LIBRARIES LZ4_INCLUDE_DIR)
-
-mark_as_advanced(
-  LZ4_LIBRARIES
-  LZ4_INCLUDE_DIR)
diff --git a/rocksdb-5.8/cmake/modules/Findsnappy.cmake b/rocksdb-5.8/cmake/modules/Findsnappy.cmake
deleted file mode 100644
--- a/rocksdb-5.8/cmake/modules/Findsnappy.cmake
+++ /dev/null
@@ -1,21 +0,0 @@
-# - Find Snappy
-# Find the snappy compression library and includes
-#
-# SNAPPY_INCLUDE_DIR - where to find snappy.h, etc.
-# SNAPPY_LIBRARIES - List of libraries when using snappy.
-# SNAPPY_FOUND - True if snappy found.
-
-find_path(SNAPPY_INCLUDE_DIR
-  NAMES snappy.h
-  HINTS ${SNAPPY_ROOT_DIR}/include)
-
-find_library(SNAPPY_LIBRARIES
-  NAMES snappy
-  HINTS ${SNAPPY_ROOT_DIR}/lib)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(snappy DEFAULT_MSG SNAPPY_LIBRARIES SNAPPY_INCLUDE_DIR)
-
-mark_as_advanced(
-  SNAPPY_LIBRARIES
-  SNAPPY_INCLUDE_DIR)
diff --git a/rocksdb-5.8/cmake/modules/Findzlib.cmake b/rocksdb-5.8/cmake/modules/Findzlib.cmake
deleted file mode 100644
--- a/rocksdb-5.8/cmake/modules/Findzlib.cmake
+++ /dev/null
@@ -1,21 +0,0 @@
-# - Find zlib
-# Find the zlib compression library and includes
-#
-# ZLIB_INCLUDE_DIR - where to find zlib.h, etc.
-# ZLIB_LIBRARIES - List of libraries when using zlib.
-# ZLIB_FOUND - True if zlib found.
-
-find_path(ZLIB_INCLUDE_DIR
-  NAMES zlib.h
-  HINTS ${ZLIB_ROOT_DIR}/include)
-
-find_library(ZLIB_LIBRARIES
-  NAMES z
-  HINTS ${ZLIB_ROOT_DIR}/lib)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(zlib DEFAULT_MSG ZLIB_LIBRARIES ZLIB_INCLUDE_DIR)
-
-mark_as_advanced(
-  ZLIB_LIBRARIES
-  ZLIB_INCLUDE_DIR)
diff --git a/rocksdb-5.8/cmake/modules/Findzstd.cmake b/rocksdb-5.8/cmake/modules/Findzstd.cmake
deleted file mode 100644
--- a/rocksdb-5.8/cmake/modules/Findzstd.cmake
+++ /dev/null
@@ -1,21 +0,0 @@
-# - Find zstd
-# Find the zstd compression library and includes
-#
-# ZSTD_INCLUDE_DIR - where to find zstd.h, etc.
-# ZSTD_LIBRARIES - List of libraries when using zstd.
-# ZSTD_FOUND - True if zstd found.
-
-find_path(ZSTD_INCLUDE_DIR
-  NAMES zstd.h
-  HINTS ${ZSTD_ROOT_DIR}/include)
-
-find_library(ZSTD_LIBRARIES
-  NAMES zstd
-  HINTS ${ZSTD_ROOT_DIR}/lib)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(zstd DEFAULT_MSG ZSTD_LIBRARIES ZSTD_INCLUDE_DIR)
-
-mark_as_advanced(
-  ZSTD_LIBRARIES
-  ZSTD_INCLUDE_DIR)
diff --git a/src/Database/RocksDB/DB.hs b/src/Database/RocksDB/DB.hs
--- a/src/Database/RocksDB/DB.hs
+++ b/src/Database/RocksDB/DB.hs
@@ -8,12 +8,12 @@
 
 import qualified Data.ByteString as BS
 import qualified Data.ByteString.Unsafe as BS
-import Database.RocksDB.Exceptions
 import Database.RocksDB.Internals
 import Database.RocksDB.Options
-import Foreign
+import Database.RocksDB.Utils
+import Foreign hiding (newForeignPtr)
 import Foreign.C
-import GHC.ForeignPtr
+import Foreign.Concurrent
 
 openDB :: Options -> FilePath -> IO (ForeignPtr Rocksdb)
 {-# INLINEABLE openDB #-}
@@ -22,7 +22,7 @@
   withForeignPtr opts_fptr $ \opts_ptr ->
     withCString path $ \path_ptr -> do
       db_ptr <- withErrorMessagePtr $ c_rocksdb_open opts_ptr path_ptr
-      newConcForeignPtr db_ptr $ c_rocksdb_close db_ptr
+      newForeignPtr db_ptr $ c_rocksdb_close db_ptr
 
 putDB ::
      ForeignPtr Rocksdb
diff --git a/src/Database/RocksDB/Exceptions.hs b/src/Database/RocksDB/Exceptions.hs
--- a/src/Database/RocksDB/Exceptions.hs
+++ b/src/Database/RocksDB/Exceptions.hs
@@ -2,26 +2,11 @@
 
 module Database.RocksDB.Exceptions
   ( RocksDBException(..)
-  , withErrorMessagePtr
   ) where
 
 import Control.Exception.Safe
 import qualified Data.ByteString as BS
-import Foreign
-import Foreign.C
 
 newtype RocksDBException = RocksDBException
   { errorMessage :: BS.ByteString
   } deriving (Show, Exception)
-
-withErrorMessagePtr :: (Ptr (Ptr CChar) -> IO r) -> IO r
-{-# INLINEABLE withErrorMessagePtr #-}
-withErrorMessagePtr cont =
-  alloca $ \p -> do
-    r <- cont p
-    p' <- peek p
-    if p' == nullPtr
-      then pure r
-      else do
-        msg <- BS.packCString p'
-        throw $ RocksDBException msg
diff --git a/src/Database/RocksDB/Internals.hs b/src/Database/RocksDB/Internals.hs
--- a/src/Database/RocksDB/Internals.hs
+++ b/src/Database/RocksDB/Internals.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE InterruptibleFFI #-}
+
 module Database.RocksDB.Internals where
 
 import Foreign
@@ -95,95 +97,102 @@
 
 data RocksdbCheckpoint
 
-foreign import ccall unsafe "rocksdb_open" c_rocksdb_open ::
+foreign import ccall interruptible "rocksdb_open" c_rocksdb_open ::
                Ptr RocksdbOptions ->
                  Ptr CChar -> Ptr (Ptr CChar) -> IO (Ptr Rocksdb)
 
-foreign import ccall unsafe "rocksdb_open_for_read_only"
+foreign import ccall interruptible "rocksdb_open_for_read_only"
                c_rocksdb_open_for_read_only ::
                Ptr RocksdbOptions ->
                  Ptr CChar -> CUChar -> Ptr (Ptr CChar) -> IO (Ptr Rocksdb)
 
-foreign import ccall unsafe "rocksdb_backup_engine_open"
+foreign import ccall interruptible "rocksdb_backup_engine_open"
                c_rocksdb_backup_engine_open ::
                Ptr RocksdbOptions ->
                  Ptr CChar -> Ptr (Ptr CChar) -> IO (Ptr RocksdbBackupEngine)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_backup_engine_create_new_backup"
                c_rocksdb_backup_engine_create_new_backup ::
                Ptr RocksdbBackupEngine -> Ptr Rocksdb -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_backup_engine_purge_old_backups"
                c_rocksdb_backup_engine_purge_old_backups ::
                Ptr RocksdbBackupEngine -> Word32 -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_restore_options_create"
+foreign import ccall interruptible "rocksdb_restore_options_create"
                c_rocksdb_restore_options_create :: IO (Ptr RocksdbRestoreOptions)
 
-foreign import ccall unsafe "rocksdb_restore_options_destroy"
-               c_rocksdb_restore_options_destroy ::
-               Ptr RocksdbRestoreOptions -> IO ()
+foreign import ccall interruptible
+               "rocksdb_restore_options_destroy" c_rocksdb_restore_options_destroy
+               :: Ptr RocksdbRestoreOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_restore_options_set_keep_log_files"
                c_rocksdb_restore_options_set_keep_log_files ::
                Ptr RocksdbRestoreOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_backup_engine_restore_db_from_latest_backup"
                c_rocksdb_backup_engine_restore_db_from_latest_backup ::
                Ptr RocksdbBackupEngine ->
                  Ptr CChar ->
                    Ptr CChar -> Ptr RocksdbRestoreOptions -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_backup_engine_get_backup_info"
+foreign import ccall interruptible
+               "rocksdb_backup_engine_get_backup_info"
                c_rocksdb_backup_engine_get_backup_info ::
                Ptr RocksdbBackupEngine -> IO (Ptr RocksdbBackupEngineInfo)
 
-foreign import ccall unsafe "rocksdb_backup_engine_info_count"
+foreign import ccall interruptible
+               "rocksdb_backup_engine_info_count"
                c_rocksdb_backup_engine_info_count ::
                Ptr RocksdbBackupEngineInfo -> IO CInt
 
-foreign import ccall unsafe "rocksdb_backup_engine_info_timestamp"
+foreign import ccall interruptible
+               "rocksdb_backup_engine_info_timestamp"
                c_rocksdb_backup_engine_info_timestamp ::
                Ptr RocksdbBackupEngineInfo -> CInt -> IO Int64
 
-foreign import ccall unsafe "rocksdb_backup_engine_info_backup_id"
+foreign import ccall interruptible
+               "rocksdb_backup_engine_info_backup_id"
                c_rocksdb_backup_engine_info_backup_id ::
                Ptr RocksdbBackupEngineInfo -> CInt -> IO Word32
 
-foreign import ccall unsafe "rocksdb_backup_engine_info_size"
-               c_rocksdb_backup_engine_info_size ::
-               Ptr RocksdbBackupEngineInfo -> CInt -> IO Word64
+foreign import ccall interruptible
+               "rocksdb_backup_engine_info_size" c_rocksdb_backup_engine_info_size
+               :: Ptr RocksdbBackupEngineInfo -> CInt -> IO Word64
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_backup_engine_info_number_files"
                c_rocksdb_backup_engine_info_number_files ::
                Ptr RocksdbBackupEngineInfo -> CInt -> IO Word32
 
-foreign import ccall unsafe "rocksdb_backup_engine_info_destroy"
+foreign import ccall interruptible
+               "rocksdb_backup_engine_info_destroy"
                c_rocksdb_backup_engine_info_destroy ::
                Ptr RocksdbBackupEngineInfo -> IO ()
 
-foreign import ccall unsafe "rocksdb_backup_engine_close"
+foreign import ccall interruptible "rocksdb_backup_engine_close"
                c_rocksdb_backup_engine_close :: Ptr RocksdbBackupEngine -> IO ()
 
-foreign import ccall unsafe "rocksdb_checkpoint_object_create"
+foreign import ccall interruptible
+               "rocksdb_checkpoint_object_create"
                c_rocksdb_checkpoint_object_create ::
                Ptr Rocksdb -> Ptr (Ptr CChar) -> IO (Ptr RocksdbCheckpoint)
 
-foreign import ccall unsafe "rocksdb_checkpoint_create"
+foreign import ccall interruptible "rocksdb_checkpoint_create"
                c_rocksdb_checkpoint_create ::
                Ptr RocksdbCheckpoint ->
                  Ptr CChar -> Word64 -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_checkpoint_object_destroy"
+foreign import ccall interruptible
+               "rocksdb_checkpoint_object_destroy"
                c_rocksdb_checkpoint_object_destroy ::
                Ptr RocksdbCheckpoint -> IO ()
 
-foreign import ccall unsafe "rocksdb_open_column_families"
+foreign import ccall interruptible "rocksdb_open_column_families"
                c_rocksdb_open_column_families ::
                Ptr RocksdbOptions ->
                  Ptr CChar ->
@@ -193,7 +202,7 @@
                          Ptr (Ptr RocksdbColumnFamilyHandle) ->
                            Ptr (Ptr CChar) -> IO (Ptr Rocksdb)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_open_for_read_only_column_families"
                c_rocksdb_open_for_read_only_column_families ::
                Ptr RocksdbOptions ->
@@ -204,92 +213,99 @@
                          Ptr (Ptr RocksdbColumnFamilyHandle) ->
                            CUChar -> Ptr (Ptr CChar) -> IO (Ptr Rocksdb)
 
-foreign import ccall unsafe "rocksdb_list_column_families"
+foreign import ccall interruptible "rocksdb_list_column_families"
                c_rocksdb_list_column_families ::
                Ptr RocksdbOptions ->
                  Ptr CChar -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr (Ptr CChar))
 
-foreign import ccall unsafe "rocksdb_list_column_families_destroy"
+foreign import ccall interruptible
+               "rocksdb_list_column_families_destroy"
                c_rocksdb_list_column_families_destroy ::
                Ptr (Ptr CChar) -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_create_column_family"
+foreign import ccall interruptible "rocksdb_create_column_family"
                c_rocksdb_create_column_family ::
                Ptr Rocksdb ->
                  Ptr RocksdbOptions ->
                    Ptr CChar -> Ptr (Ptr CChar) -> IO (Ptr RocksdbColumnFamilyHandle)
 
-foreign import ccall unsafe "rocksdb_drop_column_family"
+foreign import ccall interruptible "rocksdb_drop_column_family"
                c_rocksdb_drop_column_family ::
                Ptr Rocksdb ->
                  Ptr RocksdbColumnFamilyHandle -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_column_family_handle_destroy"
+foreign import ccall interruptible
+               "rocksdb_column_family_handle_destroy"
                c_rocksdb_column_family_handle_destroy ::
                Ptr RocksdbColumnFamilyHandle -> IO ()
 
-foreign import ccall unsafe "rocksdb_close" c_rocksdb_close ::
-               Ptr Rocksdb -> IO ()
+foreign import ccall interruptible "rocksdb_close" c_rocksdb_close
+               :: Ptr Rocksdb -> IO ()
 
-foreign import ccall unsafe "rocksdb_put" c_rocksdb_put ::
+foreign import ccall interruptible "rocksdb_put" c_rocksdb_put ::
                Ptr Rocksdb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr CChar ->
                      CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_put_cf" c_rocksdb_put_cf ::
+foreign import ccall interruptible "rocksdb_put_cf"
+               c_rocksdb_put_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr RocksdbColumnFamilyHandle ->
                      Ptr CChar ->
                        CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_delete" c_rocksdb_delete ::
+foreign import ccall interruptible "rocksdb_delete"
+               c_rocksdb_delete ::
                Ptr Rocksdb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_delete_cf" c_rocksdb_delete_cf
-               ::
+foreign import ccall interruptible "rocksdb_delete_cf"
+               c_rocksdb_delete_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr RocksdbColumnFamilyHandle ->
                      Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_merge" c_rocksdb_merge ::
+foreign import ccall interruptible "rocksdb_merge" c_rocksdb_merge
+               ::
                Ptr Rocksdb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr CChar ->
                      CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_merge_cf" c_rocksdb_merge_cf
-               ::
+foreign import ccall interruptible "rocksdb_merge_cf"
+               c_rocksdb_merge_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr RocksdbColumnFamilyHandle ->
                      Ptr CChar ->
                        CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_write" c_rocksdb_write ::
+foreign import ccall interruptible "rocksdb_write" c_rocksdb_write
+               ::
                Ptr Rocksdb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr RocksdbWritebatch -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_get" c_rocksdb_get ::
+foreign import ccall interruptible "rocksdb_get" c_rocksdb_get ::
                Ptr Rocksdb ->
                  Ptr RocksdbReadoptions ->
                    Ptr CChar ->
                      CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_get_cf" c_rocksdb_get_cf ::
+foreign import ccall interruptible "rocksdb_get_cf"
+               c_rocksdb_get_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbReadoptions ->
                    Ptr RocksdbColumnFamilyHandle ->
                      Ptr CChar ->
                        CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_multi_get" c_rocksdb_multi_get
-               ::
+foreign import ccall interruptible "rocksdb_multi_get"
+               c_rocksdb_multi_get ::
                Ptr Rocksdb ->
                  Ptr RocksdbReadoptions ->
                    CSize ->
@@ -297,7 +313,7 @@
                        Ptr CSize ->
                          Ptr (Ptr CChar) -> Ptr CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_multi_get_cf"
+foreign import ccall interruptible "rocksdb_multi_get_cf"
                c_rocksdb_multi_get_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbReadoptions ->
@@ -307,52 +323,52 @@
                          Ptr CSize ->
                            Ptr (Ptr CChar) -> Ptr CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_create_iterator"
+foreign import ccall interruptible "rocksdb_create_iterator"
                c_rocksdb_create_iterator ::
                Ptr Rocksdb -> Ptr RocksdbReadoptions -> IO (Ptr RocksdbIterator)
 
-foreign import ccall unsafe "rocksdb_create_iterator_cf"
+foreign import ccall interruptible "rocksdb_create_iterator_cf"
                c_rocksdb_create_iterator_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbReadoptions ->
                    Ptr RocksdbColumnFamilyHandle -> IO (Ptr RocksdbIterator)
 
-foreign import ccall unsafe "rocksdb_create_iterators"
+foreign import ccall interruptible "rocksdb_create_iterators"
                c_rocksdb_create_iterators ::
                Ptr Rocksdb ->
                  Ptr RocksdbReadoptions ->
                    Ptr (Ptr RocksdbColumnFamilyHandle) ->
                      Ptr (Ptr RocksdbIterator) -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_create_snapshot"
+foreign import ccall interruptible "rocksdb_create_snapshot"
                c_rocksdb_create_snapshot ::
                Ptr Rocksdb -> IO (Ptr RocksdbSnapshot)
 
-foreign import ccall unsafe "rocksdb_release_snapshot"
+foreign import ccall interruptible "rocksdb_release_snapshot"
                c_rocksdb_release_snapshot ::
                Ptr Rocksdb -> Ptr RocksdbSnapshot -> IO ()
 
-foreign import ccall unsafe "rocksdb_property_value"
+foreign import ccall interruptible "rocksdb_property_value"
                c_rocksdb_property_value ::
                Ptr Rocksdb -> Ptr CChar -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_property_int"
+foreign import ccall interruptible "rocksdb_property_int"
                c_rocksdb_property_int ::
                Ptr Rocksdb -> Ptr CChar -> Ptr Word64 -> IO CInt
 
-foreign import ccall unsafe "rocksdb_property_value_cf"
+foreign import ccall interruptible "rocksdb_property_value_cf"
                c_rocksdb_property_value_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbColumnFamilyHandle -> Ptr CChar -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_approximate_sizes"
+foreign import ccall interruptible "rocksdb_approximate_sizes"
                c_rocksdb_approximate_sizes ::
                Ptr Rocksdb ->
                  CInt ->
                    Ptr (Ptr CChar) ->
                      Ptr CSize -> Ptr (Ptr CChar) -> Ptr CSize -> Ptr Word64 -> IO ()
 
-foreign import ccall unsafe "rocksdb_approximate_sizes_cf"
+foreign import ccall interruptible "rocksdb_approximate_sizes_cf"
                c_rocksdb_approximate_sizes_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbColumnFamilyHandle ->
@@ -360,124 +376,128 @@
                      Ptr (Ptr CChar) ->
                        Ptr CSize -> Ptr (Ptr CChar) -> Ptr CSize -> Ptr Word64 -> IO ()
 
-foreign import ccall unsafe "rocksdb_compact_range"
+foreign import ccall interruptible "rocksdb_compact_range"
                c_rocksdb_compact_range ::
                Ptr Rocksdb -> Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_compact_range_cf"
+foreign import ccall interruptible "rocksdb_compact_range_cf"
                c_rocksdb_compact_range_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_compact_range_opt"
+foreign import ccall interruptible "rocksdb_compact_range_opt"
                c_rocksdb_compact_range_opt ::
                Ptr Rocksdb ->
                  Ptr RocksdbCompactoptions ->
                    Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_compact_range_cf_opt"
+foreign import ccall interruptible "rocksdb_compact_range_cf_opt"
                c_rocksdb_compact_range_cf_opt ::
                Ptr Rocksdb ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr RocksdbCompactoptions ->
                      Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_delete_file"
+foreign import ccall interruptible "rocksdb_delete_file"
                c_rocksdb_delete_file :: Ptr Rocksdb -> Ptr CChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_livefiles" c_rocksdb_livefiles
-               :: Ptr Rocksdb -> IO (Ptr RocksdbLivefiles)
+foreign import ccall interruptible "rocksdb_livefiles"
+               c_rocksdb_livefiles :: Ptr Rocksdb -> IO (Ptr RocksdbLivefiles)
 
-foreign import ccall unsafe "rocksdb_flush" c_rocksdb_flush ::
+foreign import ccall interruptible "rocksdb_flush" c_rocksdb_flush
+               ::
                Ptr Rocksdb -> Ptr RocksdbFlushoptions -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_disable_file_deletions"
+foreign import ccall interruptible "rocksdb_disable_file_deletions"
                c_rocksdb_disable_file_deletions ::
                Ptr Rocksdb -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_enable_file_deletions"
+foreign import ccall interruptible "rocksdb_enable_file_deletions"
                c_rocksdb_enable_file_deletions ::
                Ptr Rocksdb -> CUChar -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_destroy_db"
+foreign import ccall interruptible "rocksdb_destroy_db"
                c_rocksdb_destroy_db ::
                Ptr RocksdbOptions -> Ptr CChar -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_repair_db" c_rocksdb_repair_db
-               :: Ptr RocksdbOptions -> Ptr CChar -> Ptr (Ptr CChar) -> IO ()
+foreign import ccall interruptible "rocksdb_repair_db"
+               c_rocksdb_repair_db ::
+               Ptr RocksdbOptions -> Ptr CChar -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_iter_destroy"
+foreign import ccall interruptible "rocksdb_iter_destroy"
                c_rocksdb_iter_destroy :: Ptr RocksdbIterator -> IO ()
 
-foreign import ccall unsafe "rocksdb_iter_valid"
+foreign import ccall interruptible "rocksdb_iter_valid"
                c_rocksdb_iter_valid :: Ptr RocksdbIterator -> IO CUChar
 
-foreign import ccall unsafe "rocksdb_iter_seek_to_first"
+foreign import ccall interruptible "rocksdb_iter_seek_to_first"
                c_rocksdb_iter_seek_to_first :: Ptr RocksdbIterator -> IO ()
 
-foreign import ccall unsafe "rocksdb_iter_seek_to_last"
+foreign import ccall interruptible "rocksdb_iter_seek_to_last"
                c_rocksdb_iter_seek_to_last :: Ptr RocksdbIterator -> IO ()
 
-foreign import ccall unsafe "rocksdb_iter_seek" c_rocksdb_iter_seek
-               :: Ptr RocksdbIterator -> Ptr CChar -> CSize -> IO ()
+foreign import ccall interruptible "rocksdb_iter_seek"
+               c_rocksdb_iter_seek ::
+               Ptr RocksdbIterator -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_iter_seek_for_prev"
+foreign import ccall interruptible "rocksdb_iter_seek_for_prev"
                c_rocksdb_iter_seek_for_prev ::
                Ptr RocksdbIterator -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_iter_next" c_rocksdb_iter_next
-               :: Ptr RocksdbIterator -> IO ()
+foreign import ccall interruptible "rocksdb_iter_next"
+               c_rocksdb_iter_next :: Ptr RocksdbIterator -> IO ()
 
-foreign import ccall unsafe "rocksdb_iter_prev" c_rocksdb_iter_prev
-               :: Ptr RocksdbIterator -> IO ()
+foreign import ccall interruptible "rocksdb_iter_prev"
+               c_rocksdb_iter_prev :: Ptr RocksdbIterator -> IO ()
 
-foreign import ccall unsafe "rocksdb_iter_key" c_rocksdb_iter_key
-               :: Ptr RocksdbIterator -> Ptr CSize -> IO (Ptr CChar)
+foreign import ccall interruptible "rocksdb_iter_key"
+               c_rocksdb_iter_key ::
+               Ptr RocksdbIterator -> Ptr CSize -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_iter_value"
+foreign import ccall interruptible "rocksdb_iter_value"
                c_rocksdb_iter_value ::
                Ptr RocksdbIterator -> Ptr CSize -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_iter_get_error"
+foreign import ccall interruptible "rocksdb_iter_get_error"
                c_rocksdb_iter_get_error ::
                Ptr RocksdbIterator -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_create"
+foreign import ccall interruptible "rocksdb_writebatch_create"
                c_rocksdb_writebatch_create :: IO (Ptr RocksdbWritebatch)
 
-foreign import ccall unsafe "rocksdb_writebatch_create_from"
+foreign import ccall interruptible "rocksdb_writebatch_create_from"
                c_rocksdb_writebatch_create_from ::
                Ptr CChar -> CSize -> IO (Ptr RocksdbWritebatch)
 
-foreign import ccall unsafe "rocksdb_writebatch_destroy"
+foreign import ccall interruptible "rocksdb_writebatch_destroy"
                c_rocksdb_writebatch_destroy :: Ptr RocksdbWritebatch -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_clear"
+foreign import ccall interruptible "rocksdb_writebatch_clear"
                c_rocksdb_writebatch_clear :: Ptr RocksdbWritebatch -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_count"
+foreign import ccall interruptible "rocksdb_writebatch_count"
                c_rocksdb_writebatch_count :: Ptr RocksdbWritebatch -> IO CInt
 
-foreign import ccall unsafe "rocksdb_writebatch_put"
+foreign import ccall interruptible "rocksdb_writebatch_put"
                c_rocksdb_writebatch_put ::
                Ptr RocksdbWritebatch ->
                  Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_put_cf"
+foreign import ccall interruptible "rocksdb_writebatch_put_cf"
                c_rocksdb_writebatch_put_cf ::
                Ptr RocksdbWritebatch ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_putv"
+foreign import ccall interruptible "rocksdb_writebatch_putv"
                c_rocksdb_writebatch_putv ::
                Ptr RocksdbWritebatch ->
                  CInt ->
                    Ptr (Ptr CChar) ->
                      Ptr CSize -> CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_putv_cf"
+foreign import ccall interruptible "rocksdb_writebatch_putv_cf"
                c_rocksdb_writebatch_putv_cf ::
                Ptr RocksdbWritebatch ->
                  Ptr RocksdbColumnFamilyHandle ->
@@ -485,25 +505,25 @@
                      Ptr (Ptr CChar) ->
                        Ptr CSize -> CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_merge"
+foreign import ccall interruptible "rocksdb_writebatch_merge"
                c_rocksdb_writebatch_merge ::
                Ptr RocksdbWritebatch ->
                  Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_merge_cf"
+foreign import ccall interruptible "rocksdb_writebatch_merge_cf"
                c_rocksdb_writebatch_merge_cf ::
                Ptr RocksdbWritebatch ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_mergev"
+foreign import ccall interruptible "rocksdb_writebatch_mergev"
                c_rocksdb_writebatch_mergev ::
                Ptr RocksdbWritebatch ->
                  CInt ->
                    Ptr (Ptr CChar) ->
                      Ptr CSize -> CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_mergev_cf"
+foreign import ccall interruptible "rocksdb_writebatch_mergev_cf"
                c_rocksdb_writebatch_mergev_cf ::
                Ptr RocksdbWritebatch ->
                  Ptr RocksdbColumnFamilyHandle ->
@@ -511,45 +531,49 @@
                      Ptr (Ptr CChar) ->
                        Ptr CSize -> CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_delete"
+foreign import ccall interruptible "rocksdb_writebatch_delete"
                c_rocksdb_writebatch_delete ::
                Ptr RocksdbWritebatch -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_delete_cf"
+foreign import ccall interruptible "rocksdb_writebatch_delete_cf"
                c_rocksdb_writebatch_delete_cf ::
                Ptr RocksdbWritebatch ->
                  Ptr RocksdbColumnFamilyHandle -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_deletev"
+foreign import ccall interruptible "rocksdb_writebatch_deletev"
                c_rocksdb_writebatch_deletev ::
                Ptr RocksdbWritebatch ->
                  CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_deletev_cf"
+foreign import ccall interruptible "rocksdb_writebatch_deletev_cf"
                c_rocksdb_writebatch_deletev_cf ::
                Ptr RocksdbWritebatch ->
                  Ptr RocksdbColumnFamilyHandle ->
                    CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_delete_range"
-               c_rocksdb_writebatch_delete_range ::
+foreign import ccall interruptible
+               "rocksdb_writebatch_delete_range" c_rocksdb_writebatch_delete_range
+               ::
                Ptr RocksdbWritebatch ->
                  Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_delete_range_cf"
+foreign import ccall interruptible
+               "rocksdb_writebatch_delete_range_cf"
                c_rocksdb_writebatch_delete_range_cf ::
                Ptr RocksdbWritebatch ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_delete_rangev"
+foreign import ccall interruptible
+               "rocksdb_writebatch_delete_rangev"
                c_rocksdb_writebatch_delete_rangev ::
                Ptr RocksdbWritebatch ->
                  CInt ->
                    Ptr (Ptr CChar) ->
                      Ptr CSize -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_delete_rangev_cf"
+foreign import ccall interruptible
+               "rocksdb_writebatch_delete_rangev_cf"
                c_rocksdb_writebatch_delete_rangev_cf ::
                Ptr RocksdbWritebatch ->
                  Ptr RocksdbColumnFamilyHandle ->
@@ -557,11 +581,11 @@
                      Ptr (Ptr CChar) ->
                        Ptr CSize -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_put_log_data"
-               c_rocksdb_writebatch_put_log_data ::
-               Ptr RocksdbWritebatch -> Ptr CChar -> CSize -> IO ()
+foreign import ccall interruptible
+               "rocksdb_writebatch_put_log_data" c_rocksdb_writebatch_put_log_data
+               :: Ptr RocksdbWritebatch -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_iterate"
+foreign import ccall interruptible "rocksdb_writebatch_iterate"
                c_rocksdb_writebatch_iterate ::
                Ptr RocksdbWritebatch ->
                  Ptr () ->
@@ -569,55 +593,57 @@
                      (Ptr () -> Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ())
                      -> FunPtr (Ptr () -> Ptr CChar -> CSize -> IO ()) -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_data"
+foreign import ccall interruptible "rocksdb_writebatch_data"
                c_rocksdb_writebatch_data ::
                Ptr RocksdbWritebatch -> Ptr CSize -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_writebatch_set_save_point"
+foreign import ccall interruptible
+               "rocksdb_writebatch_set_save_point"
                c_rocksdb_writebatch_set_save_point ::
                Ptr RocksdbWritebatch -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_writebatch_rollback_to_save_point"
                c_rocksdb_writebatch_rollback_to_save_point ::
                Ptr RocksdbWritebatch -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_pop_save_point"
+foreign import ccall interruptible
+               "rocksdb_writebatch_pop_save_point"
                c_rocksdb_writebatch_pop_save_point ::
                Ptr RocksdbWritebatch -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_create"
+foreign import ccall interruptible "rocksdb_writebatch_wi_create"
                c_rocksdb_writebatch_wi_create ::
                CSize -> CUChar -> IO (Ptr RocksdbWritebatchWi)
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_destroy"
+foreign import ccall interruptible "rocksdb_writebatch_wi_destroy"
                c_rocksdb_writebatch_wi_destroy :: Ptr RocksdbWritebatchWi -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_clear"
+foreign import ccall interruptible "rocksdb_writebatch_wi_clear"
                c_rocksdb_writebatch_wi_clear :: Ptr RocksdbWritebatchWi -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_count"
+foreign import ccall interruptible "rocksdb_writebatch_wi_count"
                c_rocksdb_writebatch_wi_count :: Ptr RocksdbWritebatchWi -> IO CInt
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_put"
+foreign import ccall interruptible "rocksdb_writebatch_wi_put"
                c_rocksdb_writebatch_wi_put ::
                Ptr RocksdbWritebatchWi ->
                  Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_put_cf"
+foreign import ccall interruptible "rocksdb_writebatch_wi_put_cf"
                c_rocksdb_writebatch_wi_put_cf ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_putv"
+foreign import ccall interruptible "rocksdb_writebatch_wi_putv"
                c_rocksdb_writebatch_wi_putv ::
                Ptr RocksdbWritebatchWi ->
                  CInt ->
                    Ptr (Ptr CChar) ->
                      Ptr CSize -> CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_putv_cf"
+foreign import ccall interruptible "rocksdb_writebatch_wi_putv_cf"
                c_rocksdb_writebatch_wi_putv_cf ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbColumnFamilyHandle ->
@@ -625,71 +651,77 @@
                      Ptr (Ptr CChar) ->
                        Ptr CSize -> CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_merge"
+foreign import ccall interruptible "rocksdb_writebatch_wi_merge"
                c_rocksdb_writebatch_wi_merge ::
                Ptr RocksdbWritebatchWi ->
                  Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_merge_cf"
+foreign import ccall interruptible "rocksdb_writebatch_wi_merge_cf"
                c_rocksdb_writebatch_wi_merge_cf ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_mergev"
+foreign import ccall interruptible "rocksdb_writebatch_wi_mergev"
                c_rocksdb_writebatch_wi_mergev ::
                Ptr RocksdbWritebatchWi ->
                  CInt ->
                    Ptr (Ptr CChar) ->
                      Ptr CSize -> CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_mergev_cf"
-               c_rocksdb_writebatch_wi_mergev_cf ::
+foreign import ccall interruptible
+               "rocksdb_writebatch_wi_mergev_cf" c_rocksdb_writebatch_wi_mergev_cf
+               ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbColumnFamilyHandle ->
                    CInt ->
                      Ptr (Ptr CChar) ->
                        Ptr CSize -> CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_delete"
+foreign import ccall interruptible "rocksdb_writebatch_wi_delete"
                c_rocksdb_writebatch_wi_delete ::
                Ptr RocksdbWritebatchWi -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_delete_cf"
-               c_rocksdb_writebatch_wi_delete_cf ::
+foreign import ccall interruptible
+               "rocksdb_writebatch_wi_delete_cf" c_rocksdb_writebatch_wi_delete_cf
+               ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbColumnFamilyHandle -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_deletev"
+foreign import ccall interruptible "rocksdb_writebatch_wi_deletev"
                c_rocksdb_writebatch_wi_deletev ::
                Ptr RocksdbWritebatchWi ->
                  CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_deletev_cf"
+foreign import ccall interruptible
+               "rocksdb_writebatch_wi_deletev_cf"
                c_rocksdb_writebatch_wi_deletev_cf ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbColumnFamilyHandle ->
                    CInt -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_delete_range"
+foreign import ccall interruptible
+               "rocksdb_writebatch_wi_delete_range"
                c_rocksdb_writebatch_wi_delete_range ::
                Ptr RocksdbWritebatchWi ->
                  Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_delete_range_cf"
+foreign import ccall interruptible
+               "rocksdb_writebatch_wi_delete_range_cf"
                c_rocksdb_writebatch_wi_delete_range_cf ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_delete_rangev"
+foreign import ccall interruptible
+               "rocksdb_writebatch_wi_delete_rangev"
                c_rocksdb_writebatch_wi_delete_rangev ::
                Ptr RocksdbWritebatchWi ->
                  CInt ->
                    Ptr (Ptr CChar) ->
                      Ptr CSize -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_writebatch_wi_delete_rangev_cf"
                c_rocksdb_writebatch_wi_delete_rangev_cf ::
                Ptr RocksdbWritebatchWi ->
@@ -698,11 +730,12 @@
                      Ptr (Ptr CChar) ->
                        Ptr CSize -> Ptr (Ptr CChar) -> Ptr CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_put_log_data"
+foreign import ccall interruptible
+               "rocksdb_writebatch_wi_put_log_data"
                c_rocksdb_writebatch_wi_put_log_data ::
                Ptr RocksdbWritebatchWi -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_iterate"
+foreign import ccall interruptible "rocksdb_writebatch_wi_iterate"
                c_rocksdb_writebatch_wi_iterate ::
                Ptr RocksdbWritebatchWi ->
                  Ptr () ->
@@ -710,27 +743,29 @@
                      (Ptr () -> Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO ())
                      -> FunPtr (Ptr () -> Ptr CChar -> CSize -> IO ()) -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_data"
+foreign import ccall interruptible "rocksdb_writebatch_wi_data"
                c_rocksdb_writebatch_wi_data ::
                Ptr RocksdbWritebatchWi -> Ptr CSize -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_set_save_point"
+foreign import ccall interruptible
+               "rocksdb_writebatch_wi_set_save_point"
                c_rocksdb_writebatch_wi_set_save_point ::
                Ptr RocksdbWritebatchWi -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_writebatch_wi_rollback_to_save_point"
                c_rocksdb_writebatch_wi_rollback_to_save_point ::
                Ptr RocksdbWritebatchWi -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_writebatch_wi_get_from_batch"
+foreign import ccall interruptible
+               "rocksdb_writebatch_wi_get_from_batch"
                c_rocksdb_writebatch_wi_get_from_batch ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbOptions ->
                    Ptr CChar ->
                      CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_writebatch_wi_get_from_batch_cf"
                c_rocksdb_writebatch_wi_get_from_batch_cf ::
                Ptr RocksdbWritebatchWi ->
@@ -739,7 +774,7 @@
                      Ptr CChar ->
                        CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_writebatch_wi_get_from_batch_and_db"
                c_rocksdb_writebatch_wi_get_from_batch_and_db ::
                Ptr RocksdbWritebatchWi ->
@@ -748,7 +783,7 @@
                      Ptr CChar ->
                        CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_writebatch_wi_get_from_batch_and_db_cf"
                c_rocksdb_writebatch_wi_get_from_batch_and_db_cf ::
                Ptr RocksdbWritebatchWi ->
@@ -758,75 +793,77 @@
                        Ptr CChar ->
                          CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_write_writebatch_wi"
+foreign import ccall interruptible "rocksdb_write_writebatch_wi"
                c_rocksdb_write_writebatch_wi ::
                Ptr Rocksdb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr RocksdbWritebatchWi -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_writebatch_wi_create_iterator_with_base"
                c_rocksdb_writebatch_wi_create_iterator_with_base ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbIterator -> IO (Ptr RocksdbIterator)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_writebatch_wi_create_iterator_with_base_cf"
                c_rocksdb_writebatch_wi_create_iterator_with_base_cf ::
                Ptr RocksdbWritebatchWi ->
                  Ptr RocksdbIterator ->
                    Ptr RocksdbColumnFamilyHandle -> IO (Ptr RocksdbIterator)
 
-foreign import ccall unsafe "rocksdb_block_based_options_create"
+foreign import ccall interruptible
+               "rocksdb_block_based_options_create"
                c_rocksdb_block_based_options_create ::
                IO (Ptr RocksdbBlockBasedTableOptions)
 
-foreign import ccall unsafe "rocksdb_block_based_options_destroy"
+foreign import ccall interruptible
+               "rocksdb_block_based_options_destroy"
                c_rocksdb_block_based_options_destroy ::
                Ptr RocksdbBlockBasedTableOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_block_size"
                c_rocksdb_block_based_options_set_block_size ::
                Ptr RocksdbBlockBasedTableOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_block_size_deviation"
                c_rocksdb_block_based_options_set_block_size_deviation ::
                Ptr RocksdbBlockBasedTableOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_block_restart_interval"
                c_rocksdb_block_based_options_set_block_restart_interval ::
                Ptr RocksdbBlockBasedTableOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_filter_policy"
                c_rocksdb_block_based_options_set_filter_policy ::
                Ptr RocksdbBlockBasedTableOptions ->
                  Ptr RocksdbFilterpolicy -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_no_block_cache"
                c_rocksdb_block_based_options_set_no_block_cache ::
                Ptr RocksdbBlockBasedTableOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_block_cache"
                c_rocksdb_block_based_options_set_block_cache ::
                Ptr RocksdbBlockBasedTableOptions -> Ptr RocksdbCache -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_block_cache_compressed"
                c_rocksdb_block_based_options_set_block_cache_compressed ::
                Ptr RocksdbBlockBasedTableOptions -> Ptr RocksdbCache -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_whole_key_filtering"
                c_rocksdb_block_based_options_set_whole_key_filtering ::
                Ptr RocksdbBlockBasedTableOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_format_version"
                c_rocksdb_block_based_options_set_format_version ::
                Ptr RocksdbBlockBasedTableOptions -> CInt -> IO ()
@@ -839,527 +876,553 @@
 
 c_rocksdb_block_based_table_index_type_two_level_index_search = 2
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_index_type"
                c_rocksdb_block_based_options_set_index_type ::
                Ptr RocksdbBlockBasedTableOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_hash_index_allow_collision"
                c_rocksdb_block_based_options_set_hash_index_allow_collision ::
                Ptr RocksdbBlockBasedTableOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_cache_index_and_filter_blocks"
                c_rocksdb_block_based_options_set_cache_index_and_filter_blocks ::
                Ptr RocksdbBlockBasedTableOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache"
                c_rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache
                :: Ptr RocksdbBlockBasedTableOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_block_based_table_factory"
                c_rocksdb_options_set_block_based_table_factory ::
                Ptr RocksdbOptions -> Ptr RocksdbBlockBasedTableOptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_cuckoo_options_create"
+foreign import ccall interruptible "rocksdb_cuckoo_options_create"
                c_rocksdb_cuckoo_options_create ::
                IO (Ptr RocksdbCuckooTableOptions)
 
-foreign import ccall unsafe "rocksdb_cuckoo_options_destroy"
+foreign import ccall interruptible "rocksdb_cuckoo_options_destroy"
                c_rocksdb_cuckoo_options_destroy ::
                Ptr RocksdbCuckooTableOptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_cuckoo_options_set_hash_ratio"
+foreign import ccall interruptible
+               "rocksdb_cuckoo_options_set_hash_ratio"
                c_rocksdb_cuckoo_options_set_hash_ratio ::
                Ptr RocksdbCuckooTableOptions -> CDouble -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_cuckoo_options_set_max_search_depth"
                c_rocksdb_cuckoo_options_set_max_search_depth ::
                Ptr RocksdbCuckooTableOptions -> Word32 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_cuckoo_options_set_cuckoo_block_size"
                c_rocksdb_cuckoo_options_set_cuckoo_block_size ::
                Ptr RocksdbCuckooTableOptions -> Word32 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_cuckoo_options_set_identity_as_first_hash"
                c_rocksdb_cuckoo_options_set_identity_as_first_hash ::
                Ptr RocksdbCuckooTableOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_cuckoo_options_set_use_module_hash"
                c_rocksdb_cuckoo_options_set_use_module_hash ::
                Ptr RocksdbCuckooTableOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_cuckoo_table_factory"
                c_rocksdb_options_set_cuckoo_table_factory ::
                Ptr RocksdbOptions -> Ptr RocksdbCuckooTableOptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_set_options"
+foreign import ccall interruptible "rocksdb_set_options"
                c_rocksdb_set_options ::
                Ptr Rocksdb ->
                  CInt ->
                    Ptr (Ptr CChar) -> Ptr (Ptr CChar) -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_create"
+foreign import ccall interruptible "rocksdb_options_create"
                c_rocksdb_options_create :: IO (Ptr RocksdbOptions)
 
-foreign import ccall unsafe "rocksdb_options_destroy"
+foreign import ccall interruptible "rocksdb_options_destroy"
                c_rocksdb_options_destroy :: Ptr RocksdbOptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_increase_parallelism"
+foreign import ccall interruptible
+               "rocksdb_options_increase_parallelism"
                c_rocksdb_options_increase_parallelism ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_optimize_for_point_lookup"
                c_rocksdb_options_optimize_for_point_lookup ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_optimize_level_style_compaction"
                c_rocksdb_options_optimize_level_style_compaction ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_optimize_universal_style_compaction"
                c_rocksdb_options_optimize_universal_style_compaction ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_compaction_filter"
+foreign import ccall interruptible
+               "rocksdb_options_set_compaction_filter"
                c_rocksdb_options_set_compaction_filter ::
                Ptr RocksdbOptions -> Ptr RocksdbCompactionfilter -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_compaction_filter_factory"
                c_rocksdb_options_set_compaction_filter_factory ::
                Ptr RocksdbOptions -> Ptr RocksdbCompactionfilterfactory -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_compaction_readahead_size"
                c_rocksdb_options_compaction_readahead_size ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_comparator"
+foreign import ccall interruptible "rocksdb_options_set_comparator"
                c_rocksdb_options_set_comparator ::
                Ptr RocksdbOptions -> Ptr RocksdbComparator -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_merge_operator"
+foreign import ccall interruptible
+               "rocksdb_options_set_merge_operator"
                c_rocksdb_options_set_merge_operator ::
                Ptr RocksdbOptions -> Ptr RocksdbMergeoperator -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_uint64add_merge_operator"
                c_rocksdb_options_set_uint64add_merge_operator ::
                Ptr RocksdbOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_compression_per_level"
                c_rocksdb_options_set_compression_per_level ::
                Ptr RocksdbOptions -> Ptr CInt -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_create_if_missing"
+foreign import ccall interruptible
+               "rocksdb_options_set_create_if_missing"
                c_rocksdb_options_set_create_if_missing ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_create_missing_column_families"
                c_rocksdb_options_set_create_missing_column_families ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_error_if_exists"
+foreign import ccall interruptible
+               "rocksdb_options_set_error_if_exists"
                c_rocksdb_options_set_error_if_exists ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_paranoid_checks"
+foreign import ccall interruptible
+               "rocksdb_options_set_paranoid_checks"
                c_rocksdb_options_set_paranoid_checks ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_db_paths"
+foreign import ccall interruptible "rocksdb_options_set_db_paths"
                c_rocksdb_options_set_db_paths ::
                Ptr RocksdbOptions -> Ptr (Ptr RocksdbDbpath) -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_env"
+foreign import ccall interruptible "rocksdb_options_set_env"
                c_rocksdb_options_set_env ::
                Ptr RocksdbOptions -> Ptr RocksdbEnv -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_info_log"
+foreign import ccall interruptible "rocksdb_options_set_info_log"
                c_rocksdb_options_set_info_log ::
                Ptr RocksdbOptions -> Ptr RocksdbLogger -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_info_log_level"
+foreign import ccall interruptible
+               "rocksdb_options_set_info_log_level"
                c_rocksdb_options_set_info_log_level ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_write_buffer_size"
+foreign import ccall interruptible
+               "rocksdb_options_set_write_buffer_size"
                c_rocksdb_options_set_write_buffer_size ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_db_write_buffer_size"
                c_rocksdb_options_set_db_write_buffer_size ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_max_open_files"
+foreign import ccall interruptible
+               "rocksdb_options_set_max_open_files"
                c_rocksdb_options_set_max_open_files ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_file_opening_threads"
                c_rocksdb_options_set_max_file_opening_threads ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_total_wal_size"
                c_rocksdb_options_set_max_total_wal_size ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_compression_options"
                c_rocksdb_options_set_compression_options ::
                Ptr RocksdbOptions -> CInt -> CInt -> CInt -> CInt -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_prefix_extractor"
+foreign import ccall interruptible
+               "rocksdb_options_set_prefix_extractor"
                c_rocksdb_options_set_prefix_extractor ::
                Ptr RocksdbOptions -> Ptr RocksdbSlicetransform -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_num_levels"
+foreign import ccall interruptible "rocksdb_options_set_num_levels"
                c_rocksdb_options_set_num_levels ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_level0_file_num_compaction_trigger"
                c_rocksdb_options_set_level0_file_num_compaction_trigger ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_level0_slowdown_writes_trigger"
                c_rocksdb_options_set_level0_slowdown_writes_trigger ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_level0_stop_writes_trigger"
                c_rocksdb_options_set_level0_stop_writes_trigger ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_mem_compaction_level"
                c_rocksdb_options_set_max_mem_compaction_level ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_target_file_size_base"
                c_rocksdb_options_set_target_file_size_base ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_target_file_size_multiplier"
                c_rocksdb_options_set_target_file_size_multiplier ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_bytes_for_level_base"
                c_rocksdb_options_set_max_bytes_for_level_base ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_level_compaction_dynamic_level_bytes"
                c_rocksdb_options_set_level_compaction_dynamic_level_bytes ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_bytes_for_level_multiplier"
                c_rocksdb_options_set_max_bytes_for_level_multiplier ::
                Ptr RocksdbOptions -> CDouble -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_bytes_for_level_multiplier_additional"
                c_rocksdb_options_set_max_bytes_for_level_multiplier_additional ::
                Ptr RocksdbOptions -> Ptr CInt -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_enable_statistics"
+foreign import ccall interruptible
+               "rocksdb_options_enable_statistics"
                c_rocksdb_options_enable_statistics :: Ptr RocksdbOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_skip_stats_update_on_db_open"
                c_rocksdb_options_set_skip_stats_update_on_db_open ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_statistics_get_string"
+foreign import ccall interruptible
+               "rocksdb_options_statistics_get_string"
                c_rocksdb_options_statistics_get_string ::
                Ptr RocksdbOptions -> IO (Ptr CChar)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_write_buffer_number"
                c_rocksdb_options_set_max_write_buffer_number ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_min_write_buffer_number_to_merge"
                c_rocksdb_options_set_min_write_buffer_number_to_merge ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_write_buffer_number_to_maintain"
                c_rocksdb_options_set_max_write_buffer_number_to_maintain ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_background_compactions"
                c_rocksdb_options_set_max_background_compactions ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_base_background_compactions"
                c_rocksdb_options_set_base_background_compactions ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_background_flushes"
                c_rocksdb_options_set_max_background_flushes ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_max_log_file_size"
+foreign import ccall interruptible
+               "rocksdb_options_set_max_log_file_size"
                c_rocksdb_options_set_max_log_file_size ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_log_file_time_to_roll"
                c_rocksdb_options_set_log_file_time_to_roll ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_keep_log_file_num"
+foreign import ccall interruptible
+               "rocksdb_options_set_keep_log_file_num"
                c_rocksdb_options_set_keep_log_file_num ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_recycle_log_file_num"
                c_rocksdb_options_set_recycle_log_file_num ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_soft_rate_limit"
+foreign import ccall interruptible
+               "rocksdb_options_set_soft_rate_limit"
                c_rocksdb_options_set_soft_rate_limit ::
                Ptr RocksdbOptions -> CDouble -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_hard_rate_limit"
+foreign import ccall interruptible
+               "rocksdb_options_set_hard_rate_limit"
                c_rocksdb_options_set_hard_rate_limit ::
                Ptr RocksdbOptions -> CDouble -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_soft_pending_compaction_bytes_limit"
                c_rocksdb_options_set_soft_pending_compaction_bytes_limit ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_hard_pending_compaction_bytes_limit"
                c_rocksdb_options_set_hard_pending_compaction_bytes_limit ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_rate_limit_delay_max_milliseconds"
                c_rocksdb_options_set_rate_limit_delay_max_milliseconds ::
                Ptr RocksdbOptions -> CUInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_manifest_file_size"
                c_rocksdb_options_set_max_manifest_file_size ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_table_cache_numshardbits"
                c_rocksdb_options_set_table_cache_numshardbits ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_table_cache_remove_scan_count_limit"
                c_rocksdb_options_set_table_cache_remove_scan_count_limit ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_arena_block_size"
+foreign import ccall interruptible
+               "rocksdb_options_set_arena_block_size"
                c_rocksdb_options_set_arena_block_size ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_use_fsync"
+foreign import ccall interruptible "rocksdb_options_set_use_fsync"
                c_rocksdb_options_set_use_fsync ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_db_log_dir"
+foreign import ccall interruptible "rocksdb_options_set_db_log_dir"
                c_rocksdb_options_set_db_log_dir ::
                Ptr RocksdbOptions -> Ptr CChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_wal_dir"
+foreign import ccall interruptible "rocksdb_options_set_wal_dir"
                c_rocksdb_options_set_wal_dir ::
                Ptr RocksdbOptions -> Ptr CChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_WAL_ttl_seconds"
+foreign import ccall interruptible
+               "rocksdb_options_set_WAL_ttl_seconds"
                c_rocksdb_options_set_WAL_ttl_seconds ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_WAL_size_limit_MB"
+foreign import ccall interruptible
+               "rocksdb_options_set_WAL_size_limit_MB"
                c_rocksdb_options_set_WAL_size_limit_MB ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_manifest_preallocation_size"
                c_rocksdb_options_set_manifest_preallocation_size ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_purge_redundant_kvs_while_flush"
                c_rocksdb_options_set_purge_redundant_kvs_while_flush ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_allow_mmap_reads"
+foreign import ccall interruptible
+               "rocksdb_options_set_allow_mmap_reads"
                c_rocksdb_options_set_allow_mmap_reads ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_allow_mmap_writes"
+foreign import ccall interruptible
+               "rocksdb_options_set_allow_mmap_writes"
                c_rocksdb_options_set_allow_mmap_writes ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_use_direct_reads"
+foreign import ccall interruptible
+               "rocksdb_options_set_use_direct_reads"
                c_rocksdb_options_set_use_direct_reads ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_use_direct_io_for_flush_and_compaction"
                c_rocksdb_options_set_use_direct_io_for_flush_and_compaction ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_is_fd_close_on_exec"
                c_rocksdb_options_set_is_fd_close_on_exec ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_skip_log_error_on_recovery"
                c_rocksdb_options_set_skip_log_error_on_recovery ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_stats_dump_period_sec"
                c_rocksdb_options_set_stats_dump_period_sec ::
                Ptr RocksdbOptions -> CUInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_advise_random_on_open"
                c_rocksdb_options_set_advise_random_on_open ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_access_hint_on_compaction_start"
                c_rocksdb_options_set_access_hint_on_compaction_start ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_use_adaptive_mutex"
                c_rocksdb_options_set_use_adaptive_mutex ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_bytes_per_sync"
+foreign import ccall interruptible
+               "rocksdb_options_set_bytes_per_sync"
                c_rocksdb_options_set_bytes_per_sync ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_allow_concurrent_memtable_write"
                c_rocksdb_options_set_allow_concurrent_memtable_write ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_enable_write_thread_adaptive_yield"
                c_rocksdb_options_set_enable_write_thread_adaptive_yield ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_sequential_skip_in_iterations"
                c_rocksdb_options_set_max_sequential_skip_in_iterations ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_disable_auto_compactions"
                c_rocksdb_options_set_disable_auto_compactions ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_optimize_filters_for_hits"
                c_rocksdb_options_set_optimize_filters_for_hits ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_delete_obsolete_files_period_micros"
                c_rocksdb_options_set_delete_obsolete_files_period_micros ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_prepare_for_bulk_load"
+foreign import ccall interruptible
+               "rocksdb_options_prepare_for_bulk_load"
                c_rocksdb_options_prepare_for_bulk_load ::
                Ptr RocksdbOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_memtable_vector_rep"
                c_rocksdb_options_set_memtable_vector_rep ::
                Ptr RocksdbOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_memtable_prefix_bloom_size_ratio"
                c_rocksdb_options_set_memtable_prefix_bloom_size_ratio ::
                Ptr RocksdbOptions -> CDouble -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_compaction_bytes"
                c_rocksdb_options_set_max_compaction_bytes ::
                Ptr RocksdbOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_hash_skip_list_rep"
                c_rocksdb_options_set_hash_skip_list_rep ::
                Ptr RocksdbOptions -> CSize -> Int32 -> Int32 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_hash_link_list_rep"
                c_rocksdb_options_set_hash_link_list_rep ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_plain_table_factory"
                c_rocksdb_options_set_plain_table_factory ::
                Ptr RocksdbOptions -> Word32 -> CInt -> CDouble -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_min_level_to_compress"
                c_rocksdb_options_set_min_level_to_compress ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_memtable_huge_page_size"
                c_rocksdb_options_set_memtable_huge_page_size ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_max_successive_merges"
                c_rocksdb_options_set_max_successive_merges ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_bloom_locality"
+foreign import ccall interruptible
+               "rocksdb_options_set_bloom_locality"
                c_rocksdb_options_set_bloom_locality ::
                Ptr RocksdbOptions -> Word32 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_inplace_update_support"
                c_rocksdb_options_set_inplace_update_support ::
                Ptr RocksdbOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_inplace_update_num_locks"
                c_rocksdb_options_set_inplace_update_num_locks ::
                Ptr RocksdbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_report_bg_io_stats"
                c_rocksdb_options_set_report_bg_io_stats ::
                Ptr RocksdbOptions -> CInt -> IO ()
@@ -1374,7 +1437,8 @@
 
 c_rocksdb_skip_any_corrupted_records_recovery = 3
 
-foreign import ccall unsafe "rocksdb_options_set_wal_recovery_mode"
+foreign import ccall interruptible
+               "rocksdb_options_set_wal_recovery_mode"
                c_rocksdb_options_set_wal_recovery_mode ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
@@ -1396,9 +1460,9 @@
 
 c_rocksdb_zstd_compression = 7
 
-foreign import ccall unsafe "rocksdb_options_set_compression"
-               c_rocksdb_options_set_compression ::
-               Ptr RocksdbOptions -> CInt -> IO ()
+foreign import ccall interruptible
+               "rocksdb_options_set_compression" c_rocksdb_options_set_compression
+               :: Ptr RocksdbOptions -> CInt -> IO ()
 
 c_rocksdb_level_compaction, c_rocksdb_universal_compaction, c_rocksdb_fifo_compaction ::
      CInt
@@ -1408,34 +1472,36 @@
 
 c_rocksdb_fifo_compaction = 2
 
-foreign import ccall unsafe "rocksdb_options_set_compaction_style"
+foreign import ccall interruptible
+               "rocksdb_options_set_compaction_style"
                c_rocksdb_options_set_compaction_style ::
                Ptr RocksdbOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_universal_compaction_options"
                c_rocksdb_options_set_universal_compaction_options ::
                Ptr RocksdbOptions ->
                  Ptr RocksdbUniversalCompactionOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_options_set_fifo_compaction_options"
                c_rocksdb_options_set_fifo_compaction_options ::
                Ptr RocksdbOptions -> Ptr RocksdbFifoCompactionOptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_options_set_ratelimiter"
-               c_rocksdb_options_set_ratelimiter ::
-               Ptr RocksdbOptions -> Ptr RocksdbRatelimiter -> IO ()
+foreign import ccall interruptible
+               "rocksdb_options_set_ratelimiter" c_rocksdb_options_set_ratelimiter
+               :: Ptr RocksdbOptions -> Ptr RocksdbRatelimiter -> IO ()
 
-foreign import ccall unsafe "rocksdb_ratelimiter_create"
+foreign import ccall interruptible "rocksdb_ratelimiter_create"
                c_rocksdb_ratelimiter_create ::
                Int64 -> Int64 -> Int32 -> IO (Ptr RocksdbRatelimiter)
 
-foreign import ccall unsafe "rocksdb_ratelimiter_destroy"
+foreign import ccall interruptible "rocksdb_ratelimiter_destroy"
                c_rocksdb_ratelimiter_destroy :: Ptr RocksdbRatelimiter -> IO ()
 
-foreign import ccall unsafe "rocksdb_compactionfilter_create"
-               c_rocksdb_compactionfilter_create ::
+foreign import ccall interruptible
+               "rocksdb_compactionfilter_create" c_rocksdb_compactionfilter_create
+               ::
                Ptr () ->
                  FunPtr (Ptr () -> IO ()) ->
                    FunPtr
@@ -1449,26 +1515,27 @@
                      FunPtr (Ptr () -> IO (Ptr CChar)) ->
                        IO (Ptr RocksdbCompactionfilter)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_compactionfilter_set_ignore_snapshots"
                c_rocksdb_compactionfilter_set_ignore_snapshots ::
                Ptr RocksdbCompactionfilter -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_compactionfilter_destroy"
+foreign import ccall interruptible
+               "rocksdb_compactionfilter_destroy"
                c_rocksdb_compactionfilter_destroy ::
                Ptr RocksdbCompactionfilter -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_compactionfiltercontext_is_full_compaction"
                c_rocksdb_compactionfiltercontext_is_full_compaction ::
                Ptr RocksdbCompactionfiltercontext -> IO CUChar
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_compactionfiltercontext_is_manual_compaction"
                c_rocksdb_compactionfiltercontext_is_manual_compaction ::
                Ptr RocksdbCompactionfiltercontext -> IO CUChar
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_compactionfilterfactory_create"
                c_rocksdb_compactionfilterfactory_create ::
                Ptr () ->
@@ -1481,12 +1548,12 @@
                      FunPtr (Ptr () -> IO (Ptr CChar)) ->
                        IO (Ptr RocksdbCompactionfilterfactory)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_compactionfilterfactory_destroy"
                c_rocksdb_compactionfilterfactory_destroy ::
                Ptr RocksdbCompactionfilterfactory -> IO ()
 
-foreign import ccall unsafe "rocksdb_comparator_create"
+foreign import ccall interruptible "rocksdb_comparator_create"
                c_rocksdb_comparator_create ::
                Ptr () ->
                  FunPtr (Ptr () -> IO ()) ->
@@ -1494,10 +1561,10 @@
                      (Ptr () -> Ptr CChar -> CSize -> Ptr CChar -> CSize -> IO CInt)
                      -> FunPtr (Ptr () -> IO (Ptr CChar)) -> IO (Ptr RocksdbComparator)
 
-foreign import ccall unsafe "rocksdb_comparator_destroy"
+foreign import ccall interruptible "rocksdb_comparator_destroy"
                c_rocksdb_comparator_destroy :: Ptr RocksdbComparator -> IO ()
 
-foreign import ccall unsafe "rocksdb_filterpolicy_create"
+foreign import ccall interruptible "rocksdb_filterpolicy_create"
                c_rocksdb_filterpolicy_create ::
                Ptr () ->
                  FunPtr (Ptr () -> IO ()) ->
@@ -1512,19 +1579,20 @@
                        FunPtr (Ptr () -> Ptr CChar -> CSize -> IO ()) ->
                          FunPtr (Ptr () -> IO CChar) -> IO (Ptr RocksdbFilterpolicy)
 
-foreign import ccall unsafe "rocksdb_filterpolicy_destroy"
+foreign import ccall interruptible "rocksdb_filterpolicy_destroy"
                c_rocksdb_filterpolicy_destroy :: Ptr RocksdbFilterpolicy -> IO ()
 
-foreign import ccall unsafe "rocksdb_filterpolicy_create_bloom"
+foreign import ccall interruptible
+               "rocksdb_filterpolicy_create_bloom"
                c_rocksdb_filterpolicy_create_bloom ::
                CInt -> IO (Ptr RocksdbFilterpolicy)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_filterpolicy_create_bloom_full"
                c_rocksdb_filterpolicy_create_bloom_full ::
                CInt -> IO (Ptr RocksdbFilterpolicy)
 
-foreign import ccall unsafe "rocksdb_mergeoperator_create"
+foreign import ccall interruptible "rocksdb_mergeoperator_create"
                c_rocksdb_mergeoperator_create ::
                Ptr () ->
                  FunPtr (Ptr () -> IO ()) ->
@@ -1547,244 +1615,251 @@
                        FunPtr (Ptr () -> Ptr CChar -> CSize -> IO ()) ->
                          FunPtr (Ptr () -> IO (Ptr CChar)) -> IO (Ptr RocksdbMergeoperator)
 
-foreign import ccall unsafe "rocksdb_mergeoperator_destroy"
+foreign import ccall interruptible "rocksdb_mergeoperator_destroy"
                c_rocksdb_mergeoperator_destroy ::
                Ptr RocksdbMergeoperator -> IO ()
 
-foreign import ccall unsafe "rocksdb_readoptions_create"
+foreign import ccall interruptible "rocksdb_readoptions_create"
                c_rocksdb_readoptions_create :: IO (Ptr RocksdbReadoptions)
 
-foreign import ccall unsafe "rocksdb_readoptions_destroy"
+foreign import ccall interruptible "rocksdb_readoptions_destroy"
                c_rocksdb_readoptions_destroy :: Ptr RocksdbReadoptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_readoptions_set_verify_checksums"
                c_rocksdb_readoptions_set_verify_checksums ::
                Ptr RocksdbReadoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_readoptions_set_fill_cache"
+foreign import ccall interruptible
+               "rocksdb_readoptions_set_fill_cache"
                c_rocksdb_readoptions_set_fill_cache ::
                Ptr RocksdbReadoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_readoptions_set_snapshot"
+foreign import ccall interruptible
+               "rocksdb_readoptions_set_snapshot"
                c_rocksdb_readoptions_set_snapshot ::
                Ptr RocksdbReadoptions -> Ptr RocksdbSnapshot -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_readoptions_set_iterate_upper_bound"
                c_rocksdb_readoptions_set_iterate_upper_bound ::
                Ptr RocksdbReadoptions -> Ptr CChar -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_readoptions_set_read_tier"
+foreign import ccall interruptible
+               "rocksdb_readoptions_set_read_tier"
                c_rocksdb_readoptions_set_read_tier ::
                Ptr RocksdbReadoptions -> CInt -> IO ()
 
-foreign import ccall unsafe "rocksdb_readoptions_set_tailing"
-               c_rocksdb_readoptions_set_tailing ::
-               Ptr RocksdbReadoptions -> CUChar -> IO ()
+foreign import ccall interruptible
+               "rocksdb_readoptions_set_tailing" c_rocksdb_readoptions_set_tailing
+               :: Ptr RocksdbReadoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_readoptions_set_readahead_size"
                c_rocksdb_readoptions_set_readahead_size ::
                Ptr RocksdbReadoptions -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_readoptions_set_pin_data"
+foreign import ccall interruptible
+               "rocksdb_readoptions_set_pin_data"
                c_rocksdb_readoptions_set_pin_data ::
                Ptr RocksdbReadoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_readoptions_set_total_order_seek"
                c_rocksdb_readoptions_set_total_order_seek ::
                Ptr RocksdbReadoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_writeoptions_create"
+foreign import ccall interruptible "rocksdb_writeoptions_create"
                c_rocksdb_writeoptions_create :: IO (Ptr RocksdbWriteoptions)
 
-foreign import ccall unsafe "rocksdb_writeoptions_destroy"
+foreign import ccall interruptible "rocksdb_writeoptions_destroy"
                c_rocksdb_writeoptions_destroy :: Ptr RocksdbWriteoptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_writeoptions_set_sync"
+foreign import ccall interruptible "rocksdb_writeoptions_set_sync"
                c_rocksdb_writeoptions_set_sync ::
                Ptr RocksdbWriteoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_writeoptions_disable_WAL"
+foreign import ccall interruptible
+               "rocksdb_writeoptions_disable_WAL"
                c_rocksdb_writeoptions_disable_WAL ::
                Ptr RocksdbWriteoptions -> CInt -> IO ()
 
-foreign import ccall unsafe "rocksdb_compactoptions_create"
+foreign import ccall interruptible "rocksdb_compactoptions_create"
                c_rocksdb_compactoptions_create :: IO (Ptr RocksdbCompactoptions)
 
-foreign import ccall unsafe "rocksdb_compactoptions_destroy"
+foreign import ccall interruptible "rocksdb_compactoptions_destroy"
                c_rocksdb_compactoptions_destroy ::
                Ptr RocksdbCompactoptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_compactoptions_set_exclusive_manual_compaction"
                c_rocksdb_compactoptions_set_exclusive_manual_compaction ::
                Ptr RocksdbCompactoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_compactoptions_set_change_level"
                c_rocksdb_compactoptions_set_change_level ::
                Ptr RocksdbCompactoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_compactoptions_set_target_level"
                c_rocksdb_compactoptions_set_target_level ::
                Ptr RocksdbCompactoptions -> CInt -> IO ()
 
-foreign import ccall unsafe "rocksdb_flushoptions_create"
+foreign import ccall interruptible "rocksdb_flushoptions_create"
                c_rocksdb_flushoptions_create :: IO (Ptr RocksdbFlushoptions)
 
-foreign import ccall unsafe "rocksdb_flushoptions_destroy"
+foreign import ccall interruptible "rocksdb_flushoptions_destroy"
                c_rocksdb_flushoptions_destroy :: Ptr RocksdbFlushoptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_flushoptions_set_wait"
+foreign import ccall interruptible "rocksdb_flushoptions_set_wait"
                c_rocksdb_flushoptions_set_wait ::
                Ptr RocksdbFlushoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_cache_create_lru"
+foreign import ccall interruptible "rocksdb_cache_create_lru"
                c_rocksdb_cache_create_lru :: CSize -> IO (Ptr RocksdbCache)
 
-foreign import ccall unsafe "rocksdb_cache_destroy"
+foreign import ccall interruptible "rocksdb_cache_destroy"
                c_rocksdb_cache_destroy :: Ptr RocksdbCache -> IO ()
 
-foreign import ccall unsafe "rocksdb_cache_set_capacity"
+foreign import ccall interruptible "rocksdb_cache_set_capacity"
                c_rocksdb_cache_set_capacity :: Ptr RocksdbCache -> CSize -> IO ()
 
-foreign import ccall unsafe "rocksdb_cache_get_usage"
+foreign import ccall interruptible "rocksdb_cache_get_usage"
                c_rocksdb_cache_get_usage :: Ptr RocksdbCache -> IO CSize
 
-foreign import ccall unsafe "rocksdb_cache_get_pinned_usage"
+foreign import ccall interruptible "rocksdb_cache_get_pinned_usage"
                c_rocksdb_cache_get_pinned_usage :: Ptr RocksdbCache -> IO CSize
 
-foreign import ccall unsafe "rocksdb_dbpath_create"
+foreign import ccall interruptible "rocksdb_dbpath_create"
                c_rocksdb_dbpath_create ::
                Ptr CChar -> Word64 -> IO (Ptr RocksdbDbpath)
 
-foreign import ccall unsafe "rocksdb_dbpath_destroy"
+foreign import ccall interruptible "rocksdb_dbpath_destroy"
                c_rocksdb_dbpath_destroy :: Ptr RocksdbDbpath -> IO ()
 
-foreign import ccall unsafe "rocksdb_create_default_env"
+foreign import ccall interruptible "rocksdb_create_default_env"
                c_rocksdb_create_default_env :: IO (Ptr RocksdbEnv)
 
-foreign import ccall unsafe "rocksdb_create_mem_env"
+foreign import ccall interruptible "rocksdb_create_mem_env"
                c_rocksdb_create_mem_env :: IO (Ptr RocksdbEnv)
 
-foreign import ccall unsafe "rocksdb_env_set_background_threads"
+foreign import ccall interruptible
+               "rocksdb_env_set_background_threads"
                c_rocksdb_env_set_background_threads ::
                Ptr RocksdbEnv -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_env_set_high_priority_background_threads"
                c_rocksdb_env_set_high_priority_background_threads ::
                Ptr RocksdbEnv -> CInt -> IO ()
 
-foreign import ccall unsafe "rocksdb_env_join_all_threads"
+foreign import ccall interruptible "rocksdb_env_join_all_threads"
                c_rocksdb_env_join_all_threads :: Ptr RocksdbEnv -> IO ()
 
-foreign import ccall unsafe "rocksdb_env_destroy"
+foreign import ccall interruptible "rocksdb_env_destroy"
                c_rocksdb_env_destroy :: Ptr RocksdbEnv -> IO ()
 
-foreign import ccall unsafe "rocksdb_envoptions_create"
+foreign import ccall interruptible "rocksdb_envoptions_create"
                c_rocksdb_envoptions_create :: IO (Ptr RocksdbEnvoptions)
 
-foreign import ccall unsafe "rocksdb_envoptions_destroy"
+foreign import ccall interruptible "rocksdb_envoptions_destroy"
                c_rocksdb_envoptions_destroy :: Ptr RocksdbEnvoptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_sstfilewriter_create"
+foreign import ccall interruptible "rocksdb_sstfilewriter_create"
                c_rocksdb_sstfilewriter_create ::
                Ptr RocksdbEnvoptions ->
                  Ptr RocksdbOptions -> IO (Ptr RocksdbSstfilewriter)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_sstfilewriter_create_with_comparator"
                c_rocksdb_sstfilewriter_create_with_comparator ::
                Ptr RocksdbEnvoptions ->
                  Ptr RocksdbOptions ->
                    Ptr RocksdbComparator -> IO (Ptr RocksdbSstfilewriter)
 
-foreign import ccall unsafe "rocksdb_sstfilewriter_open"
+foreign import ccall interruptible "rocksdb_sstfilewriter_open"
                c_rocksdb_sstfilewriter_open ::
                Ptr RocksdbSstfilewriter -> Ptr CChar -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_sstfilewriter_add"
+foreign import ccall interruptible "rocksdb_sstfilewriter_add"
                c_rocksdb_sstfilewriter_add ::
                Ptr RocksdbSstfilewriter ->
                  Ptr CChar ->
                    CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_sstfilewriter_put"
+foreign import ccall interruptible "rocksdb_sstfilewriter_put"
                c_rocksdb_sstfilewriter_put ::
                Ptr RocksdbSstfilewriter ->
                  Ptr CChar ->
                    CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_sstfilewriter_merge"
+foreign import ccall interruptible "rocksdb_sstfilewriter_merge"
                c_rocksdb_sstfilewriter_merge ::
                Ptr RocksdbSstfilewriter ->
                  Ptr CChar ->
                    CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_sstfilewriter_delete"
+foreign import ccall interruptible "rocksdb_sstfilewriter_delete"
                c_rocksdb_sstfilewriter_delete ::
                Ptr RocksdbSstfilewriter ->
                  Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_sstfilewriter_finish"
+foreign import ccall interruptible "rocksdb_sstfilewriter_finish"
                c_rocksdb_sstfilewriter_finish ::
                Ptr RocksdbSstfilewriter -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_sstfilewriter_destroy"
+foreign import ccall interruptible "rocksdb_sstfilewriter_destroy"
                c_rocksdb_sstfilewriter_destroy ::
                Ptr RocksdbSstfilewriter -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_ingestexternalfileoptions_create"
                c_rocksdb_ingestexternalfileoptions_create ::
                IO (Ptr RocksdbIngestexternalfileoptions)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_ingestexternalfileoptions_set_move_files"
                c_rocksdb_ingestexternalfileoptions_set_move_files ::
                Ptr RocksdbIngestexternalfileoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_ingestexternalfileoptions_set_snapshot_consistency"
                c_rocksdb_ingestexternalfileoptions_set_snapshot_consistency ::
                Ptr RocksdbIngestexternalfileoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_ingestexternalfileoptions_set_allow_global_seqno"
                c_rocksdb_ingestexternalfileoptions_set_allow_global_seqno ::
                Ptr RocksdbIngestexternalfileoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_ingestexternalfileoptions_set_allow_blocking_flush"
                c_rocksdb_ingestexternalfileoptions_set_allow_blocking_flush ::
                Ptr RocksdbIngestexternalfileoptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_ingestexternalfileoptions_destroy"
                c_rocksdb_ingestexternalfileoptions_destroy ::
                Ptr RocksdbIngestexternalfileoptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_ingest_external_file"
+foreign import ccall interruptible "rocksdb_ingest_external_file"
                c_rocksdb_ingest_external_file ::
                Ptr Rocksdb ->
                  Ptr (Ptr CChar) ->
                    CSize ->
                      Ptr RocksdbIngestexternalfileoptions -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_ingest_external_file_cf"
-               c_rocksdb_ingest_external_file_cf ::
+foreign import ccall interruptible
+               "rocksdb_ingest_external_file_cf" c_rocksdb_ingest_external_file_cf
+               ::
                Ptr Rocksdb ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr (Ptr CChar) ->
                      CSize ->
                        Ptr RocksdbIngestexternalfileoptions -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_slicetransform_create"
+foreign import ccall interruptible "rocksdb_slicetransform_create"
                c_rocksdb_slicetransform_create ::
                Ptr () ->
                  FunPtr (Ptr () -> IO ()) ->
@@ -1795,16 +1870,17 @@
                        FunPtr (Ptr () -> Ptr CChar -> CSize -> IO CUChar) ->
                          FunPtr (Ptr () -> IO (Ptr CChar)) -> IO (Ptr RocksdbSlicetransform)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_slicetransform_create_fixed_prefix"
                c_rocksdb_slicetransform_create_fixed_prefix ::
                CSize -> IO (Ptr RocksdbSlicetransform)
 
-foreign import ccall unsafe "rocksdb_slicetransform_create_noop"
+foreign import ccall interruptible
+               "rocksdb_slicetransform_create_noop"
                c_rocksdb_slicetransform_create_noop ::
                IO (Ptr RocksdbSlicetransform)
 
-foreign import ccall unsafe "rocksdb_slicetransform_destroy"
+foreign import ccall interruptible "rocksdb_slicetransform_destroy"
                c_rocksdb_slicetransform_destroy ::
                Ptr RocksdbSlicetransform -> IO ()
 
@@ -1814,157 +1890,161 @@
 
 c_rocksdb_total_size_compaction_stop_style = 1
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_universal_compaction_options_create"
                c_rocksdb_universal_compaction_options_create ::
                IO (Ptr RocksdbUniversalCompactionOptions)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_universal_compaction_options_set_size_ratio"
                c_rocksdb_universal_compaction_options_set_size_ratio ::
                Ptr RocksdbUniversalCompactionOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_universal_compaction_options_set_min_merge_width"
                c_rocksdb_universal_compaction_options_set_min_merge_width ::
                Ptr RocksdbUniversalCompactionOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_universal_compaction_options_set_max_merge_width"
                c_rocksdb_universal_compaction_options_set_max_merge_width ::
                Ptr RocksdbUniversalCompactionOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_universal_compaction_options_set_max_size_amplification_percent"
                c_rocksdb_universal_compaction_options_set_max_size_amplification_percent
                :: Ptr RocksdbUniversalCompactionOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_universal_compaction_options_set_compression_size_percent"
                c_rocksdb_universal_compaction_options_set_compression_size_percent
                :: Ptr RocksdbUniversalCompactionOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_universal_compaction_options_set_stop_style"
                c_rocksdb_universal_compaction_options_set_stop_style ::
                Ptr RocksdbUniversalCompactionOptions -> CInt -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_universal_compaction_options_destroy"
                c_rocksdb_universal_compaction_options_destroy ::
                Ptr RocksdbUniversalCompactionOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_fifo_compaction_options_create"
                c_rocksdb_fifo_compaction_options_create ::
                IO (Ptr RocksdbFifoCompactionOptions)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_fifo_compaction_options_set_max_table_files_size"
                c_rocksdb_fifo_compaction_options_set_max_table_files_size ::
                Ptr RocksdbFifoCompactionOptions -> Word64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_fifo_compaction_options_destroy"
                c_rocksdb_fifo_compaction_options_destroy ::
                Ptr RocksdbFifoCompactionOptions -> IO ()
 
-foreign import ccall unsafe "rocksdb_livefiles_count"
+foreign import ccall interruptible "rocksdb_livefiles_count"
                c_rocksdb_livefiles_count :: Ptr RocksdbLivefiles -> IO CInt
 
-foreign import ccall unsafe "rocksdb_livefiles_name"
+foreign import ccall interruptible "rocksdb_livefiles_name"
                c_rocksdb_livefiles_name ::
                Ptr RocksdbLivefiles -> CInt -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_livefiles_level"
+foreign import ccall interruptible "rocksdb_livefiles_level"
                c_rocksdb_livefiles_level ::
                Ptr RocksdbLivefiles -> CInt -> IO CInt
 
-foreign import ccall unsafe "rocksdb_livefiles_size"
+foreign import ccall interruptible "rocksdb_livefiles_size"
                c_rocksdb_livefiles_size ::
                Ptr RocksdbLivefiles -> CInt -> IO CSize
 
-foreign import ccall unsafe "rocksdb_livefiles_smallestkey"
+foreign import ccall interruptible "rocksdb_livefiles_smallestkey"
                c_rocksdb_livefiles_smallestkey ::
                Ptr RocksdbLivefiles -> CInt -> Ptr CSize -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_livefiles_largestkey"
+foreign import ccall interruptible "rocksdb_livefiles_largestkey"
                c_rocksdb_livefiles_largestkey ::
                Ptr RocksdbLivefiles -> CInt -> Ptr CSize -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_livefiles_destroy"
+foreign import ccall interruptible "rocksdb_livefiles_destroy"
                c_rocksdb_livefiles_destroy :: Ptr RocksdbLivefiles -> IO ()
 
-foreign import ccall unsafe "rocksdb_get_options_from_string"
-               c_rocksdb_get_options_from_string ::
+foreign import ccall interruptible
+               "rocksdb_get_options_from_string" c_rocksdb_get_options_from_string
+               ::
                Ptr RocksdbOptions ->
                  Ptr CChar -> Ptr RocksdbOptions -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_delete_file_in_range"
+foreign import ccall interruptible "rocksdb_delete_file_in_range"
                c_rocksdb_delete_file_in_range ::
                Ptr Rocksdb ->
                  Ptr CChar ->
                    CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_delete_file_in_range_cf"
-               c_rocksdb_delete_file_in_range_cf ::
+foreign import ccall interruptible
+               "rocksdb_delete_file_in_range_cf" c_rocksdb_delete_file_in_range_cf
+               ::
                Ptr Rocksdb ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar ->
                      CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transactiondb_create_column_family"
                c_rocksdb_transactiondb_create_column_family ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbOptions ->
                    Ptr CChar -> Ptr (Ptr CChar) -> IO (Ptr RocksdbColumnFamilyHandle)
 
-foreign import ccall unsafe "rocksdb_transactiondb_open"
+foreign import ccall interruptible "rocksdb_transactiondb_open"
                c_rocksdb_transactiondb_open ::
                Ptr RocksdbOptions ->
                  Ptr RocksdbTransactiondbOptions ->
                    Ptr CChar -> Ptr (Ptr CChar) -> IO (Ptr RocksdbTransactiondb)
 
-foreign import ccall unsafe "rocksdb_transactiondb_create_snapshot"
+foreign import ccall interruptible
+               "rocksdb_transactiondb_create_snapshot"
                c_rocksdb_transactiondb_create_snapshot ::
                Ptr RocksdbTransactiondb -> IO (Ptr RocksdbSnapshot)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transactiondb_release_snapshot"
                c_rocksdb_transactiondb_release_snapshot ::
                Ptr RocksdbTransactiondb -> Ptr RocksdbSnapshot -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_begin"
+foreign import ccall interruptible "rocksdb_transaction_begin"
                c_rocksdb_transaction_begin ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr RocksdbTransactionOptions ->
                      Ptr RocksdbTransaction -> IO (Ptr RocksdbTransaction)
 
-foreign import ccall unsafe "rocksdb_transaction_commit"
+foreign import ccall interruptible "rocksdb_transaction_commit"
                c_rocksdb_transaction_commit ::
                Ptr RocksdbTransaction -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_rollback"
+foreign import ccall interruptible "rocksdb_transaction_rollback"
                c_rocksdb_transaction_rollback ::
                Ptr RocksdbTransaction -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_destroy"
+foreign import ccall interruptible "rocksdb_transaction_destroy"
                c_rocksdb_transaction_destroy :: Ptr RocksdbTransaction -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_get_snapshot"
+foreign import ccall interruptible
+               "rocksdb_transaction_get_snapshot"
                c_rocksdb_transaction_get_snapshot ::
                Ptr RocksdbTransaction -> IO (Ptr RocksdbSnapshot)
 
-foreign import ccall unsafe "rocksdb_transaction_get"
+foreign import ccall interruptible "rocksdb_transaction_get"
                c_rocksdb_transaction_get ::
                Ptr RocksdbTransaction ->
                  Ptr RocksdbReadoptions ->
                    Ptr CChar ->
                      CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_transaction_get_cf"
+foreign import ccall interruptible "rocksdb_transaction_get_cf"
                c_rocksdb_transaction_get_cf ::
                Ptr RocksdbTransaction ->
                  Ptr RocksdbReadoptions ->
@@ -1972,21 +2052,22 @@
                      Ptr CChar ->
                        CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_transaction_get_for_update"
+foreign import ccall interruptible
+               "rocksdb_transaction_get_for_update"
                c_rocksdb_transaction_get_for_update ::
                Ptr RocksdbTransaction ->
                  Ptr RocksdbReadoptions ->
                    Ptr CChar ->
                      CSize -> Ptr CSize -> CUChar -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_transactiondb_get"
+foreign import ccall interruptible "rocksdb_transactiondb_get"
                c_rocksdb_transactiondb_get ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbReadoptions ->
                    Ptr CChar ->
                      CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_transactiondb_get_cf"
+foreign import ccall interruptible "rocksdb_transactiondb_get_cf"
                c_rocksdb_transactiondb_get_cf ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbReadoptions ->
@@ -1994,27 +2075,27 @@
                      Ptr CChar ->
                        CSize -> Ptr CSize -> Ptr (Ptr CChar) -> IO (Ptr CChar)
 
-foreign import ccall unsafe "rocksdb_transaction_put"
+foreign import ccall interruptible "rocksdb_transaction_put"
                c_rocksdb_transaction_put ::
                Ptr RocksdbTransaction ->
                  Ptr CChar ->
                    CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_put_cf"
+foreign import ccall interruptible "rocksdb_transaction_put_cf"
                c_rocksdb_transaction_put_cf ::
                Ptr RocksdbTransaction ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar ->
                      CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transactiondb_put"
+foreign import ccall interruptible "rocksdb_transactiondb_put"
                c_rocksdb_transactiondb_put ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr CChar ->
                      CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transactiondb_put_cf"
+foreign import ccall interruptible "rocksdb_transactiondb_put_cf"
                c_rocksdb_transactiondb_put_cf ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbWriteoptions ->
@@ -2022,177 +2103,187 @@
                      Ptr CChar ->
                        CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transactiondb_write"
+foreign import ccall interruptible "rocksdb_transactiondb_write"
                c_rocksdb_transactiondb_write ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr RocksdbWritebatch -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_merge"
+foreign import ccall interruptible "rocksdb_transaction_merge"
                c_rocksdb_transaction_merge ::
                Ptr RocksdbTransaction ->
                  Ptr CChar ->
                    CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transactiondb_merge"
+foreign import ccall interruptible "rocksdb_transactiondb_merge"
                c_rocksdb_transactiondb_merge ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr CChar ->
                      CSize -> Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_delete"
+foreign import ccall interruptible "rocksdb_transaction_delete"
                c_rocksdb_transaction_delete ::
                Ptr RocksdbTransaction ->
                  Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_delete_cf"
+foreign import ccall interruptible "rocksdb_transaction_delete_cf"
                c_rocksdb_transaction_delete_cf ::
                Ptr RocksdbTransaction ->
                  Ptr RocksdbColumnFamilyHandle ->
                    Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transactiondb_delete"
+foreign import ccall interruptible "rocksdb_transactiondb_delete"
                c_rocksdb_transactiondb_delete ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transactiondb_delete_cf"
-               c_rocksdb_transactiondb_delete_cf ::
+foreign import ccall interruptible
+               "rocksdb_transactiondb_delete_cf" c_rocksdb_transactiondb_delete_cf
+               ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr RocksdbColumnFamilyHandle ->
                      Ptr CChar -> CSize -> Ptr (Ptr CChar) -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_create_iterator"
+foreign import ccall interruptible
+               "rocksdb_transaction_create_iterator"
                c_rocksdb_transaction_create_iterator ::
                Ptr RocksdbTransaction ->
                  Ptr RocksdbReadoptions -> IO (Ptr RocksdbIterator)
 
-foreign import ccall unsafe "rocksdb_transactiondb_create_iterator"
+foreign import ccall interruptible
+               "rocksdb_transactiondb_create_iterator"
                c_rocksdb_transactiondb_create_iterator ::
                Ptr RocksdbTransactiondb ->
                  Ptr RocksdbReadoptions -> IO (Ptr RocksdbIterator)
 
-foreign import ccall unsafe "rocksdb_transactiondb_close"
+foreign import ccall interruptible "rocksdb_transactiondb_close"
                c_rocksdb_transactiondb_close :: Ptr RocksdbTransactiondb -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transactiondb_checkpoint_object_create"
                c_rocksdb_transactiondb_checkpoint_object_create ::
                Ptr RocksdbTransactiondb ->
                  Ptr (Ptr CChar) -> IO (Ptr RocksdbCheckpoint)
 
-foreign import ccall unsafe "rocksdb_optimistictransactiondb_open"
+foreign import ccall interruptible
+               "rocksdb_optimistictransactiondb_open"
                c_rocksdb_optimistictransactiondb_open ::
                Ptr RocksdbOptions ->
                  Ptr CChar ->
                    Ptr (Ptr CChar) -> IO (Ptr RocksdbOptimistictransactiondb)
 
-foreign import ccall unsafe "rocksdb_optimistictransaction_begin"
+foreign import ccall interruptible
+               "rocksdb_optimistictransaction_begin"
                c_rocksdb_optimistictransaction_begin ::
                Ptr RocksdbOptimistictransactiondb ->
                  Ptr RocksdbWriteoptions ->
                    Ptr RocksdbOptimistictransactionOptions ->
                      Ptr RocksdbTransaction -> IO (Ptr RocksdbTransaction)
 
-foreign import ccall unsafe "rocksdb_optimistictransactiondb_close"
+foreign import ccall interruptible
+               "rocksdb_optimistictransactiondb_close"
                c_rocksdb_optimistictransactiondb_close ::
                Ptr RocksdbOptimistictransactiondb -> IO ()
 
-foreign import ccall unsafe "rocksdb_transactiondb_options_create"
+foreign import ccall interruptible
+               "rocksdb_transactiondb_options_create"
                c_rocksdb_transactiondb_options_create ::
                IO (Ptr RocksdbTransactiondbOptions)
 
-foreign import ccall unsafe "rocksdb_transactiondb_options_destroy"
+foreign import ccall interruptible
+               "rocksdb_transactiondb_options_destroy"
                c_rocksdb_transactiondb_options_destroy ::
                Ptr RocksdbTransactiondbOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transactiondb_options_set_max_num_locks"
                c_rocksdb_transactiondb_options_set_max_num_locks ::
                Ptr RocksdbTransactiondbOptions -> Int64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transactiondb_options_set_num_stripes"
                c_rocksdb_transactiondb_options_set_num_stripes ::
                Ptr RocksdbTransactiondbOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transactiondb_options_set_transaction_lock_timeout"
                c_rocksdb_transactiondb_options_set_transaction_lock_timeout ::
                Ptr RocksdbTransactiondbOptions -> Int64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transactiondb_options_set_default_lock_timeout"
                c_rocksdb_transactiondb_options_set_default_lock_timeout ::
                Ptr RocksdbTransactiondbOptions -> Int64 -> IO ()
 
-foreign import ccall unsafe "rocksdb_transaction_options_create"
+foreign import ccall interruptible
+               "rocksdb_transaction_options_create"
                c_rocksdb_transaction_options_create ::
                IO (Ptr RocksdbTransactionOptions)
 
-foreign import ccall unsafe "rocksdb_transaction_options_destroy"
+foreign import ccall interruptible
+               "rocksdb_transaction_options_destroy"
                c_rocksdb_transaction_options_destroy ::
                Ptr RocksdbTransactionOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transaction_options_set_set_snapshot"
                c_rocksdb_transaction_options_set_set_snapshot ::
                Ptr RocksdbTransactionOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transaction_options_set_deadlock_detect"
                c_rocksdb_transaction_options_set_deadlock_detect ::
                Ptr RocksdbTransactionOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transaction_options_set_lock_timeout"
                c_rocksdb_transaction_options_set_lock_timeout ::
                Ptr RocksdbTransactionOptions -> Int64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transaction_options_set_expiration"
                c_rocksdb_transaction_options_set_expiration ::
                Ptr RocksdbTransactionOptions -> Int64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transaction_options_set_deadlock_detect_depth"
                c_rocksdb_transaction_options_set_deadlock_detect_depth ::
                Ptr RocksdbTransactionOptions -> Int64 -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_transaction_options_set_max_write_batch_size"
                c_rocksdb_transaction_options_set_max_write_batch_size ::
                Ptr RocksdbTransactionOptions -> CSize -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_optimistictransaction_options_create"
                c_rocksdb_optimistictransaction_options_create ::
                IO (Ptr RocksdbOptimistictransactionOptions)
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_optimistictransaction_options_destroy"
                c_rocksdb_optimistictransaction_options_destroy ::
                Ptr RocksdbOptimistictransactionOptions -> IO ()
 
-foreign import ccall unsafe
+foreign import ccall interruptible
                "rocksdb_optimistictransaction_options_set_set_snapshot"
                c_rocksdb_optimistictransaction_options_set_set_snapshot ::
                Ptr RocksdbOptimistictransactionOptions -> CUChar -> IO ()
 
-foreign import ccall unsafe "rocksdb_free" c_rocksdb_free ::
+foreign import ccall interruptible "rocksdb_free" c_rocksdb_free ::
                Ptr () -> IO ()
 
-foreign import ccall unsafe "rocksdb_get_pinned"
+foreign import ccall interruptible "rocksdb_get_pinned"
                c_rocksdb_get_pinned ::
                Ptr Rocksdb ->
                  Ptr RocksdbReadoptions ->
                    Ptr CChar ->
                      CSize -> Ptr (Ptr CChar) -> IO (Ptr RocksdbPinnableslice)
 
-foreign import ccall unsafe "rocksdb_get_pinned_cf"
+foreign import ccall interruptible "rocksdb_get_pinned_cf"
                c_rocksdb_get_pinned_cf ::
                Ptr Rocksdb ->
                  Ptr RocksdbReadoptions ->
@@ -2200,10 +2291,10 @@
                      Ptr CChar ->
                        CSize -> Ptr (Ptr CChar) -> IO (Ptr RocksdbPinnableslice)
 
-foreign import ccall unsafe "rocksdb_pinnableslice_destroy"
+foreign import ccall interruptible "rocksdb_pinnableslice_destroy"
                c_rocksdb_pinnableslice_destroy ::
                Ptr RocksdbPinnableslice -> IO ()
 
-foreign import ccall unsafe "rocksdb_pinnableslice_value"
+foreign import ccall interruptible "rocksdb_pinnableslice_value"
                c_rocksdb_pinnableslice_value ::
                Ptr RocksdbPinnableslice -> Ptr CSize -> IO (Ptr CChar)
diff --git a/src/Database/RocksDB/Options.hs b/src/Database/RocksDB/Options.hs
--- a/src/Database/RocksDB/Options.hs
+++ b/src/Database/RocksDB/Options.hs
@@ -8,8 +8,8 @@
 
 import Database.RocksDB.Internals
 import Database.RocksDB.Utils
-import Foreign
-import GHC.ForeignPtr
+import Foreign hiding (newForeignPtr)
+import Foreign.Concurrent
 
 data Options = Options
   { totalThreads :: !(Maybe Int)
@@ -27,4 +27,4 @@
   setIntOptions totalThreads $c_rocksdb_options_increase_parallelism opts_p
   setBoolOptions createIfMissing $
     c_rocksdb_options_set_create_if_missing opts_p
-  newConcForeignPtr opts_p $ c_rocksdb_options_destroy opts_p
+  newForeignPtr opts_p $ c_rocksdb_options_destroy opts_p
diff --git a/src/Database/RocksDB/ReadOptions.hs b/src/Database/RocksDB/ReadOptions.hs
--- a/src/Database/RocksDB/ReadOptions.hs
+++ b/src/Database/RocksDB/ReadOptions.hs
@@ -8,8 +8,8 @@
 
 import Database.RocksDB.Internals
 import Database.RocksDB.Utils
-import Foreign
-import GHC.ForeignPtr
+import Foreign hiding (newForeignPtr)
+import Foreign.Concurrent
 
 data ReadOptions = ReadOptions
   { verityChecksums :: !(Maybe Bool)
@@ -28,4 +28,4 @@
   setBoolOptions verityChecksums $
     c_rocksdb_readoptions_set_verify_checksums ropts_p
   setBoolOptions fillCache $ c_rocksdb_readoptions_set_fill_cache ropts_p
-  newConcForeignPtr ropts_p $ c_rocksdb_readoptions_destroy ropts_p
+  newForeignPtr ropts_p $ c_rocksdb_readoptions_destroy ropts_p
diff --git a/src/Database/RocksDB/Utils.hs b/src/Database/RocksDB/Utils.hs
--- a/src/Database/RocksDB/Utils.hs
+++ b/src/Database/RocksDB/Utils.hs
@@ -1,9 +1,15 @@
 module Database.RocksDB.Utils
   ( setIntOptions
   , setBoolOptions
+  , withErrorMessagePtr
   ) where
 
+import Control.Exception.Safe
+import qualified Data.ByteString as BS
 import Data.Foldable
+import Database.RocksDB.Exceptions
+import Foreign
+import Foreign.C
 
 setIntOptions :: Integral t => Maybe Int -> (t -> IO ()) -> IO ()
 {-# INLINEABLE setIntOptions #-}
@@ -17,3 +23,15 @@
     if val
       then 1
       else 0
+
+withErrorMessagePtr :: (Ptr (Ptr CChar) -> IO r) -> IO r
+{-# INLINEABLE withErrorMessagePtr #-}
+withErrorMessagePtr cont =
+  alloca $ \p -> do
+    r <- cont p
+    p' <- peek p
+    if p' == nullPtr
+      then pure r
+      else do
+        msg <- BS.packCString p'
+        throw $ RocksDBException msg
diff --git a/src/Database/RocksDB/WriteOptions.hs b/src/Database/RocksDB/WriteOptions.hs
--- a/src/Database/RocksDB/WriteOptions.hs
+++ b/src/Database/RocksDB/WriteOptions.hs
@@ -8,8 +8,8 @@
 
 import Database.RocksDB.Internals
 import Database.RocksDB.Utils
-import Foreign
-import GHC.ForeignPtr
+import Foreign hiding (newForeignPtr)
+import Foreign.Concurrent
 
 data WriteOptions = WriteOptions
   { sync :: !(Maybe Bool)
@@ -26,4 +26,4 @@
   wopts_p <- c_rocksdb_writeoptions_create
   setBoolOptions sync $ c_rocksdb_writeoptions_set_sync wopts_p
   setIntOptions disableWAL $ c_rocksdb_writeoptions_disable_WAL wopts_p
-  newConcForeignPtr wopts_p $ c_rocksdb_writeoptions_destroy wopts_p
+  newForeignPtr wopts_p $ c_rocksdb_writeoptions_destroy wopts_p
