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
[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。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2018-08-04 oracle 11g亿级复杂SQL优化一例(数量级性能提升)
2018-08-04 Program terminated with signal 6, Aborted,有可能啥原因呢?
2018-08-04 The address where a.out.debug has been loaded is missing以及No symbol "*" in current context原因与解决方法
2016-08-04 线上mysql内存持续增长直至内存溢出被killed分析(已解决)