@ -3,6 +3,8 @@
// COPYING file in the root directory) and Apache 2.0 License
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
// (found in the LICENSE.Apache file in the root directory).
# include <memory>
# include "db/blob/blob_index.h"
# include "db/blob/blob_index.h"
# include "db/db_impl/db_impl.h"
# include "db/db_impl/db_impl.h"
# include "db/db_test_util.h"
# include "db/db_test_util.h"
@ -707,27 +709,28 @@ TEST_F(EventListenerTest, CompactionReasonFIFO) {
class TableFileCreationListener : public EventListener {
class TableFileCreationListener : public EventListener {
public :
public :
class TestEnv : public Env Wrapper {
class TestFS : public FileSystem Wrapper {
public :
public :
explicit TestEnv ( Env * t ) : EnvWrapper ( t ) { }
explicit TestFS ( const std : : shared_ptr < FileSystem > & t )
: FileSystemWrapper ( t ) { }
static const char * kClassName ( ) { return " TestEnv " ; }
static const char * kClassName ( ) { return " TestEnv " ; }
const char * Name ( ) const override { return kClassName ( ) ; }
const char * Name ( ) const override { return kClassName ( ) ; }
void SetStatus ( Status s ) { status_ = s ; }
void SetStatus ( IO Status s ) { status_ = s ; }
Status NewWritableFile ( const std : : string & fname ,
IO Status NewWritableFile ( const std : : string & fname , const FileOptions & opts ,
std : : unique_ptr < WritableFile > * result ,
std : : unique_ptr < FS WritableFile> * result ,
const EnvOptions & options ) override {
IODebugContext * dbg ) override {
if ( fname . size ( ) > 4 & & fname . substr ( fname . size ( ) - 4 ) = = " .sst " ) {
if ( fname . size ( ) > 4 & & fname . substr ( fname . size ( ) - 4 ) = = " .sst " ) {
if ( ! status_ . ok ( ) ) {
if ( ! status_ . ok ( ) ) {
return status_ ;
return status_ ;
}
}
}
}
return target ( ) - > NewWritableFile ( fname , result , options ) ;
return target ( ) - > NewWritableFile ( fname , opts , result , dbg ) ;
}
}
private :
private :
Status status_ ;
IO Status status_ ;
} ;
} ;
TableFileCreationListener ( ) {
TableFileCreationListener ( ) {
@ -813,8 +816,10 @@ class TableFileCreationListener : public EventListener {
TEST_F ( EventListenerTest , TableFileCreationListenersTest ) {
TEST_F ( EventListenerTest , TableFileCreationListenersTest ) {
auto listener = std : : make_shared < TableFileCreationListener > ( ) ;
auto listener = std : : make_shared < TableFileCreationListener > ( ) ;
Options options ;
Options options ;
std : : unique_ptr < TableFileCreationListener : : TestEnv > test_env (
std : : shared_ptr < TableFileCreationListener : : TestFS > test_fs =
new TableFileCreationListener : : TestEnv ( CurrentOptions ( ) . env ) ) ;
std : : make_shared < TableFileCreationListener : : TestFS > (
CurrentOptions ( ) . env - > GetFileSystem ( ) ) ;
std : : unique_ptr < Env > test_env = NewCompositeEnv ( test_fs ) ;
options . create_if_missing = true ;
options . create_if_missing = true ;
options . listeners . push_back ( listener ) ;
options . listeners . push_back ( listener ) ;
options . env = test_env . get ( ) ;
options . env = test_env . get ( ) ;
@ -827,11 +832,11 @@ TEST_F(EventListenerTest, TableFileCreationListenersTest) {
listener - > CheckAndResetCounters ( 1 , 1 , 0 , 0 , 0 , 0 ) ;
listener - > CheckAndResetCounters ( 1 , 1 , 0 , 0 , 0 , 0 ) ;
ASSERT_OK ( Put ( " foo " , " aaa1 " ) ) ;
ASSERT_OK ( Put ( " foo " , " aaa1 " ) ) ;
ASSERT_OK ( Put ( " bar " , " bbb1 " ) ) ;
ASSERT_OK ( Put ( " bar " , " bbb1 " ) ) ;
test_env - > SetStatus ( Status : : NotSupported ( " not supported " ) ) ;
test_fs - > SetStatus ( IO Status: : NotSupported ( " not supported " ) ) ;
ASSERT_NOK ( Flush ( ) ) ;
ASSERT_NOK ( Flush ( ) ) ;
listener - > CheckAndResetCounters ( 1 , 1 , 1 , 0 , 0 , 0 ) ;
listener - > CheckAndResetCounters ( 1 , 1 , 1 , 0 , 0 , 0 ) ;
ASSERT_TRUE ( listener - > last_failure_ . IsNotSupported ( ) ) ;
ASSERT_TRUE ( listener - > last_failure_ . IsNotSupported ( ) ) ;
test_env - > SetStatus ( Status : : OK ( ) ) ;
test_fs - > SetStatus ( IO Status: : OK ( ) ) ;
Reopen ( options ) ;
Reopen ( options ) ;
ASSERT_OK ( Put ( " foo " , " aaa2 " ) ) ;
ASSERT_OK ( Put ( " foo " , " aaa2 " ) ) ;
@ -850,7 +855,7 @@ TEST_F(EventListenerTest, TableFileCreationListenersTest) {
ASSERT_OK ( Put ( " foo " , " aaa3 " ) ) ;
ASSERT_OK ( Put ( " foo " , " aaa3 " ) ) ;
ASSERT_OK ( Put ( " bar " , " bbb3 " ) ) ;
ASSERT_OK ( Put ( " bar " , " bbb3 " ) ) ;
ASSERT_OK ( Flush ( ) ) ;
ASSERT_OK ( Flush ( ) ) ;
test_env - > SetStatus ( Status : : NotSupported ( " not supported " ) ) ;
test_fs - > SetStatus ( IO Status: : NotSupported ( " not supported " ) ) ;
ASSERT_NOK (
ASSERT_NOK (
dbfull ( ) - > CompactRange ( CompactRangeOptions ( ) , & kRangeStart , & kRangeEnd ) ) ;
dbfull ( ) - > CompactRange ( CompactRangeOptions ( ) , & kRangeStart , & kRangeEnd ) ) ;
ASSERT_NOK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
ASSERT_NOK ( dbfull ( ) - > TEST_WaitForCompact ( ) ) ;
@ -858,7 +863,7 @@ TEST_F(EventListenerTest, TableFileCreationListenersTest) {
ASSERT_TRUE ( listener - > last_failure_ . IsNotSupported ( ) ) ;
ASSERT_TRUE ( listener - > last_failure_ . IsNotSupported ( ) ) ;
// Reset
// Reset
test_env - > SetStatus ( Status : : OK ( ) ) ;
test_fs - > SetStatus ( IO Status: : OK ( ) ) ;
DestroyAndReopen ( options ) ;
DestroyAndReopen ( options ) ;
// Verify that an empty table file that is immediately deleted gives Aborted
// Verify that an empty table file that is immediately deleted gives Aborted