@ -48,18 +48,17 @@ Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,
std : : set < uint64_t > live ;
std : : set < uint64_t > live ;
versions_ - > AddLiveFilesCurrentVersion ( & live ) ;
versions_ - > AddLiveFilesCurrentVersion ( & live ) ;
ret . resize ( live . size ( ) + 2 ) ; //*.sst + CURRENT + MANIFEST
ret . clear ( ) ;
ret . reserve ( live . size ( ) + 2 ) ; //*.sst + CURRENT + MANIFEST
// create names of the live files. The names are not absolute
// create names of the live files. The names are not absolute
// paths, instead they are relative to dbname_;
// paths, instead they are relative to dbname_;
std : : set < uint64_t > : : iterator it = live . begin ( ) ;
for ( auto live_file : live ) {
for ( unsigned int i = 0 ; i < live . size ( ) ; i + + , it + + ) {
ret . push_back ( TableFileName ( " " , live_file ) ) ;
ret [ i ] = TableFileName ( " " , * it ) ;
}
}
ret [ live . size ( ) ] = CurrentFileName ( " " ) ;
ret . push_back ( CurrentFileName ( " " ) ) ;
ret [ live . size ( ) + 1 ] = DescriptorFileName ( " " ,
ret . push_back ( DescriptorFileName ( " " , versions_ - > ManifestFileNumber ( ) ) ) ;
versions_ - > ManifestFileNumber ( ) ) ;
// find length of manifest file while holding the mutex lock
// find length of manifest file while holding the mutex lock
* manifest_file_size = versions_ - > ManifestFileSize ( ) ;
* manifest_file_size = versions_ - > ManifestFileSize ( ) ;
@ -81,11 +80,7 @@ Status DBImpl::GetSortedWalFiles(VectorLogPtr& files) {
}
}
}
}
// list wal files in main db dir.
// list wal files in main db dir.
s = AppendSortedWalsOfType ( dbname_ , files , kAliveLogFile ) ;
return AppendSortedWalsOfType ( dbname_ , files , kAliveLogFile ) ;
if ( ! s . ok ( ) ) {
return s ;
}
return s ;
}
}
Status DBImpl : : DeleteWalFiles ( const VectorLogPtr & files ) {
Status DBImpl : : DeleteWalFiles ( const VectorLogPtr & files ) {
@ -93,14 +88,17 @@ Status DBImpl::DeleteWalFiles(const VectorLogPtr& files) {
std : : string archivedir = ArchivalDirectory ( dbname_ ) ;
std : : string archivedir = ArchivalDirectory ( dbname_ ) ;
std : : string files_not_deleted ;
std : : string files_not_deleted ;
for ( const auto & wal : files ) {
for ( const auto & wal : files ) {
/* Try deleting in archive dir. If fails, try deleting in main db dir.
/* Try deleting in the dir that pathname points to for the logfile.
* This is efficient because all except for very few wal files will be in
This may fail if we try to delete a log file which was live when captured
* archive . Checking for WalType is not much helpful because alive wal could
but is archived now . Try deleting it from archive also
be archived now .
*/
*/
if ( ! env_ - > DeleteFile ( archivedir + " / " + wal - > Filename ( ) ) . ok ( ) & &
Status st = env_ - > DeleteFile ( dbname_ + " / " + wal - > PathName ( ) ) ;
! env_ - > DeleteFile ( dbname_ + " / " + wal - > Filename ( ) ) . ok ( ) ) {
if ( ! st . ok ( ) ) {
files_not_deleted . append ( wal - > Filename ( ) ) ;
if ( wal - > Type ( ) = = kAliveLogFile & &
env_ - > DeleteFile ( LogFileName ( archivedir , wal - > LogNumber ( ) ) ) . ok ( ) ) {
continue ;
}
files_not_deleted . append ( wal - > PathName ( ) ) ;
}
}
}
}
if ( ! files_not_deleted . empty ( ) ) {
if ( ! files_not_deleted . empty ( ) ) {