@ -291,20 +291,18 @@ class CompositeEnvWrapper : public Env {
public :
// Initialize a CompositeEnvWrapper that delegates all thread/time related
// calls to env, and all file operations to fs
explicit CompositeEnvWrapper ( Env * env , FileSystem * fs )
: env_target_ ( env ) , fs_ env_target_( fs ) { }
explicit CompositeEnvWrapper ( Env * env , std : : shared_ptr < FileSystem > fs )
: Env ( fs ) , env_target_ ( env ) { }
~ CompositeEnvWrapper ( ) { }
// Return the target to which this Env forwards all calls
Env * env_target ( ) const { return env_target_ ; }
FileSystem * fs_env_target ( ) const { return fs_env_target_ ; }
Status RegisterDbPaths ( const std : : vector < std : : string > & paths ) override {
return fs_env_target _ - > RegisterDbPaths ( paths ) ;
return file_system_ - > RegisterDbPaths ( paths ) ;
}
Status UnregisterDbPaths ( const std : : vector < std : : string > & paths ) override {
return fs_env_target _ - > UnregisterDbPaths ( paths ) ;
return file_system _ - > UnregisterDbPaths ( paths ) ;
}
// The following text is boilerplate that forwards all methods to target()
@ -315,7 +313,7 @@ class CompositeEnvWrapper : public Env {
std : : unique_ptr < FSSequentialFile > file ;
Status status ;
status =
fs_env_target _ - > NewSequentialFile ( f , FileOptions ( options ) , & file , & dbg ) ;
file_system _ - > NewSequentialFile ( f , FileOptions ( options ) , & file , & dbg ) ;
if ( status . ok ( ) ) {
r - > reset ( new CompositeSequentialFileWrapper ( file ) ) ;
}
@ -327,8 +325,8 @@ class CompositeEnvWrapper : public Env {
IODebugContext dbg ;
std : : unique_ptr < FSRandomAccessFile > file ;
Status status ;
status = fs_env_target_ - > NewRandomAccessFile ( f , FileOptions ( options ) , & file ,
& dbg ) ;
status =
file_system_ - > NewRandomAccessFile ( f , FileOptions ( options ) , & file , & dbg ) ;
if ( status . ok ( ) ) {
r - > reset ( new CompositeRandomAccessFileWrapper ( file ) ) ;
}
@ -340,7 +338,7 @@ class CompositeEnvWrapper : public Env {
std : : unique_ptr < FSWritableFile > file ;
Status status ;
status =
fs_env_target _ - > NewWritableFile ( f , FileOptions ( options ) , & file , & dbg ) ;
file_system _ - > NewWritableFile ( f , FileOptions ( options ) , & file , & dbg ) ;
if ( status . ok ( ) ) {
r - > reset ( new CompositeWritableFileWrapper ( file ) ) ;
}
@ -352,8 +350,8 @@ class CompositeEnvWrapper : public Env {
IODebugContext dbg ;
Status status ;
std : : unique_ptr < FSWritableFile > file ;
status = fs_env_target _ - > ReopenWritableFile ( fname , FileOptions ( options ) ,
& file , & dbg ) ;
status = file_system _ - > ReopenWritableFile ( fname , FileOptions ( options ) ,
& file , & dbg ) ;
if ( status . ok ( ) ) {
result - > reset ( new CompositeWritableFileWrapper ( file ) ) ;
}
@ -366,8 +364,8 @@ class CompositeEnvWrapper : public Env {
IODebugContext dbg ;
Status status ;
std : : unique_ptr < FSWritableFile > file ;
status = fs_env_target _ - > ReuseWritableFile (
fname , old_fname , FileOptions ( options ) , & file , & dbg ) ;
status = file_system _ - > ReuseWritableFile ( fname , old_fname ,
FileOptions ( options ) , & file , & dbg ) ;
if ( status . ok ( ) ) {
r - > reset ( new CompositeWritableFileWrapper ( file ) ) ;
}
@ -379,8 +377,8 @@ class CompositeEnvWrapper : public Env {
IODebugContext dbg ;
std : : unique_ptr < FSRandomRWFile > file ;
Status status ;
status = fs_env_target_ - > NewRandomRWFile ( fname , FileOptions ( options ) , & file ,
& dbg ) ;
status =
file_system_ - > NewRandomRWFile ( fname , FileOptions ( options ) , & file , & dbg ) ;
if ( status . ok ( ) ) {
result - > reset ( new CompositeRandomRWFileWrapper ( file ) ) ;
}
@ -389,7 +387,7 @@ class CompositeEnvWrapper : public Env {
Status NewMemoryMappedFileBuffer (
const std : : string & fname ,
std : : unique_ptr < MemoryMappedFileBuffer > * result ) override {
return fs_env_target _ - > NewMemoryMappedFileBuffer ( fname , result ) ;
return file_system _ - > NewMemoryMappedFileBuffer ( fname , result ) ;
}
Status NewDirectory ( const std : : string & name ,
std : : unique_ptr < Directory > * result ) override {
@ -397,7 +395,7 @@ class CompositeEnvWrapper : public Env {
IODebugContext dbg ;
std : : unique_ptr < FSDirectory > dir ;
Status status ;
status = fs_env_target _ - > NewDirectory ( name , io_opts , & dir , & dbg ) ;
status = file_system _ - > NewDirectory ( name , io_opts , & dir , & dbg ) ;
if ( status . ok ( ) ) {
result - > reset ( new CompositeDirectoryWrapper ( dir ) ) ;
}
@ -406,102 +404,108 @@ class CompositeEnvWrapper : public Env {
Status FileExists ( const std : : string & f ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > FileExists ( f , io_opts , & dbg ) ;
return file_system _ - > FileExists ( f , io_opts , & dbg ) ;
}
Status GetChildren ( const std : : string & dir ,
std : : vector < std : : string > * r ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > GetChildren ( dir , io_opts , r , & dbg ) ;
return file_system _ - > GetChildren ( dir , io_opts , r , & dbg ) ;
}
Status GetChildrenFileAttributes (
const std : : string & dir , std : : vector < FileAttributes > * result ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target_ - > GetChildrenFileAttributes ( dir , io_opts , result ,
& dbg ) ;
return file_system_ - > GetChildrenFileAttributes ( dir , io_opts , result , & dbg ) ;
}
Status DeleteFile ( const std : : string & f ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > DeleteFile ( f , io_opts , & dbg ) ;
return file_system _ - > DeleteFile ( f , io_opts , & dbg ) ;
}
Status Truncate ( const std : : string & fname , size_t size ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > Truncate ( fname , size , io_opts , & dbg ) ;
return file_system _ - > Truncate ( fname , size , io_opts , & dbg ) ;
}
Status CreateDir ( const std : : string & d ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > CreateDir ( d , io_opts , & dbg ) ;
return file_system _ - > CreateDir ( d , io_opts , & dbg ) ;
}
Status CreateDirIfMissing ( const std : : string & d ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > CreateDirIfMissing ( d , io_opts , & dbg ) ;
return file_system _ - > CreateDirIfMissing ( d , io_opts , & dbg ) ;
}
Status DeleteDir ( const std : : string & d ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > DeleteDir ( d , io_opts , & dbg ) ;
return file_system _ - > DeleteDir ( d , io_opts , & dbg ) ;
}
Status GetFileSize ( const std : : string & f , uint64_t * s ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > GetFileSize ( f , io_opts , s , & dbg ) ;
return file_system _ - > GetFileSize ( f , io_opts , s , & dbg ) ;
}
Status GetFileModificationTime ( const std : : string & fname ,
uint64_t * file_mtime ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > GetFileModificationTime ( fname , io_opts , file_mtime ,
& dbg ) ;
return file_system _ - > GetFileModificationTime ( fname , io_opts , file_mtime ,
& dbg ) ;
}
Status RenameFile ( const std : : string & s , const std : : string & t ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > RenameFile ( s , t , io_opts , & dbg ) ;
return file_system _ - > RenameFile ( s , t , io_opts , & dbg ) ;
}
Status LinkFile ( const std : : string & s , const std : : string & t ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > LinkFile ( s , t , io_opts , & dbg ) ;
return file_system _ - > LinkFile ( s , t , io_opts , & dbg ) ;
}
Status NumFileLinks ( const std : : string & fname , uint64_t * count ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > NumFileLinks ( fname , io_opts , count , & dbg ) ;
return file_system _ - > NumFileLinks ( fname , io_opts , count , & dbg ) ;
}
Status AreFilesSame ( const std : : string & first , const std : : string & second ,
bool * res ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > AreFilesSame ( first , second , io_opts , res , & dbg ) ;
return file_system _ - > AreFilesSame ( first , second , io_opts , res , & dbg ) ;
}
Status LockFile ( const std : : string & f , FileLock * * l ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > LockFile ( f , io_opts , l , & dbg ) ;
return file_system _ - > LockFile ( f , io_opts , l , & dbg ) ;
}
Status UnlockFile ( FileLock * l ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > UnlockFile ( l , io_opts , & dbg ) ;
return file_system _ - > UnlockFile ( l , io_opts , & dbg ) ;
}
Status GetAbsolutePath ( const std : : string & db_path ,
std : : string * output_path ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target_ - > GetAbsolutePath ( db_path , io_opts , output_path , & dbg ) ;
return file_system_ - > GetAbsolutePath ( db_path , io_opts , output_path , & dbg ) ;
}
Status NewLogger ( const std : : string & fname ,
std : : shared_ptr < Logger > * result ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return file_system_ - > NewLogger ( fname , io_opts , result , & dbg ) ;
}
# if !defined(OS_WIN) && !defined(ROCKSDB_NO_DYNAMIC_EXTENSION)
@ -531,10 +535,6 @@ class CompositeEnvWrapper : public Env {
Status GetTestDirectory ( std : : string * path ) override {
return env_target_ - > GetTestDirectory ( path ) ;
}
Status NewLogger ( const std : : string & fname ,
std : : shared_ptr < Logger > * result ) override {
return env_target_ - > NewLogger ( fname , result ) ;
}
uint64_t NowMicros ( ) override { return env_target_ - > NowMicros ( ) ; }
uint64_t NowNanos ( ) override { return env_target_ - > NowNanos ( ) ; }
uint64_t NowCPUNanos ( ) override { return env_target_ - > NowCPUNanos ( ) ; }
@ -590,46 +590,41 @@ class CompositeEnvWrapper : public Env {
}
EnvOptions OptimizeForLogRead ( const EnvOptions & env_options ) const override {
return fs_env_target _ - > OptimizeForLogRead ( FileOptions ( env_options ) ) ;
return file_system _ - > OptimizeForLogRead ( FileOptions ( env_options ) ) ;
}
EnvOptions OptimizeForManifestRead (
const EnvOptions & env_options ) const override {
return fs_env_target_ - > OptimizeForManifestRead (
FileOptions ( env_options ) ) ;
return file_system_ - > OptimizeForManifestRead ( FileOptions ( env_options ) ) ;
}
EnvOptions OptimizeForLogWrite ( const EnvOptions & env_options ,
const DBOptions & db_options ) const override {
return fs_env_target _ - > OptimizeForLogWrite ( FileOptions ( env_options ) ,
db_options ) ;
return file_system _ - > OptimizeForLogWrite ( FileOptions ( env_options ) ,
db_options ) ;
}
EnvOptions OptimizeForManifestWrite (
const EnvOptions & env_options ) const override {
return fs_env_target_ - > OptimizeForManifestWrite (
FileOptions ( env_options ) ) ;
return file_system_ - > OptimizeForManifestWrite ( FileOptions ( env_options ) ) ;
}
EnvOptions OptimizeForCompactionTableWrite (
const EnvOptions & env_options ,
const ImmutableDBOptions & immutable_ops ) const override {
return fs_env_target_ - > OptimizeForCompactionTableWrite (
FileOptions ( env_options ) ,
immutable_ops ) ;
return file_system_ - > OptimizeForCompactionTableWrite (
FileOptions ( env_options ) , immutable_ops ) ;
}
EnvOptions OptimizeForCompactionTableRead (
const EnvOptions & env_options ,
const ImmutableDBOptions & db_options ) const override {
return fs_env_target_ - > OptimizeForCompactionTableRead (
FileOptions ( env_options ) ,
db_options ) ;
return file_system_ - > OptimizeForCompactionTableRead (
FileOptions ( env_options ) , db_options ) ;
}
Status GetFreeSpace ( const std : : string & path , uint64_t * diskfree ) override {
IOOptions io_opts ;
IODebugContext dbg ;
return fs_env_target _ - > GetFreeSpace ( path , io_opts , diskfree , & dbg ) ;
return file_system _ - > GetFreeSpace ( path , io_opts , diskfree , & dbg ) ;
}
private :
Env * env_target_ ;
FileSystem * fs_env_target_ ;
} ;
class LegacySequentialFileWrapper : public FSSequentialFile {
@ -1067,6 +1062,10 @@ class LegacyFileSystemWrapper : public FileSystem {
return status_to_io_status ( target_ - > NewLogger ( fname , result ) ) ;
}
void SanitizeFileOptions ( FileOptions * opts ) const override {
target_ - > SanitizeEnvOptions ( opts ) ;
}
FileOptions OptimizeForLogRead (
const FileOptions & file_options ) const override {
return target_ - > OptimizeForLogRead ( file_options ) ;