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