@ -34,11 +34,40 @@
# include "util/logging.h"
# include "util/mutexlock.h"
# include "util/build_version.h"
# include "util/auto_split_logger.h"
namespace leveldb {
void dumpLeveldbBuildVersion ( Logger * log ) ;
static Status NewLogger ( const std : : string & dbname ,
const std : : string & db_log_dir ,
Env * env ,
size_t max_log_file_size ,
Logger * * logger ) {
std : : string db_absolute_path ;
env - > GetAbsolutePath ( dbname , & db_absolute_path ) ;
if ( max_log_file_size > 0 ) { // need to auto split the log file?
AutoSplitLogger < Logger > * auto_split_logger =
new AutoSplitLogger < Logger > ( env , dbname , db_log_dir , max_log_file_size ) ;
Status s = auto_split_logger - > GetStatus ( ) ;
if ( ! s . ok ( ) ) {
delete auto_split_logger ;
} else {
* logger = auto_split_logger ;
}
return s ;
} else {
// Open a log file in the same directory as the db
env - > CreateDir ( dbname ) ; // In case it does not exist
std : : string fname = InfoLogFileName ( dbname , db_absolute_path , db_log_dir ) ;
env - > RenameFile ( fname , OldInfoLogFileName ( dbname , env - > NowMicros ( ) ,
db_absolute_path , db_log_dir ) ) ;
return env - > NewLogger ( fname , logger ) ;
}
}
// Information kept for every waiting writer
struct DBImpl : : Writer {
Status status ;
@ -116,16 +145,9 @@ Options SanitizeOptions(const std::string& dbname,
ClipToRange ( & result . max_open_files , 20 , 50000 ) ;
ClipToRange ( & result . write_buffer_size , 64 < < 10 , 1 < < 30 ) ;
ClipToRange ( & result . block_size , 1 < < 10 , 4 < < 20 ) ;
std : : string db_absolute_path ;
src . env - > GetAbsolutePath ( dbname , & db_absolute_path ) ;
if ( result . info_log = = NULL ) {
// Open a log file in the same directory as the db
src . env - > CreateDir ( dbname ) ; // In case it does not exist
src . env - > RenameFile ( InfoLogFileName ( dbname , db_absolute_path ,
result . db_log_dir ) , OldInfoLogFileName ( dbname , src . env - > NowMicros ( ) ,
db_absolute_path , result . db_log_dir ) ) ;
Status s = src . env - > NewLogger ( InfoLogFileName ( dbname , db_absolute_path ,
result . db_log_dir ) , & result . info_log ) ;
Status s = NewLogger ( dbname , result . db_log_dir , src . env ,
result . max_log_file_size , & result . info_log ) ;
if ( ! s . ok ( ) ) {
// No place suitable for logging
result . info_log = NULL ;