Skip to content

Compile And Install

rockeet edited this page Nov 3, 2023 · 33 revisions

编译并安装 ToplingDB

Makefile 编译脚本会自动从 github 获取并更新各个组件仓库,目前 topling-rocks 仓库是私有仓库,需要访问权限,无该仓库访问权限的用户编译出来的 ToplingDB 是社区版,社区版除了不能创建 ToplingZipTable 的 SST,其它功能与企业版完全相同,社区版还可以读取 ToplingZipTable 的 SST。

联系 contact at topling.cn 获取企业版 ToplingDB

1. 安装依赖

sudo yum config-manager --set-enabled powertools # 有些 linux 发行版不需要此行
sudo yum -y epel-release centos-release-scl
sudo yum -y install git libaio-devel gcc-c++ gflags-devel zlib-devel bzip2-devel libcurl-devel liburing-devel
#sudo apt-get update -y && sudo apt-get install -y libjemalloc-dev libaio-dev libgflags-dev zlib1g-dev libbz2-dev libcurl4-gnutls-dev liburing-dev libsnappy-dev libbz2-dev liblz4-dev libzstd-dev

可以直接下载我们预编译好的 动态库 tar 包静态库 tar 包,或者按照以下流程自行编译。

2. clone git

git clone https://github.com/topling/toplingdb.git
cd toplingdb
git submodule update --init --recursive
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts # silent git

3. 动态库 编译、安装

make -j`nproc` DEBUG_LEVEL=0 shared_lib
sudo make DEBUG_LEVEL=0 install-shared

默认安装路径是 /usr/local,如果要安装到别处,需指定 PREFIX=somepath,例如:

sudo make install-shared DEBUG_LEVEL=0 PREFIX=/opt

3.1. 特别说明

用户程序应首选动态链接到 ToplingDB,参考 101

动态库编译、安装时会将 dcompact_worker 安装到 /$PREFIX/bin 下。

3.2. DEBUG_LEVEL

DEBUG_LEVEL=? 编译版本 library 名称 链接
DEBUG_LEVEL=0 release librocksdb -lrocksdb
DEBUG_LEVEL=1 带优化的 debug librocksdb_debug_1 -lrocksdb_debug_1
DEBUG_LEVEL=2 debug librocksdb -lrocksdb_debug

4. 静态库 编译、安装

make -j`nproc` DEBUG_LEVEL=0 static_lib
sudo make DEBUG_LEVEL=0 install-static

不推荐静态链接到 ToplingDB,参考 101,如果必须使用静态链接,需特别注意以下事项:

4.1. 用户程序必须使用 --whole-archive

用户程序静态连接 ToplingDB 时,需要在前后增加 -Wl,--whole-archive--no-whole-archive,因为 ToplingDB 的插件机制为了隔离用户代码对插件代码的直接依赖,通过 C++ 的全局对象构造来注册插件,注册插件的这些代码静态链接时会被链接器自动删除,所以需要通过 -Wl,--whole-archive 来强制链接器不要删除这些代码,但同时也会导致链接器保留了真正无用的代码。

4.2. dcompact_worker 仍然是动态链接的

静态库 编译、安装 时 无 dcompact_worker,因为 dcompact_worker 依赖 ToplingDB 动态库,并且要通过 LD_PRELOAD 加载用户定义的 CompactionFilter 等插件,这些用户自定义的插件也依赖 ToplingDB 动态库。

所以,即便程序是静态链接到 ToplingDB 的,要使用分布式 Compact,该程序相应的 CompactionFilter 等插件也必须编译成动态库,通过 LD_PRELOAD 加载到 dcompact_worker

Clone this wiki locally