bytedance / terarkdb

A RocksDB compatible KV storage engine with better performance
Apache License 2.0
2.05k stars 202 forks source link

[Valgrind] Memory detect #189

Open yapple opened 2 years ago

yapple commented 2 years ago

[BUG]

Expected behavior

0 error

Actual behavior

` ==652331== Memcheck, a memory error detector ==652331== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==652331== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==652331== Command: ./db_bench --use_terark_table=0 ==652331== Initializing RocksDB Options from the specified file Initializing RocksDB Options from command-line flags ==652331== Warning: unimplemented fcntl command: 1036 ==652331== Warning: unimplemented fcntl command: 1036

RocksDB: version 5.18 Date: Sat Dec 18 18:12:05 2021 CPU: 40 * Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz CPUCache: 25600 KB Keys: 16 bytes each Values: 100 bytes each (50 bytes after compression) Entries: 1000000 Prefix: 0 bytes Keys per prefix: 0 RawSize: 110.6 MB (estimated) FileSize: 62.9 MB (estimated) Write rate: 0 bytes/second Read rate: 0 ops/second Compression: Snappy Memtablerep: skip_list Perf Level: 1 WARNING: Optimization is disabled: benchmarks unnecessarily slow WARNING: Assertions are enabled; benchmarks unnecessarily slow


Initializing RocksDB Options from the specified file Initializing RocksDB Options from command-line flags ==652331== Warning: unimplemented fcntl command: 1036 ==652331== Warning: unimplemented fcntl command: 1036 DB path: [/tmp/rocksdbtest-3003/dbbench] ==652331== Warning: unimplemented fcntl command: 1036 ==652331== Warning: unimplemented fcntl command: 1036 ==652331== Warning: unimplemented fcntl command: 1036 ==652331== Warning: unimplemented fcntl command: 1036 fillseq : 743.209 micros/op 1345 ops/sec; 0.1 MB/s Please disable_auto_compactions in FillDeterministic benchmark ==652331== ==652331== HEAP SUMMARY: ==652331== in use at exit: 17,908,254 bytes in 1,594 blocks ==652331== total heap usage: 7,170,607 allocs, 7,169,013 frees, 902,718,097 bytes allocated ==652331== ==652331== 16 bytes in 1 blocks are possibly lost in loss record 505 of 1,446 ==652331== at 0x4839F2F: operator new(unsigned long) (vg_replace_malloc.c:422) ==652331== by 0x23BAAB: gnu_cxx::new_allocator<terarkdb::FileMetaData>::allocate(unsigned long, void const) (new_allocator.h:104) ==652331== by 0x233E07: std::allocator_traits<std::allocator<terarkdb::FileMetaData> >::allocate(std::allocator<terarkdb::FileMetaData>&, unsigned long) (alloc_traits.h:436) ==652331== by 0x228DFF: std::_Vector_base<terarkdb::FileMetaData, std::allocator<terarkdb::FileMetaData> >::_M_allocate(unsigned long) (stl_vector.h:170) ==652331== by 0x6264FD: terarkdb::FileMetaData std::vector<terarkdb::FileMetaData, std::allocator<terarkdb::FileMetaData> >::_M_allocate_and_copy<std::move_iterator<terarkdb::FileMetaData> >(unsigned long, std::move_iterator<terarkdb::FileMetaData>, std::move_iterator<terarkdb::FileMetaData>) (stl_vector.h:1222) ==652331== by 0x624AD0: std::vector<terarkdb::FileMetaData, std::allocator<terarkdb::FileMetaData> >::reserve(unsigned long) (vector.tcc:75) ==652331== by 0x6205BB: terarkdb::VersionStorageInfo::Reserve(int, unsigned long) (version_set.h:102) ==652331== by 0x62395A: terarkdb::VersionBuilder::Rep::SaveTo(terarkdb::VersionStorageInfo, double) (version_builder.cc:700) ==652331== by 0x62033D: terarkdb::VersionBuilder::SaveTo(terarkdb::VersionStorageInfo, double) (version_builder.cc:883) ==652331== by 0x367509: terarkdb::(anonymous namespace)::BaseReferencedVersionBuilder::DoApplyAndSaveTo(terarkdb::VersionStorageInfo, double) (version_set.cc:749) ==652331== by 0x373EC3: terarkdb::VersionSet::ProcessManifestWrites(std::deque<terarkdb::VersionSet::ManifestWriter, std::allocator >&, terarkdb::InstrumentedMutex, terarkdb::Directory, bool) (version_set.cc:3200) ==652331== by 0x376719: terarkdb::VersionSet::LogAndApply(terarkdb::autovector<terarkdb::ColumnFamilyData, 8ul> const&, terarkdb::autovector<terarkdb::MutableCFOptions const, 8ul> const&, terarkdb::autovector<terarkdb::autovector<terarkdb::VersionEdit, 8ul>, 8ul> const&, terarkdb::InstrumentedMutex, terarkdb::Directory, bool, terarkdb::autovector<terarkdb::ColumnFamilyOptions const, 8ul> const&) (version_set.cc:3514) ==652331== ==652331== 32 bytes in 1 blocks are definitely lost in loss record 557 of 1,446 ==652331== at 0x483B20F: operator new[](unsigned long) (vg_replace_malloc.c:640) ==652331== by 0x36A2A6: terarkdb::VersionStorageInfo::VersionStorageInfo(terarkdb::InternalKeyComparator const, terarkdb::Comparator const, int, terarkdb::CompactionStyle, bool) (version_set.cc:1218) ==652331== by 0x36A949: terarkdb::Version::Version(terarkdb::ColumnFamilyData, terarkdb::VersionSet, terarkdb::EnvOptions const&, terarkdb::MutableCFOptions, unsigned long) (version_set.cc:1270) ==652331== by 0x37E57C: terarkdb::VersionSet::CreateColumnFamily(terarkdb::ColumnFamilyOptions const&, terarkdb::VersionEdit) (version_set.cc:4810) ==652331== by 0x377F6A: terarkdb::VersionSet::Recover(std::vector<terarkdb::ColumnFamilyDescriptor, std::allocator > const&, bool) (version_set.cc:3780) ==652331== by 0x2992A9: terarkdb::DBImpl::Recover(std::vector<terarkdb::ColumnFamilyDescriptor, std::allocator > const&, bool, bool, bool) (db_impl_open.cc:397) ==652331== by 0x29E877: terarkdb::DBImpl::Open(terarkdb::DBOptions const&, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::vector<terarkdb::ColumnFamilyDescriptor, std::allocator > const&, std::vector<terarkdb::ColumnFamilyHandle, std::allocator<terarkdb::ColumnFamilyHandle> >*, terarkdb::DB*, bool, bool) (db_impl_open.cc:1335) ==652331== by 0x29E115: terarkdb::DB::Open(terarkdb::DBOptions const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::vector<terarkdb::ColumnFamilyDescriptor, std::allocator > const&, std::vector<terarkdb::ColumnFamilyHandle, std::allocator<terarkdb::ColumnFamilyHandle> >, terarkdb::DB) (db_impl_open.cc:1254) ==652331== by 0x29DEE0: terarkdb::DB::Open(terarkdb::Options const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, terarkdb::DB) (db_impl_open.cc:1231) ==652331== by 0x171C84: terarkdb::Benchmark::OpenDb(terarkdb::Options, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, terarkdb::DBWithColumnFamilies) (db_bench_tool.cc:3813) ==652331== by 0x170F6D: terarkdb::Benchmark::InitializeOptionsGeneral(terarkdb::Options) (db_bench_tool.cc:3697) ==652331== by 0x1712FD: terarkdb::Benchmark::Open(terarkdb::Options) (db_bench_tool.cc:3723) ==652331== ==652331== 200 bytes in 1 blocks are possibly lost in loss record 1,391 of 1,446 ==652331== at 0x483B20F: operator new[](unsigned long) (vg_replace_malloc.c:640) ==652331== by 0x36A2A6: terarkdb::VersionStorageInfo::VersionStorageInfo(terarkdb::InternalKeyComparator const, terarkdb::Comparator const, int, terarkdb::CompactionStyle, bool) (version_set.cc:1218) ==652331== by 0x36A949: terarkdb::Version::Version(terarkdb::ColumnFamilyData, terarkdb::VersionSet, terarkdb::EnvOptions const&, terarkdb::MutableCFOptions, unsigned long) (version_set.cc:1270) ==652331== by 0x3735C1: terarkdb::VersionSet::ProcessManifestWrites(std::deque<terarkdb::VersionSet::ManifestWriter, std::allocator >&, terarkdb::InstrumentedMutex, terarkdb::Directory, bool) (version_set.cc:3106) ==652331== by 0x376719: terarkdb::VersionSet::LogAndApply(terarkdb::autovector<terarkdb::ColumnFamilyData, 8ul> const&, terarkdb::autovector<terarkdb::MutableCFOptions const, 8ul> const&, terarkdb::autovector<terarkdb::autovector<terarkdb::VersionEdit, 8ul>, 8ul> const&, terarkdb::InstrumentedMutex, terarkdb::Directory, bool, terarkdb::autovector<terarkdb::ColumnFamilyOptions const, 8ul> const&) (version_set.cc:3514) ==652331== by 0x32F0D7: terarkdb::VersionSet::LogAndApply(terarkdb::ColumnFamilyData, terarkdb::MutableCFOptions const&, terarkdb::autovector<terarkdb::VersionEdit, 8ul> const&, terarkdb::InstrumentedMutex, terarkdb::Directory, bool, terarkdb::ColumnFamilyOptions const) (version_set.h:919) ==652331== by 0x32CED4: terarkdb::MemTableList::TryInstallMemtableFlushResults(terarkdb::ColumnFamilyData, terarkdb::MutableCFOptions const&, terarkdb::autovector<terarkdb::MemTable, 8ul> const&, terarkdb::LogsWithPrepTracker, terarkdb::VersionSet, terarkdb::InstrumentedMutex, unsigned long, terarkdb::autovector<terarkdb::MemTable, 8ul>, terarkdb::Directory, terarkdb::LogBuffer, unsigned long) (memtable_list.cc:480) ==652331== by 0x2D116E: terarkdb::FlushJob::Run(terarkdb::LogsWithPrepTracker) (flush_job.cc:248) ==652331== by 0x25ACC1: terarkdb::DBImpl::FlushMemTableToOutputFile(terarkdb::ColumnFamilyData, terarkdb::MutableCFOptions const&, bool, terarkdb::JobContext, terarkdb::SuperVersionContext, terarkdb::LogBuffer, terarkdb::VersionEdit::ApplyCallback) (db_impl_compaction_flush.cc:180) ==652331== by 0x25B752: terarkdb::DBImpl::FlushMemTablesToOutputFiles(terarkdb::autovector<terarkdb::DBImpl::BGFlushArg, 8ul> const&, bool, terarkdb::JobContext, terarkdb::LogBuffer) (db_impl_compaction_flush.cc:275) ==652331== by 0x266BCB: terarkdb::DBImpl::BackgroundFlush(bool, terarkdb::JobContext, terarkdb::LogBuffer, terarkdb::FlushReason) (db_impl_compaction_flush.cc:2199) ==652331== by 0x2672CA: terarkdb::DBImpl::BackgroundCallFlush() (db_impl_compaction_flush.cc:2250) ==652331== ==652331== 320 bytes in 1 blocks are possibly lost in loss record 1,398 of 1,446 ==652331== at 0x483E5EF: calloc (vg_replace_malloc.c:1328) ==652331== by 0x40130E7: calloc (rtld-malloc.h:44) ==652331== by 0x40130E7: allocate_dtv (dl-tls.c:366) ==652331== by 0x40130E7: _dl_allocate_tls (dl-tls.c:612) ==652331== by 0x4862BE4: allocate_stack (allocatestack.c:624) ==652331== by 0x4862BE4: pthread_create@@GLIBC_2.2.5 (pthread_create.c:634) ==652331== by 0x49A9B19: std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete >, void ()()) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.29) ==652331== by 0x4C88ED: std::thread::thread<void (terarkdb::DeleteScheduler::)(), terarkdb::DeleteScheduler>(void (terarkdb::DeleteScheduler::&&)(), terarkdb::DeleteScheduler&&) (thread:137) ==652331== by 0x4C6408: terarkdb::DeleteScheduler::DeleteScheduler(terarkdb::Env, long, terarkdb::Logger, terarkdb::SstFileManagerImpl, double, unsigned long) (delete_scheduler.cc:43) ==652331== by 0x4E4B9A: terarkdb::SstFileManagerImpl::SstFileManagerImpl(terarkdb::Env, std::shared_ptr, long, double, unsigned long) (sst_file_manager_impl.cc:39) ==652331== by 0x4E6BC2: terarkdb::NewSstFileManager(terarkdb::Env, std::shared_ptr, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, long, bool, terarkdb::Status*, double, unsigned long) (sst_file_manager_impl.cc:474) ==652331== by 0x2978F0: terarkdb::SanitizeOptions(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, terarkdb::DBOptions const&) (db_impl_open.cc:158) ==652331== by 0x297034: terarkdb::SanitizeOptions(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, terarkdb::Options const&) (db_impl_open.cc:37) ==652331== by 0x1FE604: terarkdb::DestroyDB(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, terarkdb::Options const&, std::vector<terarkdb::ColumnFamilyDescriptor, std::allocator > const&) (db_impl.cc:3978) ==652331== by 0x1699BE: terarkdb::Benchmark::Benchmark() (db_bench_tool.cc:2445) ==652331== ==652331== LEAK SUMMARY: ==652331== definitely lost: 32 bytes in 1 blocks ==652331== indirectly lost: 0 bytes in 0 blocks ==652331== possibly lost: 536 bytes in 3 blocks ==652331== still reachable: 17,907,686 bytes in 1,590 blocks ==652331== of which reachable via heuristic: ==652331== newarray : 512 bytes in 1 blocks ==652331== suppressed: 0 bytes in 0 blocks ==652331== Reachable blocks (those to which a pointer was found) are not shown. ==652331== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==652331== ==652331== For lists of detected and suppressed errors, rerun with: -s ==652331== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)`

Steps to reproduce the behavior

valgrind --leak-check=full ./db_bench --use_terark_table=0

[Enhancement]

Problem

Solution