@ -3414,13 +3414,27 @@ bool VersionStorageInfo::RangeMightExistAfterSortedRun(
return false ;
return false ;
}
}
void Version : : AddLiveFiles ( std : : vector < FileDescriptor > * live ) {
void Version : : AddLiveFiles ( std : : vector < uint64_t > * live_table_files ,
for ( int level = 0 ; level < storage_info_ . num_levels ( ) ; level + + ) {
std : : vector < uint64_t > * live_blob_files ) const {
const std : : vector < FileMetaData * > & files = storage_info_ . files_ [ level ] ;
assert ( live_table_files ) ;
for ( const auto & file : files ) {
assert ( live_blob_files ) ;
live - > push_back ( file - > fd ) ;
for ( int level = 0 ; level < storage_info_ . num_levels ( ) ; + + level ) {
const auto & level_files = storage_info_ . LevelFiles ( level ) ;
for ( const auto & meta : level_files ) {
assert ( meta ) ;
live_table_files - > emplace_back ( meta - > fd . GetNumber ( ) ) ;
}
}
}
}
const auto & blob_files = storage_info_ . GetBlobFiles ( ) ;
for ( const auto & pair : blob_files ) {
const auto & meta = pair . second ;
assert ( meta ) ;
live_blob_files - > emplace_back ( meta - > GetBlobFileNumber ( ) ) ;
}
}
}
std : : string Version : : DebugString ( bool hex , bool print_stats ) const {
std : : string Version : : DebugString ( bool hex , bool print_stats ) const {
@ -5511,44 +5525,70 @@ uint64_t VersionSet::ApproximateSize(Version* v, const FdWithKeyRange& f,
v - > GetMutableCFOptions ( ) . prefix_extractor . get ( ) ) ;
v - > GetMutableCFOptions ( ) . prefix_extractor . get ( ) ) ;
}
}
void VersionSet : : AddLiveFiles ( std : : vector < FileDescriptor > * live_list ) {
void VersionSet : : AddLiveFiles ( std : : vector < uint64_t > * live_table_files ,
std : : vector < uint64_t > * live_blob_files ) const {
assert ( live_table_files ) ;
assert ( live_blob_files ) ;
// pre-calculate space requirement
// pre-calculate space requirement
int64_t total_files = 0 ;
size_t total_table_files = 0 ;
size_t total_blob_files = 0 ;
assert ( column_family_set_ ) ;
for ( auto cfd : * column_family_set_ ) {
for ( auto cfd : * column_family_set_ ) {
assert ( cfd ) ;
if ( ! cfd - > initialized ( ) ) {
if ( ! cfd - > initialized ( ) ) {
continue ;
continue ;
}
}
Version * dummy_versions = cfd - > dummy_versions ( ) ;
Version * const dummy_versions = cfd - > dummy_versions ( ) ;
assert ( dummy_versions ) ;
for ( Version * v = dummy_versions - > next_ ; v ! = dummy_versions ;
for ( Version * v = dummy_versions - > next_ ; v ! = dummy_versions ;
v = v - > next_ ) {
v = v - > next_ ) {
assert ( v ) ;
const auto * vstorage = v - > storage_info ( ) ;
const auto * vstorage = v - > storage_info ( ) ;
for ( int level = 0 ; level < vstorage - > num_levels ( ) ; level + + ) {
assert ( vstorage ) ;
total_files + = vstorage - > LevelFiles ( level ) . size ( ) ;
for ( int level = 0 ; level < vstorage - > num_levels ( ) ; + + level ) {
total_table_files + = vstorage - > LevelFiles ( level ) . size ( ) ;
}
}
total_blob_files + = vstorage - > GetBlobFiles ( ) . size ( ) ;
}
}
}
}
// just one time extension to the right size
// just one time extension to the right size
live_list - > reserve ( live_list - > size ( ) + static_cast < size_t > ( total_files ) ) ;
live_table_files - > reserve ( live_table_files - > size ( ) + total_table_files ) ;
live_blob_files - > reserve ( live_blob_files - > size ( ) + total_blob_files ) ;
assert ( column_family_set_ ) ;
for ( auto cfd : * column_family_set_ ) {
for ( auto cfd : * column_family_set_ ) {
assert ( cfd ) ;
if ( ! cfd - > initialized ( ) ) {
if ( ! cfd - > initialized ( ) ) {
continue ;
continue ;
}
}
auto * current = cfd - > current ( ) ;
auto * current = cfd - > current ( ) ;
bool found_current = false ;
bool found_current = false ;
Version * dummy_versions = cfd - > dummy_versions ( ) ;
Version * const dummy_versions = cfd - > dummy_versions ( ) ;
assert ( dummy_versions ) ;
for ( Version * v = dummy_versions - > next_ ; v ! = dummy_versions ;
for ( Version * v = dummy_versions - > next_ ; v ! = dummy_versions ;
v = v - > next_ ) {
v = v - > next_ ) {
v - > AddLiveFiles ( live_list ) ;
v - > AddLiveFiles ( live_table_files , live_blob_files ) ;
if ( v = = current ) {
if ( v = = current ) {
found_current = true ;
found_current = true ;
}
}
}
}
if ( ! found_current & & current ! = nullptr ) {
if ( ! found_current & & current ! = nullptr ) {
// Should never happen unless it is a bug.
// Should never happen unless it is a bug.
assert ( false ) ;
assert ( false ) ;
current - > AddLiveFiles ( live_list ) ;
current - > AddLiveFiles ( live_table_files , live_blob_files ) ;
}
}
}
}
}
}