rocksdb安装与使用

首先要安装gcc 7.3以上版本,依赖于c++ 17.
参见
gcc 7安装及4.8.5和7.5并存
需要rpm方式或源码安装gflags 2.2,否则系统可能内置了gflags 2.1,从而导致链接时一直找不到gflags库。如下:
/tmp/ccUXmr9R.o: In function `__static_initialization_and_destruction_0(int, int)':
/home/zjh/test_gflags.cpp:4: undefined reference to `google::FlagRegisterer::FlagRegisterer<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
collect2: error: ld returned 1 exit status
离线库可从https://pan.baidu.com/s/1P-LAEfJQbJfhbsda1Cd0QQ?pwd=vcu5下载。
cd gflags-2.2.2
mkdir build && cd build
注意:记得先清理干净。

cmake -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DINSTALL_HEADERS=ON -DINSTALL_SHARED_LIBS=ON -DINSTALL_STATIC_LIBS=ON ..
make -j4
make install

tar -xzvf v8.5.4.tar.gz
cd rocksdb-8.5.4/
make static_lib
make shared_lib
 make 生成rocksdb辅助工具如db_bench等,注意默认生成的是debug模式,所以需要动态库和静态库先独立生产,然后再跑make。但是除了上面的动态库和静态库,最好是一次性跑make,不要单独跑make xxx
 
make db_bench报错,如下:

