@ -301,8 +301,9 @@ Status DBImpl::NewDB() {
return s ;
return s ;
}
}
Status DBImpl : : CreateAndNewDirectory ( Env * env , const std : : string & dirname ,
IOStatus DBImpl : : CreateAndNewDirectory (
std : : unique_ptr < Directory > * directory ) {
FileSystem * fs , const std : : string & dirname ,
std : : unique_ptr < FSDirectory > * directory ) {
// We call CreateDirIfMissing() as the directory may already exist (if we
// We call CreateDirIfMissing() as the directory may already exist (if we
// are reopening a DB), when this happens we don't want creating the
// are reopening a DB), when this happens we don't want creating the
// directory to cause an error. However, we need to check if creating the
// directory to cause an error. However, we need to check if creating the
@ -310,24 +311,24 @@ Status DBImpl::CreateAndNewDirectory(Env* env, const std::string& dirname,
// file not existing. One real-world example of this occurring is if
// file not existing. One real-world example of this occurring is if
// env->CreateDirIfMissing() doesn't create intermediate directories, e.g.
// env->CreateDirIfMissing() doesn't create intermediate directories, e.g.
// when dbname_ is "dir/db" but when "dir" doesn't exist.
// when dbname_ is "dir/db" but when "dir" doesn't exist.
Status s = env - > CreateDirIfMissing ( dirname ) ;
IO Status io_ s = fs - > CreateDirIfMissing ( dirname , IOOptions ( ) , nullptr ) ;
if ( ! s . ok ( ) ) {
if ( ! io_ s. ok ( ) ) {
return s ;
return io_ s;
}
}
return env - > NewDirectory ( dirname , directory ) ;
return fs - > NewDirectory ( dirname , IOOptions ( ) , directory , nullptr ) ;
}
}
Status Directories : : SetDirectories ( Env * env , const std : : string & dbname ,
IO Status Directories : : SetDirectories ( FileSystem * fs , const std : : string & dbname ,
const std : : string & wal_dir ,
const std : : string & wal_dir ,
const std : : vector < DbPath > & data_paths ) {
const std : : vector < DbPath > & data_paths ) {
Status s = DBImpl : : CreateAndNewDirectory ( env , dbname , & db_dir_ ) ;
IO Status io_ s = DBImpl : : CreateAndNewDirectory ( fs , dbname , & db_dir_ ) ;
if ( ! s . ok ( ) ) {
if ( ! io_ s. ok ( ) ) {
return s ;
return io_ s;
}
}
if ( ! wal_dir . empty ( ) & & dbname ! = wal_dir ) {
if ( ! wal_dir . empty ( ) & & dbname ! = wal_dir ) {
s = DBImpl : : CreateAndNewDirectory ( env , wal_dir , & wal_dir_ ) ;
io_ s = DBImpl : : CreateAndNewDirectory ( fs , wal_dir , & wal_dir_ ) ;
if ( ! s . ok ( ) ) {
if ( ! io_ s. ok ( ) ) {
return s ;
return io_ s;
}
}
}
}
@ -337,16 +338,16 @@ Status Directories::SetDirectories(Env* env, const std::string& dbname,
if ( db_path = = dbname ) {
if ( db_path = = dbname ) {
data_dirs_ . emplace_back ( nullptr ) ;
data_dirs_ . emplace_back ( nullptr ) ;
} else {
} else {
std : : unique_ptr < Directory > path_directory ;
std : : unique_ptr < FS Directory> path_directory ;
s = DBImpl : : CreateAndNewDirectory ( env , db_path , & path_directory ) ;
io_ s = DBImpl : : CreateAndNewDirectory ( fs , db_path , & path_directory ) ;
if ( ! s . ok ( ) ) {
if ( ! io_ s. ok ( ) ) {
return s ;
return io_ s;
}
}
data_dirs_ . emplace_back ( path_directory . release ( ) ) ;
data_dirs_ . emplace_back ( path_directory . release ( ) ) ;
}
}
}
}
assert ( data_dirs_ . size ( ) = = data_paths . size ( ) ) ;
assert ( data_dirs_ . size ( ) = = data_paths . size ( ) ) ;
return Status : : OK ( ) ;
return IO Status: : OK ( ) ;
}
}
Status DBImpl : : Recover (
Status DBImpl : : Recover (
@ -358,7 +359,7 @@ Status DBImpl::Recover(
bool is_new_db = false ;
bool is_new_db = false ;
assert ( db_lock_ = = nullptr ) ;
assert ( db_lock_ = = nullptr ) ;
if ( ! read_only ) {
if ( ! read_only ) {
Status s = directories_ . SetDirectories ( env_ , dbname_ ,
Status s = directories_ . SetDirectories ( fs_ . get ( ) , dbname_ ,
immutable_db_options_ . wal_dir ,
immutable_db_options_ . wal_dir ,
immutable_db_options_ . db_paths ) ;
immutable_db_options_ . db_paths ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
@ -458,7 +459,7 @@ Status DBImpl::Recover(
s = CheckConsistency ( ) ;
s = CheckConsistency ( ) ;
}
}
if ( s . ok ( ) & & ! read_only ) {
if ( s . ok ( ) & & ! read_only ) {
std : : map < std : : string , std : : shared_ptr < Directory > > created_dirs ;
std : : map < std : : string , std : : shared_ptr < FS Directory> > created_dirs ;
for ( auto cfd : * versions_ - > GetColumnFamilySet ( ) ) {
for ( auto cfd : * versions_ - > GetColumnFamilySet ( ) ) {
s = cfd - > AddDirectories ( & created_dirs ) ;
s = cfd - > AddDirectories ( & created_dirs ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
@ -1477,7 +1478,7 @@ Status DBImpl::Open(const DBOptions& db_options, const std::string& dbname,
}
}
impl - > DeleteObsoleteFiles ( ) ;
impl - > DeleteObsoleteFiles ( ) ;
s = impl - > directories_ . GetDbDir ( ) - > Fsync ( ) ;
s = impl - > directories_ . GetDbDir ( ) - > Fsync ( IOOptions ( ) , nullptr ) ;
}
}
if ( s . ok ( ) ) {
if ( s . ok ( ) ) {
// In WritePrepared there could be gap in sequence numbers. This breaks
// In WritePrepared there could be gap in sequence numbers. This breaks