@ -20,14 +20,16 @@
namespace rocksdb {
namespace rocksdb {
// Given a path, flatten the path name by replacing all chars not in
// Given a path, flatten the path name by replacing all chars not in
// {[0-9,a-z,A-Z,-,_,.]} with _. And append '\0' at the end.
// {[0-9,a-z,A-Z,-,_,.]} with _. And append '_LOG \0' at the end.
// Return the number of chars stored in dest not including the trailing '\0'.
// Return the number of chars stored in dest not including the trailing '\0'.
static int FlattenPath ( const std : : string & path , char * dest , int len ) {
static size_t GetInfoLogPrefix ( const std : : string & path , char * dest , int len ) {
int write_idx = 0 ;
const char suffix [ ] = " _LOG " ;
int i = 0 ;
int src_len = path . size ( ) ;
while ( i < src_len & & write_idx < len - 1 ) {
size_t write_idx = 0 ;
size_t i = 0 ;
size_t src_len = path . size ( ) ;
while ( i < src_len & & write_idx < len - sizeof ( suffix ) ) {
if ( ( path [ i ] > = ' a ' & & path [ i ] < = ' z ' ) | |
if ( ( path [ i ] > = ' a ' & & path [ i ] < = ' z ' ) | |
( path [ i ] > = ' 0 ' & & path [ i ] < = ' 9 ' ) | |
( path [ i ] > = ' 0 ' & & path [ i ] < = ' 9 ' ) | |
( path [ i ] > = ' A ' & & path [ i ] < = ' Z ' ) | |
( path [ i ] > = ' A ' & & path [ i ] < = ' Z ' ) | |
@ -41,8 +43,10 @@ static int FlattenPath(const std::string& path, char* dest, int len) {
}
}
i + + ;
i + + ;
}
}
assert ( sizeof ( suffix ) < = len - write_idx ) ;
dest [ write_idx ] = ' \0 ' ;
// "\0" is automatically added by snprintf
snprintf ( dest + write_idx , len - write_idx , suffix ) ;
write_idx + = sizeof ( suffix ) - 1 ;
return write_idx ;
return write_idx ;
}
}
@ -118,14 +122,26 @@ std::string TempFileName(const std::string& dbname, uint64_t number) {
return MakeFileName ( dbname , number , " dbtmp " ) ;
return MakeFileName ( dbname , number , " dbtmp " ) ;
}
}
InfoLogPrefix : : InfoLogPrefix ( bool has_log_dir ,
const std : : string & db_absolute_path ) {
if ( ! has_log_dir ) {
const char kInfoLogPrefix [ ] = " LOG " ;
// "\0" is automatically added to the end
snprintf ( buf , sizeof ( buf ) , kInfoLogPrefix ) ;
prefix = Slice ( buf , sizeof ( kInfoLogPrefix ) - 1 ) ;
} else {
size_t len = GetInfoLogPrefix ( db_absolute_path , buf , sizeof ( buf ) ) ;
prefix = Slice ( buf , len ) ;
}
}
std : : string InfoLogFileName ( const std : : string & dbname ,
std : : string InfoLogFileName ( const std : : string & dbname ,
const std : : string & db_path , const std : : string & log_dir ) {
const std : : string & db_path , const std : : string & log_dir ) {
if ( log_dir . empty ( ) )
if ( log_dir . empty ( ) )
return dbname + " /LOG " ;
return dbname + " /LOG " ;
char flatten_db_path [ 256 ] ;
InfoLogPrefix info_log_prefix ( true , db_path ) ;
FlattenPath ( db_path , flatten_db_path , 256 ) ;
return log_dir + " / " + info_log_prefix . buf ;
return log_dir + " / " + flatten_db_path + " _LOG " ;
}
}
// Return the name of the old info log file for "dbname".
// Return the name of the old info log file for "dbname".
@ -137,9 +153,8 @@ std::string OldInfoLogFileName(const std::string& dbname, uint64_t ts,
if ( log_dir . empty ( ) )
if ( log_dir . empty ( ) )
return dbname + " /LOG.old. " + buf ;
return dbname + " /LOG.old. " + buf ;
char flatten_db_path [ 256 ] ;
InfoLogPrefix info_log_prefix ( true , db_path ) ;
FlattenPath ( db_path , flatten_db_path , 256 ) ;
return log_dir + " / " + info_log_prefix . buf + " .old. " + buf ;
return log_dir + " / " + flatten_db_path + " _LOG.old. " + buf ;
}
}
std : : string MetaDatabaseName ( const std : : string & dbname , uint64_t number ) {
std : : string MetaDatabaseName ( const std : : string & dbname , uint64_t number ) {
@ -157,8 +172,8 @@ std::string IdentityFileName(const std::string& dbname) {
// dbname/IDENTITY
// dbname/IDENTITY
// dbname/CURRENT
// dbname/CURRENT
// dbname/LOCK
// dbname/LOCK
// dbname/LOG
// dbname/<info_log_name_prefix>
// dbname/LOG .old.[0-9]+
// dbname/<info_log_name_prefix> .old.[0-9]+
// dbname/MANIFEST-[0-9]+
// dbname/MANIFEST-[0-9]+
// dbname/[0-9]+.(log|sst)
// dbname/[0-9]+.(log|sst)
// dbname/METADB-[0-9]+
// dbname/METADB-[0-9]+
@ -167,6 +182,12 @@ bool ParseFileName(const std::string& fname,
uint64_t * number ,
uint64_t * number ,
FileType * type ,
FileType * type ,
WalFileType * log_type ) {
WalFileType * log_type ) {
return ParseFileName ( fname , number , " " , type , log_type ) ;
}
bool ParseFileName ( const std : : string & fname , uint64_t * number ,
const Slice & info_log_name_prefix , FileType * type ,
WalFileType * log_type ) {
Slice rest ( fname ) ;
Slice rest ( fname ) ;
if ( fname . length ( ) > 1 & & fname [ 0 ] = = ' / ' ) {
if ( fname . length ( ) > 1 & & fname [ 0 ] = = ' / ' ) {
rest . remove_prefix ( 1 ) ;
rest . remove_prefix ( 1 ) ;
@ -180,18 +201,22 @@ bool ParseFileName(const std::string& fname,
} else if ( rest = = " LOCK " ) {
} else if ( rest = = " LOCK " ) {
* number = 0 ;
* number = 0 ;
* type = kDBLockFile ;
* type = kDBLockFile ;
} else if ( rest = = " LOG " | | rest = = " LOG.old " ) {
} else if ( info_log_name_prefix . size ( ) > 0 & &
* number = 0 ;
rest . starts_with ( info_log_name_prefix ) ) {
* type = kInfoLogFile ;
rest . remove_prefix ( info_log_name_prefix . size ( ) ) ;
} else if ( rest . starts_with ( " LOG.old. " ) ) {
if ( rest = = " " | | rest = = " .old " ) {
uint64_t ts_suffix ;
* number = 0 ;
// sizeof also counts the trailing '\0'.
* type = kInfoLogFile ;
rest . remove_prefix ( sizeof ( " LOG.old. " ) - 1 ) ;
} else if ( rest . starts_with ( " .old. " ) ) {
if ( ! ConsumeDecimalNumber ( & rest , & ts_suffix ) ) {
uint64_t ts_suffix ;
return false ;
// sizeof also counts the trailing '\0'.
rest . remove_prefix ( sizeof ( " .old. " ) - 1 ) ;
if ( ! ConsumeDecimalNumber ( & rest , & ts_suffix ) ) {
return false ;
}
* number = ts_suffix ;
* type = kInfoLogFile ;
}
}
* number = ts_suffix ;
* type = kInfoLogFile ;
} else if ( rest . starts_with ( " MANIFEST- " ) ) {
} else if ( rest . starts_with ( " MANIFEST- " ) ) {
rest . remove_prefix ( strlen ( " MANIFEST- " ) ) ;
rest . remove_prefix ( strlen ( " MANIFEST- " ) ) ;
uint64_t num ;
uint64_t num ;