@ -88,13 +88,19 @@ class EnvPosixTest : public testing::Test {
public :
public :
Env * env_ ;
Env * env_ ;
EnvPosixTest ( ) : env_ ( Env : : Default ( ) ) { }
bool direct_io_ ;
EnvPosixTest ( ) : env_ ( Env : : Default ( ) ) , direct_io_ ( false ) { }
} ;
} ;
class EnvPosixTestWithParam : public EnvPosixTest ,
class EnvPosixTestWithParam
public : : testing : : WithParamInterface < Env * > {
: public EnvPosixTest ,
public : : testing : : WithParamInterface < std : : pair < Env * , bool > > {
public :
public :
EnvPosixTestWithParam ( ) { env_ = GetParam ( ) ; }
EnvPosixTestWithParam ( ) {
std : : pair < Env * , bool > param_pair = GetParam ( ) ;
env_ = param_pair . first ;
direct_io_ = param_pair . second ;
}
void WaitThreadPoolsEmpty ( ) {
void WaitThreadPoolsEmpty ( ) {
// Wait until the thread pools are empty.
// Wait until the thread pools are empty.
@ -678,46 +684,48 @@ class IoctlFriendlyTmpdir {
std : : string dir_ ;
std : : string dir_ ;
} ;
} ;
TEST_F ( EnvPosixTest , PositionedAppend ) {
TEST_P ( EnvPosixTestWithParam , PositionedAppend ) {
unique_ptr < WritableFile > writable_file ;
if ( direct_io_ & & env_ = = Env : : Default ( ) ) {
unique_ptr < WritableFile > writable_file ;
EnvOptions options ;
EnvOptions options ;
options . use_direct_writes = true ;
options . use_direct_writes = direct_io_ ;
options . use_mmap_writes = false ;
options . use_mmap_writes = false ;
IoctlFriendlyTmpdir ift ;
IoctlFriendlyTmpdir ift ;
ASSERT_OK ( env_ - > NewWritableFile ( ift . name ( ) + " /f " , & writable_file , options ) ) ;
ASSERT_OK (
env_ - > NewWritableFile ( ift . name ( ) + " /f " , & writable_file , options ) ) ;
const size_t kBlockSize = 512 ;
const size_t kPageSize = 4096 ;
const size_t kBlockSize = 512 ;
const size_t kDataSize = kPageSize ;
const size_t kPageSize = 4096 ;
// Write a page worth of 'a'
const size_t kDataSize = kPageSize ;
auto data_ptr = NewAligned ( kDataSize , ' a ' ) ;
// Write a page worth of 'a'
Slice data_a ( data_ptr . get ( ) , kDataSize ) ;
auto data_ptr = NewAligned ( kDataSize , ' a ' ) ;
ASSERT_OK ( writable_file - > PositionedAppend ( data_a , 0U ) ) ;
Slice data_a ( data_ptr . get ( ) , kDataSize ) ;
// Write a page worth of 'b' right after the first sector
ASSERT_OK ( writable_file - > PositionedAppend ( data_a , 0U ) ) ;
data_ptr = NewAligned ( kDataSize , ' b ' ) ;
// Write a page worth of 'b' right after the first sector
Slice data_b ( data_ptr . get ( ) , kDataSize ) ;
data_ptr = NewAligned ( kDataSize , ' b ' ) ;
ASSERT_OK ( writable_file - > PositionedAppend ( data_b , kBlockSize ) ) ;
Slice data_b ( data_ptr . get ( ) , kDataSize ) ;
ASSERT_OK ( writable_file - > Close ( ) ) ;
ASSERT_OK ( writable_file - > PositionedAppend ( data_b , kBlockSize ) ) ;
// The file now has 1 sector worth of a followed by a page worth of b
ASSERT_OK ( writable_file - > Close ( ) ) ;
// The file now has 1 sector worth of a followed by a page worth of b
// Verify the above
unique_ptr < SequentialFile > seq_file ;
// Verify the above
ASSERT_OK ( env_ - > NewSequentialFile ( ift . name ( ) + " /f " , & seq_file , options ) ) ;
unique_ptr < SequentialFile > seq_file ;
char scratch [ kPageSize * 2 ] ;
ASSERT_OK ( env_ - > NewSequentialFile ( ift . name ( ) + " /f " , & seq_file , options ) ) ;
Slice result ;
char scratch [ kPageSize * 2 ] ;
ASSERT_OK ( seq_file - > Read ( sizeof ( scratch ) , & result , scratch ) ) ;
Slice result ;
ASSERT_EQ ( kPageSize + kBlockSize , result . size ( ) ) ;
ASSERT_OK ( seq_file - > Read ( sizeof ( scratch ) , & result , scratch ) ) ;
ASSERT_EQ ( ' a ' , result [ kBlockSize - 1 ] ) ;
ASSERT_EQ ( kPageSize + kBlockSize , result . size ( ) ) ;
ASSERT_EQ ( ' b ' , result [ kBlockSize ] ) ;
ASSERT_EQ ( ' a ' , result [ kBlockSize - 1 ] ) ;
ASSERT_EQ ( ' b ' , result [ kBlockSize ] ) ;
}
}
}
// Only works in linux platforms
// Only works in linux platforms
TEST_F ( EnvPosixTest , RandomAccessUniqueID ) {
TEST_P ( EnvPosixTestWithParam , RandomAccessUniqueID ) {
for ( bool directio : { true , false } ) {
// Create file.
// Create file.
if ( env_ = = Env : : Default ( ) ) {
EnvOptions soptions ;
EnvOptions soptions ;
soptions . use_direct_reads = soptions . use_direct_writes = directio ;
soptions . use_direct_reads = soptions . use_direct_writes = direct_ io_ ;
IoctlFriendlyTmpdir ift ;
IoctlFriendlyTmpdir ift ;
std : : string fname = ift . name ( ) + " /testfile " ;
std : : string fname = ift . name ( ) + " /testfile " ;
unique_ptr < WritableFile > wfile ;
unique_ptr < WritableFile > wfile ;
@ -758,8 +766,8 @@ TEST_F(EnvPosixTest, RandomAccessUniqueID) {
// only works in linux platforms
// only works in linux platforms
# ifdef ROCKSDB_FALLOCATE_PRESENT
# ifdef ROCKSDB_FALLOCATE_PRESENT
TEST_F ( EnvPosixTest , AllocateTest ) {
TEST_P ( EnvPosixTestWithParam , AllocateTest ) {
for ( bool directio : { true , false } ) {
if ( env_ = = Env : : Default ( ) ) {
IoctlFriendlyTmpdir ift ;
IoctlFriendlyTmpdir ift ;
std : : string fname = ift . name ( ) + " /preallocate_testfile " ;
std : : string fname = ift . name ( ) + " /preallocate_testfile " ;
@ -789,7 +797,7 @@ TEST_F(EnvPosixTest, AllocateTest) {
EnvOptions soptions ;
EnvOptions soptions ;
soptions . use_mmap_writes = false ;
soptions . use_mmap_writes = false ;
soptions . use_direct_reads = soptions . use_direct_writes = directio ;
soptions . use_direct_reads = soptions . use_direct_writes = direct_ io_ ;
unique_ptr < WritableFile > wfile ;
unique_ptr < WritableFile > wfile ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & wfile , soptions ) ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & wfile , soptions ) ) ;
@ -846,11 +854,11 @@ bool HasPrefix(const std::unordered_set<std::string>& ss) {
}
}
// Only works in linux and WIN platforms
// Only works in linux and WIN platforms
TEST_F ( EnvPosixTest , RandomAccessUniqueIDConcurrent ) {
TEST_P ( EnvPosixTestWithParam , RandomAccessUniqueIDConcurrent ) {
for ( bool directio : { true , false } ) {
if ( env_ = = Env : : Default ( ) ) {
// Check whether a bunch of concurrently existing files have unique IDs.
// Check whether a bunch of concurrently existing files have unique IDs.
EnvOptions soptions ;
EnvOptions soptions ;
soptions . use_direct_reads = soptions . use_direct_writes = directio ;
soptions . use_direct_reads = soptions . use_direct_writes = direct_ io_ ;
// Create the files
// Create the files
IoctlFriendlyTmpdir ift ;
IoctlFriendlyTmpdir ift ;
@ -888,10 +896,10 @@ TEST_F(EnvPosixTest, RandomAccessUniqueIDConcurrent) {
}
}
// Only works in linux and WIN platforms
// Only works in linux and WIN platforms
TEST_F ( EnvPosixTest , RandomAccessUniqueIDDeletes ) {
TEST_P ( EnvPosixTestWithParam , RandomAccessUniqueIDDeletes ) {
for ( bool directio : { true , false } ) {
if ( env_ = = Env : : Default ( ) ) {
EnvOptions soptions ;
EnvOptions soptions ;
soptions . use_direct_reads = soptions . use_direct_writes = directio ;
soptions . use_direct_reads = soptions . use_direct_writes = direct_ io_ ;
IoctlFriendlyTmpdir ift ;
IoctlFriendlyTmpdir ift ;
std : : string fname = ift . name ( ) + " / " + " testfile " ;
std : : string fname = ift . name ( ) + " / " + " testfile " ;
@ -935,9 +943,8 @@ TEST_P(EnvPosixTestWithParam, DISABLED_InvalidateCache) {
TEST_P ( EnvPosixTestWithParam , InvalidateCache ) {
TEST_P ( EnvPosixTestWithParam , InvalidateCache ) {
# endif
# endif
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
for ( bool directio : { true , false } ) {
EnvOptions soptions ;
EnvOptions soptions ;
soptions . use_direct_reads = soptions . use_direct_writes = directio ;
soptions . use_direct_reads = soptions . use_direct_writes = direct_ io_ ;
std : : string fname = test : : TmpDir ( env_ ) + " / " + " testfile " ;
std : : string fname = test : : TmpDir ( env_ ) + " / " + " testfile " ;
const size_t kSectorSize = 512 ;
const size_t kSectorSize = 512 ;
@ -997,7 +1004,6 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
}
}
// Delete the file
// Delete the file
ASSERT_OK ( env_ - > DeleteFile ( fname ) ) ;
ASSERT_OK ( env_ - > DeleteFile ( fname ) ) ;
}
rocksdb : : SyncPoint : : GetInstance ( ) - > ClearTrace ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > ClearTrace ( ) ;
}
}
# endif // not TRAVIS
# endif // not TRAVIS
@ -1121,12 +1127,10 @@ TEST_P(EnvPosixTestWithParam, LogBufferMaxSizeTest) {
TEST_P ( EnvPosixTestWithParam , Preallocation ) {
TEST_P ( EnvPosixTestWithParam , Preallocation ) {
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
for ( bool directio : { true , false } ) {
const std : : string src = test : : TmpDir ( env_ ) + " / " + " testfile " ;
const std : : string src = test : : TmpDir ( env_ ) + " / " + " testfile " ;
unique_ptr < WritableFile > srcfile ;
unique_ptr < WritableFile > srcfile ;
EnvOptions soptions ;
EnvOptions soptions ;
soptions . use_direct_reads = soptions . use_direct_writes = directio ;
soptions . use_direct_reads = soptions . use_direct_writes = direct_ io_ ;
# if !defined(OS_MACOSX) && !defined(OS_WIN)
# if !defined(OS_MACOSX) && !defined(OS_WIN)
if ( soptions . use_direct_writes ) {
if ( soptions . use_direct_writes ) {
rocksdb : : SyncPoint : : GetInstance ( ) - > SetCallBack (
rocksdb : : SyncPoint : : GetInstance ( ) - > SetCallBack (
@ -1172,7 +1176,6 @@ TEST_P(EnvPosixTestWithParam, Preallocation) {
srcfile - > GetPreallocationStatus ( & block_size , & last_allocated_block ) ;
srcfile - > GetPreallocationStatus ( & block_size , & last_allocated_block ) ;
ASSERT_EQ ( last_allocated_block , 7UL ) ;
ASSERT_EQ ( last_allocated_block , 7UL ) ;
}
}
}
rocksdb : : SyncPoint : : GetInstance ( ) - > ClearTrace ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > ClearTrace ( ) ;
}
}
@ -1180,9 +1183,8 @@ TEST_P(EnvPosixTestWithParam, Preallocation) {
// individually) behave consistently.
// individually) behave consistently.
TEST_P ( EnvPosixTestWithParam , ConsistentChildrenAttributes ) {
TEST_P ( EnvPosixTestWithParam , ConsistentChildrenAttributes ) {
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
for ( bool directio : { true , false } ) {
EnvOptions soptions ;
EnvOptions soptions ;
soptions . use_direct_reads = soptions . use_direct_writes = directio ;
soptions . use_direct_reads = soptions . use_direct_writes = direct_ io_ ;
const int kNumChildren = 10 ;
const int kNumChildren = 10 ;
std : : string data ;
std : : string data ;
@ -1224,7 +1226,6 @@ TEST_P(EnvPosixTestWithParam, ConsistentChildrenAttributes) {
ASSERT_EQ ( size , 512 * i ) ;
ASSERT_EQ ( size , 512 * i ) ;
ASSERT_EQ ( size , file_attrs_iter - > size_bytes ) ;
ASSERT_EQ ( size , file_attrs_iter - > size_bytes ) ;
}
}
}
rocksdb : : SyncPoint : : GetInstance ( ) - > ClearTrace ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > ClearTrace ( ) ;
}
}
@ -1462,13 +1463,24 @@ TEST_P(EnvPosixTestWithParam, PosixRandomRWFileRandomized) {
env_ - > DeleteFile ( path ) ;
env_ - > DeleteFile ( path ) ;
}
}
INSTANTIATE_TEST_CASE_P ( DefaultEnv , EnvPosixTestWithParam ,
INSTANTIATE_TEST_CASE_P ( DefaultEnvWithoutDirectIO , EnvPosixTestWithParam ,
: : testing : : Values ( Env : : Default ( ) ) ) ;
: : testing : : Values ( std : : pair < Env * , bool > ( Env : : Default ( ) ,
false ) ) ) ;
# if !defined(ROCKSDB_LITE)
INSTANTIATE_TEST_CASE_P ( DefaultEnvWithDirectIO , EnvPosixTestWithParam ,
: : testing : : Values ( std : : pair < Env * , bool > ( Env : : Default ( ) ,
true ) ) ) ;
# endif // !defined(ROCKSDB_LITE)
# if !defined(ROCKSDB_LITE) && !defined(OS_WIN)
# if !defined(ROCKSDB_LITE) && !defined(OS_WIN)
static unique_ptr < Env > chroot_env ( NewChrootEnv ( Env : : Default ( ) ,
static unique_ptr < Env > chroot_env ( NewChrootEnv ( Env : : Default ( ) ,
test : : TmpDir ( Env : : Default ( ) ) ) ) ;
test : : TmpDir ( Env : : Default ( ) ) ) ) ;
INSTANTIATE_TEST_CASE_P ( ChrootEnv , EnvPosixTestWithParam ,
INSTANTIATE_TEST_CASE_P (
: : testing : : Values ( chroot_env . get ( ) ) ) ;
ChrootEnvWithoutDirectIO , EnvPosixTestWithParam ,
: : testing : : Values ( std : : pair < Env * , bool > ( chroot_env . get ( ) , false ) ) ) ;
INSTANTIATE_TEST_CASE_P (
ChrootEnvWithDirectIO , EnvPosixTestWithParam ,
: : testing : : Values ( std : : pair < Env * , bool > ( chroot_env . get ( ) , true ) ) ) ;
# endif // !defined(ROCKSDB_LITE) && !defined(OS_WIN)
# endif // !defined(ROCKSDB_LITE) && !defined(OS_WIN)
} // namespace rocksdb
} // namespace rocksdb