rocksdb
Overview
概述
RocksDB: A Persistent Key-Value Store for Flash and RAM Storage
RocksDB:一个用于闪存和RAM存储的持久化键值存储数据库
RocksDB is developed and maintained by Facebook Database Engineering Team. It is built on earlier work on LevelDB by Sanjay Ghemawat (sanjay@google.com) and Jeff Dean (jeff@google.com)
RocksDB 是由Facebook数据库工程团队研发和维护,是在 Sanjay Ghemawat(sanjay@google.com) 和 eff Dean(jeff@google.com) 前期的工作成果LevelDB的基础上建立起来的。
This code is a library that forms the core building block for a fast key-value server, especially suited for storing data on flash drives. It has a Log-Structured-Merge-Database (LSM) design with flexible tradeoffs between Write-Amplification-Factor (WAF), Read-Amplification-Factor (RAF) and Space-Amplification-Factor (SAF). It has multi-threaded compactions, making it especially suitable for storing multiple terabytes of data in a single database.
这段代码(RocksDB)构成了快速键值服务的核心构建模块的库,特别适合在闪存驱动器上存储数据。它采用了日志结构合并数据库(LSM),可以在写放大因子(WAF),读放大因子(RAF)和空间放大因子(SAF)之间灵活权衡。它还拥有多线程的压缩功能,特别适合在单个数据库中存储多个TB的数据。
Start with example usage here: https://github.com/facebook/rocksdb/tree/master/examples
这里开始一个示范用例:https://github.com/facebook/rocksdb/tree/master/examples
See the github wiki for more explanation.
更多解释可以参考github wiki。
The public interface is in include/. Callers should not include or rely on the details of any other header files in this package. Those internal APIs may be changed without warning.
公共接口位于目录 include/ 中。调用者不应包含或依赖这个包中任何其他头文件的细节。那些内部的API可能会在没有警告的情况下修改。
Design discussions are conducted in https://www.facebook.com/groups/rocksdb.dev/ and https://rocksdb.slack.com/
可以在 https://www.facebook.com/groups/rocksdb.dev/ 和 https://rocksdb.slack.com/ 上进行设计相关的讨论
Install
安装
Compilation
编译
Important: If you plan to run RocksDB in production, don't compile using default make or make all. That will compile RocksDB in debug mode, which is much slower than release mode.
重要:如果你计划在生产环境运行RocksDB,不要使用默认的make和make install去编译。那样将在调试模式下编译RocksDB,会比发布模式慢的多。
RocksDB's library should be able to compile without any dependency installed, although we recommend installing some compression libraries (see below). We do depend on newer gcc/clang with C++11 support.
RocksDB 库应该能在不需要安装任何依赖的情况下进行编译,尽管我们建议可以先安装一些压缩库(见下文)。我们确实依赖支持C++11的更新版本的gcc/clang.
There are few options when compiling RocksDB:
编译 RocksDB 时的一些选项:
-
[recommended]
make static_lib
will compile librocksdb.a, RocksDB static library. Compiles static library in release mode.
【推荐】make static_lib
会编译 librocksdb.a,RocksDB 静态库,在发布模式下编译静态库。 -
make shared_lib
will compile librocksdb.so, RocksDB shared library. Compiles shared library in release mode.
make shared_lib
会编译 librocksdb.so,RocksDB 的共享库,在发布模式下编译共享库。 -
make check
will compile and run all the unit tests.make check
will compile RocksDB in debug mode.
make check
会编译并运行所有单元测试。make check
会在调试模式下编译 RocksDB。 -
make all
will compile our static library, and all our tools and unit tests. Our tools depend on gflags. You will need to have gflags installed to runmake all
. This will compile RocksDB in debug mode. Don't use binaries compiled bymake all
in production.
make all
会编译我们的静态库,以及所有的工具和单元测试。我们的工具依赖 gflags。你需要安装先 gflags 才能运行make all
。这样将在调试模式下编译 RocksDB。不要在生产环境中使用由make all
编译的二进制文件。 -
By default the binary we produce is optimized for the platform you're compiling on (
-march=native
or the equivalent). SSE4.2 will thus be enabled automatically if your CPU supports it. To print a warning if your CPU does not support SSE4.2, build withUSE_SSE=1
makestatic_lib
or, if using CMake,cmake -DFORCE_SSE42=ON
. If you want to build a portable binary, addPORTABLE=1
before your make commands, like this:PORTABLE=1 make static_lib
.
默认情况下,我们生成的二进制文件是针对你正在编译的平台进行优化的(使用-march=native
或其他等效的选项)。如果你的CPU支持SSE4.2指令集,那么它被将被自动启用。如果你的CPU不支持SSE4.2指令集时想要打印告警的话,可以使用USE_SSE=1
static_lib
参数进行构建,如果使用CMake,可以使用cmake -DFORCE_SSE42=ON
参数。如果你想构建一个可移植的二进制文件,在使用make指令前添加PORTABLE=1
参数,例如:PORTABLE=1 make static_lib
。
Dependencies
依赖
-
You can link RocksDB with following compression libraries:
你可以使用以下压缩库来链接RocksDB:- zlib - a library for data compression.
zlib - 一个用于数据压缩的库。 - bzip2 - a library for data compression.
bzip2 - 一个用于数据压缩的库。 - lz4 - a library for extremely fast data compression.
lz4 - 一个用于快速压缩数据的库。 - snappy - a library for fast data compression.
snappy - 一个用于快速压缩数据的库。 - zstandard - Fast real-time compression algorithm.
zstandard - 快速实时压缩算法。
- zlib - a library for data compression.
-
All our tools depend on:
我们所有的工具都依赖于:- gflags - a library that handles command line flags processing. You can compile rocksdb library even if you don't have gflags installed.
gflags - 一个用于处理命令行标识的库。但即使没安装gflags,也可以编译rocksdb库。
- gflags - a library that handles command line flags processing. You can compile rocksdb library even if you don't have gflags installed.
-
make check
will also check code formatting, which requires clang-format
make check
还将检查代码格式,而这需要使用clang-format。 -
If you wish to build the RocksJava static target, then cmake is required for building Snappy.
如果你想要构建 RocksJava 静态对象,还需要使用cmake构建Snappy。
Supported platforms
支持平台
-
Linux - Ubuntu
- Upgrade your gcc to version at least 4.8 to get C++11 support.
将你的gcc升级到至少4.8版本以获得C++11的支持。 - Install gflags. First, try:
sudo apt-get install libgflags-dev
. If this doesn't work and you're using Ubuntu, here's a nice tutorial: (http://askubuntu.com/questions/312173/installing-gflags-12-04)
安装 gflags。首先,尝试执行:sudo apt-get install libgflags-dev
。如果这样没有用,并且你正在使用Ubuntu,这里有个不错的教程:(http://askubuntu.com/questions/312173/installing-gflags-12-04) - Install snappy. This is usually as easy as:
sudo apt-get install libsnappy-dev
.
安装 snappy。这个通常很简单,就像:sudo apt-get install libsnappy-dev
。 - Install zlib. Try:
sudo apt-get install zlib1g-dev
.
安装 zlib。尝试:sudo apt-get install zlib1g-dev
。 - Install bzip2:
sudo apt-get install libbz2-dev
.
安装 bzip2:sudo apt-get install libbz2-dev
。 - Install lz4:
sudo apt-get install liblz4-dev
.
安装 lz4:sudo apt-get install liblz4-dev
。 - Install zstandard:
sudo apt-get install libzstd-dev
.
安装 zstandard:sudo apt-get install libzstd-dev
。
- Upgrade your gcc to version at least 4.8 to get C++11 support.
-
Linux - CentOS / RHEL
-
Upgrade your gcc to version at least 4.8 to get C++11 support:
yum install gcc48-c++
将你的gcc升级到至少4.8版本以获得C++11的支持:yum install gcc48-c++
-
Install gflags:
安装gflags
git clone https://github.com/gflags/gflags.git cd gflags git checkout v2.0 ./configure && make && sudo make install
Notice: Once installed, please add the include path for gflags to your CPATH environment variable and the lib path to LIBRARY_PATH. If installed with default settings, the include path will be /usr/local/include and the lib path will be /usr/local/lib.
注意:完成安装后,请将gflags的包含路径添加到CPATH环境变量,将库路径添加到LIBRARY_PATH中。如果使用默认设置安装,包含路径将为 /usr/local/include,库路径将为 /usr/local/lib。- Install snappy:
安装 snappy:
sudo yum install snappy snappy-devel
- Install zlib:
安装 zlib:
sudo yum install zlib zlib-devel
- Install bzip2:
安装 bzip2:
sudo yum install bzip2 bzip2-devel
- Install lz4:
安装 lz4:
sudo yum install lz4-devel
- Install ASAN (optional for debugging):
安装 ASAN(用于调试的选项):
sudo yum install libasan
- Install zstandard:
安装 zstandard:- With EPEL:
基于 EPEL:
sudo yum install libzstd-devel
- With CentOS 8:
基于 CentOS 8:
sudo dnf install libzstd-devel
- From source:
使用源码:
wget https://github.com/facebook/zstd/archive/v1.1.3.tar.gz mv v1.1.3.tar.gz zstd-1.1.3.tar.gz tar zxvf zstd-1.1.3.tar.gz cd zstd-1.1.3 make && sudo make install
- With EPEL:
-
-
OS X:
- Install latest C++ compiler that supports C++ 11:
安装支持C++ 11的最新版本的C++编译器:- Update XCode: run xcode-select --install (or install it from XCode App's settting).
升级 XCode:运行xcode-select --install
命令(或者从XCode应用设置中安装) - Install via homebrew.
通过 homebrew 安装- If you're first time developer in MacOS, you still need to run:
xcode-select --install
in your command line.
如果你是第一次在MacOS上进行开发,你还需要先在命令行执行:xcode-select --install
。 - run
brew tap homebrew/versions; brew install gcc48 --use-llvm
to install gcc 4.8 (or higher).
运行brew tap homebrew/versions; brew install gcc48 --use-llvm
来安装gcc 4.8(或更高的版本)。
- If you're first time developer in MacOS, you still need to run:
- Update XCode: run xcode-select --install (or install it from XCode App's settting).
- run
brew install rocksdb
运行brew install rocksdb
- Install latest C++ compiler that supports C++ 11:
-
FreeBSD (11.01):
-
You can either install RocksDB from the Ports system using
cd /usr/ports/databases/rocksdb && make install
, or you can follow the details below to install dependencies and compile from source code:
你也可以从Ports系统安装RocksDB,安装命令是cd /usr/ports/databases/rocksdb && make install
,或者可以根据以下详细说明从源码安装依赖并编译: -
Install the dependencies for RocksDB:
安装RocksDB依赖:
export BATCH=YES cd /usr/ports/devel/gmake && make install cd /usr/ports/devel/gflags && make install cd /usr/ports/archivers/snappy && make install cd /usr/ports/archivers/bzip2 && make install cd /usr/ports/archivers/liblz4 && make install cd /usr/ports/archivesrs/zstd && make install cd /usr/ports/devel/git && make install
- Install the dependencies for RocksJava (optional):
安装RocksJava依赖(可选):
export BATCH=yes cd /usr/ports/java/openjdk7 && make install
- Build RocksDB from source:
从源码构建RocksDB:
cd ~ git clone https://github.com/facebook/rocksdb.git cd rocksdb gmake static_lib
- Build RocksJava from source (optional):
从源码构建RocksJava(可选):
cd rocksdb export JAVA_HOME=/usr/local/openjdk7 gmake rocksdbjava
-
-
OpenBSD (6.3/-current):
-
As RocksDB is not available in the ports yet you have to build it on your own:
由于 RocksDB 在ports还未提供,所以你需要自己构建它: -
Install the dependencies for RocksDB:
安装 RocksDB 依赖:
pkg_add gmake gflags snappy bzip2 lz4 zstd git jdk bash findutils gnuwatch -
Build RocksDB from source:
从源码构建RocksDB:
cd ~ git clone https://github.com/facebook/rocksdb.git cd rocksdb gmake static_lib
- Build RocksJava from source (optional):
从源码构建RocksJava(可选):
cd rocksdb export JAVA_HOME=/usr/local/jdk-1.8.0 export PATH=$PATH:/usr/local/jdk-1.8.0/bin gmake rocksdbjava
-
-
iOS:
- Run: TARGET_OS=IOS make static_lib. When building the project which uses rocksdb iOS library, make sure to define two important pre-processing macros: ROCKSDB_LITE and IOS_CROSS_COMPILE.
运行:
TARGET_OS=IOS make static_lib
当构建使用rocksdb ios库的项目时,请确保定义两个重要的预处理宏: ROCKSDB_LITE 和 IOS_CROSS_COMPILE。
- Run: TARGET_OS=IOS make static_lib. When building the project which uses rocksdb iOS library, make sure to define two important pre-processing macros: ROCKSDB_LITE and IOS_CROSS_COMPILE.
-
Windows:
- For building with MS Visual Studio 13 you will need Update 4 installed.
当使用 MS Visual Studio 13 进行编译时,需要先安装 Update 4。 - Read and follow the instructions at CMakeLists.txt
阅读并遵循 CMakeLists.txt 上的说明。 - Or install via vcpkg
或者通过 vcpkg 安装- run
vcpkg install rocksdb:x64-windows
运行vcpkg install rocksdb:x64-windows
- run
- For building with MS Visual Studio 13 you will need Update 4 installed.
-
AIX 6.1
- Install AIX Toolbox rpms with gcc
使用gcc安装AIX Toolbox rpms - Use these environment variables:
使用这些环境变量:
export PORTABLE=1 export CC=gcc export AR="ar -X64" export EXTRA_ARFLAGS=-X64 export EXTRA_CFLAGS=-maix64 export EXTRA_CXXFLAGS=-maix64 export PLATFORM_LDFLAGS="-static-libstdc++ -static-libgcc" export LIBPATH=/opt/freeware/lib export JAVA_HOME=/usr/java8_64 export PATH=/opt/freeware/bin:$PATH
- Install AIX Toolbox rpms with gcc
-
Solaris Sparc
-
Install GCC 4.8.2 and higher.
安装 GCC 4.8.2 和更高级的版本。 -
Use these environment variables:
使用这些环境变量:
export CC=gcc export EXTRA_CFLAGS=-m64 export EXTRA_CXXFLAGS=-m64 export EXTRA_LDFLAGS=-m64 export PORTABLE=1 export PLATFORM_LDFLAGS="-static-libstdc++ -static-libgcc"
-
License
许可
RocksDB is dual-licensed under both the GPLv2 (found in the COPYING file in the root directory) and Apache 2.0 License (found in the LICENSE.Apache file in the root directory). You may select, at your option, one of the above-listed licenses.
RocksDB 使用双许可证,分别是GPLv2(可以在根目录的 COPYING 文件中找到)和 Apache 2.0许可证(可以在根目录的 LICENSE.Apache 文件中找到)。你可以根据你的意愿,选择上述列出的许可证之一。
本文作者:505donkey
本文链接:https://www.cnblogs.com/505donkey/p/17713828.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步