@ -3149,26 +3149,38 @@ inline void DBImpl::DelayLoggingAndReset() {
Status DBImpl : : DeleteFile ( std : : string name ) {
Status DBImpl : : DeleteFile ( std : : string name ) {
uint64_t number ;
uint64_t number ;
FileType type ;
FileType type ;
if ( ! ParseFileName ( name , & number , & type ) | |
WalFileType log_type ;
( type ! = kTableFile ) ) {
if ( ! ParseFileName ( name , & number , & type , & log_type ) | |
Log ( options_ . info_log ,
( type ! = kTableFile & & type ! = kLogFile ) ) {
" DeleteFile #%ld FAILED. Invalid file name \n " ,
Log ( options_ . info_log , " DeleteFile %s failed. \n " , name . c_str ( ) ) ;
number ) ;
return Status : : InvalidArgument ( " Invalid file name " ) ;
return Status : : InvalidArgument ( " Invalid file name " ) ;
}
}
Status status ;
if ( type = = kLogFile ) {
// Only allow deleting archived log files
if ( log_type ! = kArchivedLogFile ) {
Log ( options_ . info_log , " DeleteFile %s failed. \n " , name . c_str ( ) ) ;
return Status : : NotSupported ( " Delete only supported for archived logs " ) ;
}
status = env_ - > DeleteFile ( options_ . wal_dir + " / " + name . c_str ( ) ) ;
if ( ! status . ok ( ) ) {
Log ( options_ . info_log , " DeleteFile %s failed. \n " , name . c_str ( ) ) ;
}
return status ;
}
int level ;
int level ;
FileMetaData metadata ;
FileMetaData metadata ;
int maxlevel = NumberLevels ( ) ;
int maxlevel = NumberLevels ( ) ;
VersionEdit edit ( maxlevel ) ;
VersionEdit edit ( maxlevel ) ;
DeletionState deletion_state ;
DeletionState deletion_state ;
Status status ;
{
{
MutexLock l ( & mutex_ ) ;
MutexLock l ( & mutex_ ) ;
status = versions_ - > GetMetadataForFile ( number , & level , & metadata ) ;
status = versions_ - > GetMetadataForFile ( number , & level , & metadata ) ;
if ( ! status . ok ( ) ) {
if ( ! status . ok ( ) ) {
Log ( options_ . info_log , " DeleteFile #%lld FAILED. File not found \n " ,
Log ( options_ . info_log , " DeleteFile %s failed . File not found \n " ,
static_cast < unsigned long long > ( number ) ) ;
name . c_str ( ) ) ;
return Status : : InvalidArgument ( " File not found " ) ;
return Status : : InvalidArgument ( " File not found " ) ;
}
}
assert ( ( level > 0 ) & & ( level < maxlevel ) ) ;
assert ( ( level > 0 ) & & ( level < maxlevel ) ) ;
@ -3176,8 +3188,7 @@ Status DBImpl::DeleteFile(std::string name) {
// If the file is being compacted no need to delete.
// If the file is being compacted no need to delete.
if ( metadata . being_compacted ) {
if ( metadata . being_compacted ) {
Log ( options_ . info_log ,
Log ( options_ . info_log ,
" DeleteFile #%lld Skipped. File about to be compacted \n " ,
" DeleteFile %s Skipped. File about to be compacted \n " , name . c_str ( ) ) ;
static_cast < unsigned long long > ( number ) ) ;
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
@ -3187,8 +3198,7 @@ Status DBImpl::DeleteFile(std::string name) {
for ( int i = level + 1 ; i < maxlevel ; i + + ) {
for ( int i = level + 1 ; i < maxlevel ; i + + ) {
if ( versions_ - > NumLevelFiles ( i ) ! = 0 ) {
if ( versions_ - > NumLevelFiles ( i ) ! = 0 ) {
Log ( options_ . info_log ,
Log ( options_ . info_log ,
" DeleteFile #%lld FAILED. File not in last level \n " ,
" DeleteFile %s FAILED. File not in last level \n " , name . c_str ( ) ) ;
static_cast < unsigned long long > ( number ) ) ;
return Status : : InvalidArgument ( " File not in last level " ) ;
return Status : : InvalidArgument ( " File not in last level " ) ;
}
}
}
}