[zjh@hs-10-20-30-193 rocksdb-8.5.4]$ make db_bench
$DEBUG_LEVEL is 1, $LIB_MODE is shared
Makefile:166: Warning: Compiling in debug mode. Don't use the resulting binary in production
CCLD db_bench
tools/db_bench_tool.o: In function `rocksdb::CompressData(rocksdb::Slice const&, rocksdb::CompressionInfo const&, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
/home/zjh/cpp_demo/rocksdb-8.5.4/./util/compression.h:1583: undefined reference to `rocksdb::SyncPoint::GetInstance()'
tools/db_bench_tool.o: In function `void rocksdb::SyncPoint::Process<35ul>(char const (&) [35ul], void*)':
/home/zjh/cpp_demo/rocksdb-8.5.4/./test_util/sync_point.h:132: undefined reference to `rocksdb::SyncPoint::Process(rocksdb::Slice const&, void*)'
tools/db_bench_tool.o: In function `rocksdb::SimCache* rocksdb::static_cast_with_check<rocksdb::SimCache, rocksdb::Cache>(rocksdb::Cache*)':
/home/zjh/cpp_demo/rocksdb-8.5.4/./util/cast_util.h:22: undefined reference to `typeinfo for rocksdb::Cache'
tools/db_bench_tool.o:(.data.rel.ro._ZTIN7rocksdb12CacheWrapperE[_ZTIN7rocksdb12CacheWrapperE]+0x10): undefined reference to `typeinfo for rocksdb::Cache'
tools/db_bench_tool.o:(.data.rel.ro._ZTIN7rocksdb22FileChecksumGenFactoryE[_ZTIN7rocksdb22FileChecksumGenFactoryE]+0x10): undefined reference to `typeinfo for rocksdb::Customizable'
tools/db_bench_tool.o:(.data.rel.ro._ZTIN7rocksdb13EventListenerE[_ZTIN7rocksdb13EventListenerE]+0x10): undefined reference to `typeinfo for rocksdb::Customizable'
tools/db_bench_tool.o:(.data.rel.ro._ZTIN7rocksdb16CompactionFilterE[_ZTIN7rocksdb16CompactionFilterE]+0x10): undefined reference to `typeinfo for rocksdb::Customizable'
test_util/testutil.o:(.data.rel.ro._ZTIN7rocksdb18MemTableRepFactoryE[_ZTIN7rocksdb18MemTableRepFactoryE]+0x10): undefined reference to `typeinfo for rocksdb::Customizable'
test_util/testutil.o:(.data.rel.ro._ZTIN7rocksdb10ComparatorE[_ZTIN7rocksdb10ComparatorE]+0x18): undefined reference to `typeinfo for rocksdb::Customizable'
test_util/testutil.o:(.data.rel.ro._ZTIN7rocksdb23CompactionFilterFactoryE[_ZTIN7rocksdb23CompactionFilterFactoryE]+0x10): more undefined references to `typeinfo for rocksdb::Customizable' follow
test_util/testutil.o:(.data.rel.ro._ZTIN7rocksdb4test22ChanglingMergeOperatorE[_ZTIN7rocksdb4test22ChanglingMergeOperatorE]+0x10): undefined reference to `typeinfo for rocksdb::MergeOperator'
test_util/testutil.o:(.data.rel.ro._ZTIN7rocksdb15MockSystemClockE[_ZTIN7rocksdb15MockSystemClockE]+0x10): undefined reference to `typeinfo for rocksdb::SystemClockWrapper'
test_util/testutil.o:(.data.rel.ro+0x28): undefined reference to `typeinfo for rocksdb::MemTableRep'
tools/simulated_hybrid_file_system.o:(.data.rel.ro._ZTIN7rocksdb25SimulatedHybridFileSystemE[_ZTIN7rocksdb25SimulatedHybridFileSystemE]+0x10): undefined reference to `typeinfo for rocksdb::FileSystemWrapper'
collect2: error: ld returned 1 exit status
make: *** [db_bench] Error 1

但是rocksdb so已经存在了LD_LIBRARY_PATH指向的目录了。

make all时也报错,类似:

[zjh@hs-10-20-30-193 rocksdb-8.5.4]$ make all
$DEBUG_LEVEL is 1, $LIB_MODE is shared
Makefile:166: Warning: Compiling in debug mode. Don't use the resulting binary in production
CCLD table_reader_bench
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::DB'
./librocksdb_test_debug.so: undefined reference to `rocksdb::DBImpl::TEST_MaxNextLevelOverlappingBytes(rocksdb::ColumnFamilyHandle*)'
./librocksdb_test_debug.so: undefined reference to `rocksdb::DBImpl::TEST_WaitForCompact()'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::Env'
./librocksdb_test_debug.so: undefined reference to `rocksdb::SyncPoint::ClearAllCallBacks()'
./librocksdb_test_debug.so: undefined reference to `rocksdb::SyncPoint::Process(rocksdb::Slice const&, void*)'
./librocksdb_test_debug.so: undefined reference to `rocksdb::SyncPoint::ClearCallBack(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::DBImpl'
./librocksdb_test_debug.so: undefined reference to `rocksdb::SyncPoint::DisableProcessing()'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::MemTableRep'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::Cache'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::WritableFile'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::SystemClockWrapper'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::EnvWrapper'
./librocksdb_test_debug.so: undefined reference to `rocksdb::DBImpl::TEST_CompactRange(int, rocksdb::Slice const*, rocksdb::Slice const*, rocksdb::ColumnFamilyHandle*, bool)'
./librocksdb_test_debug.so: undefined reference to `rocksdb::SyncPoint::LoadDependency(std::vector<rocksdb::SyncPoint::SyncPointPair, std::allocator<rocksdb::SyncPoint::SyncPointPair> > const&)'
./librocksdb_test_debug.so: undefined reference to `rocksdb::SyncPoint::EnableProcessing()'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::MergeOperator'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::SequentialFile'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::Customizable'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::CompositeEnvWrapper'
./librocksdb_test_debug.so: undefined reference to `typeinfo for rocksdb::RandomAccessFile'
./librocksdb_test_debug.so: undefined reference to `rocksdb::DBImpl::TEST_WaitForFlushMemTable(rocksdb::ColumnFamilyHandle*)'
./librocksdb_test_debug.so: undefined reference to `rocksdb::SyncPoint::GetInstance()'
collect2: error: ld returned 1 exit status

原因:rocksdb.so和rocksdb.a用release版本编译,make使用debug,是不兼容的。

参见:https://github.com/facebook/rocksdb/issues/10072、https://github.com/facebook/rocksdb/issues/4329。

解决方法就是:用cmake编译release版本,或都是debug版。

delete db后,rocksdb仍然还有很多rocksdb:low, rocksdb:high线程,如下:

原因是:这俩是后台清理线程,详见https://blog.csdn.net/qq_30708747/article/details/120307971。

posted @ 2024-08-04 09:15  zhjh256  阅读(156)  评论(0编辑  收藏  举报