-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a leak of open Blob files #13106
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
#ifndef NDEBUG | ||
|
||
#include "db/blob/blob_file_cache.h" | ||
#include "db/column_family.h" | ||
#include "db/db_impl/db_impl.h" | ||
#include "db/error_handler.h" | ||
|
@@ -321,5 +322,53 @@ size_t DBImpl::TEST_EstimateInMemoryStatsHistorySize() const { | |
InstrumentedMutexLock l(&const_cast<DBImpl*>(this)->stats_history_mutex_); | ||
return EstimateInMemoryStatsHistorySize(); | ||
} | ||
|
||
void DBImpl::TEST_VerifyNoObsoleteFilesCached( | ||
bool db_mutex_already_held) const { | ||
// This check is somewhat expensive and obscure to make a part of every | ||
// unit test in every build variety. Thus, we only enable it for ASAN builds, | ||
// and of course only DEBUG builds. | ||
#ifndef NDEBUG | ||
if (!kMustFreeHeapAllocations) { | ||
return; | ||
} | ||
|
||
std::optional<InstrumentedMutexLock> l; | ||
if (db_mutex_already_held) { | ||
mutex_.AssertHeld(); | ||
} else { | ||
l.emplace(&mutex_); | ||
} | ||
|
||
std::vector<uint64_t> live_table_files; | ||
std::vector<uint64_t> live_blob_files; | ||
for (auto cfd : *versions_->GetColumnFamilySet()) { | ||
if (cfd->IsDropped()) { | ||
continue; | ||
} | ||
cfd->current()->AddLiveFiles(&live_table_files, &live_blob_files); | ||
} | ||
|
||
std::set<uint64_t> live_files; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorting |
||
live_files.insert(live_table_files.begin(), live_table_files.end()); | ||
live_files.insert(live_blob_files.begin(), live_blob_files.end()); | ||
|
||
auto fn = [&](const Slice& key, Cache::ObjectPtr, size_t, | ||
const Cache::CacheItemHelper* helper) { | ||
if (helper != BlobFileCache::GetHelper()) { | ||
// Skip non-blob files for now | ||
// FIXME: diagnose and fix the leaks of obsolete SST files revealed in | ||
// unit tests. | ||
return; | ||
} | ||
// See TableCache and BlobFileCache | ||
assert(key.size() == sizeof(uint64_t)); | ||
uint64_t file_number; | ||
GetUnaligned(reinterpret_cast<const uint64_t*>(key.data()), &file_number); | ||
assert(live_files.find(file_number) != live_files.end()); | ||
}; | ||
table_cache_->ApplyToAllEntries(fn, {}); | ||
#endif // !NDEBUG | ||
} | ||
} // namespace ROCKSDB_NAMESPACE | ||
#endif // NDEBUG |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
#include <vector> | ||
|
||
#include "cache/cache_reservation_manager.h" | ||
#include "db/blob/blob_file_cache.h" | ||
#include "db/blob/blob_file_meta.h" | ||
#include "db/dbformat.h" | ||
#include "db/internal_stats.h" | ||
|
@@ -744,19 +745,18 @@ class VersionBuilder::Rep { | |
return Status::Corruption("VersionBuilder", oss.str()); | ||
} | ||
|
||
// Note: we use C++11 for now but in C++14, this could be done in a more | ||
// elegant way using generalized lambda capture. | ||
VersionSet* const vs = version_set_; | ||
const ImmutableCFOptions* const ioptions = ioptions_; | ||
|
||
auto deleter = [vs, ioptions](SharedBlobFileMetaData* shared_meta) { | ||
auto deleter = [vs = version_set_, ioptions = ioptions_, | ||
bc = cfd_ ? cfd_->blob_file_cache() | ||
: nullptr](SharedBlobFileMetaData* shared_meta) { | ||
if (vs) { | ||
assert(ioptions); | ||
assert(!ioptions->cf_paths.empty()); | ||
assert(shared_meta); | ||
assert(bc); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do |
||
|
||
vs->AddObsoleteBlobFile(shared_meta->GetBlobFileNumber(), | ||
ioptions->cf_paths.front().path); | ||
bc->Evict(shared_meta->GetBlobFileNumber()); | ||
} | ||
|
||
delete shared_meta; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might have to move this declaration to the
#ifdef NDEBUG
block above and#ifdef
the definition+call too to fix those linker errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't see that db_impl_debug.cc is already in a giant ifdef