@ -21,6 +21,7 @@
# include "rocksdb/iterator.h"
# include "rocksdb/iterator.h"
# include "rocksdb/memtablerep.h"
# include "rocksdb/memtablerep.h"
# include "table/block_based_table_builder.h"
# include "table/block_based_table_builder.h"
# include "table/block_based_table_factory.h"
# include "table/block_based_table_reader.h"
# include "table/block_based_table_reader.h"
# include "table/block_builder.h"
# include "table/block_builder.h"
# include "table/block.h"
# include "table/block.h"
@ -44,12 +45,6 @@ static std::string Reverse(const Slice& key) {
return rev ;
return rev ;
}
}
static Options GetDefaultOptions ( ) {
Options options ;
options . SetUpDefaultFlushBlockPolicyFactory ( ) ;
return options ;
}
class ReverseKeyComparator : public Comparator {
class ReverseKeyComparator : public Comparator {
public :
public :
virtual const char * Name ( ) const {
virtual const char * Name ( ) const {
@ -257,7 +252,12 @@ class BlockBasedTableConstructor: public Constructor {
virtual Status FinishImpl ( const Options & options , const KVMap & data ) {
virtual Status FinishImpl ( const Options & options , const KVMap & data ) {
Reset ( ) ;
Reset ( ) ;
sink_ . reset ( new StringSink ( ) ) ;
sink_ . reset ( new StringSink ( ) ) ;
BlockBasedTableBuilder builder ( options , sink_ . get ( ) , options . compression ) ;
BlockBasedTableBuilder builder (
options ,
sink_ . get ( ) ,
new FlushBlockBySizePolicyFactory (
options . block_size , options . block_size_deviation ) ,
options . compression ) ;
for ( KVMap : : const_iterator it = data . begin ( ) ;
for ( KVMap : : const_iterator it = data . begin ( ) ;
it ! = data . end ( ) ;
it ! = data . end ( ) ;
@ -430,7 +430,7 @@ class DBConstructor: public Constructor {
void NewDB ( ) {
void NewDB ( ) {
std : : string name = test : : TmpDir ( ) + " /table_testdb " ;
std : : string name = test : : TmpDir ( ) + " /table_testdb " ;
Options options = GetDefaultOptions ( ) ;
Options options ;
options . comparator = comparator_ ;
options . comparator = comparator_ ;
Status status = DestroyDB ( name , options ) ;
Status status = DestroyDB ( name , options ) ;
ASSERT_TRUE ( status . ok ( ) ) < < status . ToString ( ) ;
ASSERT_TRUE ( status . ok ( ) ) < < status . ToString ( ) ;
@ -449,7 +449,7 @@ class DBConstructor: public Constructor {
static bool SnappyCompressionSupported ( ) {
static bool SnappyCompressionSupported ( ) {
std : : string out ;
std : : string out ;
Slice in = " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " ;
Slice in = " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " ;
return port : : Snappy_Compress ( GetDefault Options( ) . compression_opts ,
return port : : Snappy_Compress ( Options ( ) . compression_opts ,
in . data ( ) , in . size ( ) ,
in . data ( ) , in . size ( ) ,
& out ) ;
& out ) ;
}
}
@ -457,7 +457,7 @@ static bool SnappyCompressionSupported() {
static bool ZlibCompressionSupported ( ) {
static bool ZlibCompressionSupported ( ) {
std : : string out ;
std : : string out ;
Slice in = " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " ;
Slice in = " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " ;
return port : : Zlib_Compress ( GetDefault Options( ) . compression_opts ,
return port : : Zlib_Compress ( Options ( ) . compression_opts ,
in . data ( ) , in . size ( ) ,
in . data ( ) , in . size ( ) ,
& out ) ;
& out ) ;
}
}
@ -466,7 +466,7 @@ static bool ZlibCompressionSupported() {
static bool BZip2CompressionSupported ( ) {
static bool BZip2CompressionSupported ( ) {
std : : string out ;
std : : string out ;
Slice in = " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " ;
Slice in = " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " ;
return port : : BZip2_Compress ( GetDefault Options( ) . compression_opts ,
return port : : BZip2_Compress ( Options ( ) . compression_opts ,
in . data ( ) , in . size ( ) ,
in . data ( ) , in . size ( ) ,
& out ) ;
& out ) ;
}
}
@ -487,7 +487,7 @@ struct TestArgs {
} ;
} ;
static std : : vector < TestArgs > Generate_ Arg_ List ( ) {
static std : : vector < TestArgs > GenerateArgList ( ) {
std : : vector < TestArgs > ret ;
std : : vector < TestArgs > ret ;
TestType test_type [ 4 ] = { TABLE_TEST , BLOCK_TEST , MEMTABLE_TEST , DB_TEST } ;
TestType test_type [ 4 ] = { TABLE_TEST , BLOCK_TEST , MEMTABLE_TEST , DB_TEST } ;
int test_type_len = 4 ;
int test_type_len = 4 ;
@ -536,14 +536,13 @@ class Harness {
void Init ( const TestArgs & args ) {
void Init ( const TestArgs & args ) {
delete constructor_ ;
delete constructor_ ;
constructor_ = nullptr ;
constructor_ = nullptr ;
options_ = GetDefault Options( ) ;
options_ = Options ( ) ;
options_ . block_restart_interval = args . restart_interval ;
options_ . block_restart_interval = args . restart_interval ;
options_ . compression = args . compression ;
options_ . compression = args . compression ;
// Use shorter block size for tests to exercise block boundary
// Use shorter block size for tests to exercise block boundary
// conditions more.
// conditions more.
options_ . block_size = 256 ;
options_ . block_size = 256 ;
options_ . SetUpDefaultFlushBlockPolicyFactory ( ) ;
if ( args . reverse_compare ) {
if ( args . reverse_compare ) {
options_ . comparator = & reverse_key_comparator ;
options_ . comparator = & reverse_key_comparator ;
}
}
@ -737,13 +736,13 @@ class Harness {
DB * db ( ) const { return constructor_ - > db ( ) ; }
DB * db ( ) const { return constructor_ - > db ( ) ; }
private :
private :
Options options_ = GetDefault Options( ) ;
Options options_ = Options ( ) ;
Constructor * constructor_ ;
Constructor * constructor_ ;
} ;
} ;
// Test the empty key
// Test the empty key
TEST ( Harness , SimpleEmptyKey ) {
TEST ( Harness , SimpleEmptyKey ) {
std : : vector < TestArgs > args = Generate_ Arg_ List ( ) ;
std : : vector < TestArgs > args = GenerateArgList ( ) ;
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
Init ( args [ i ] ) ;
Init ( args [ i ] ) ;
Random rnd ( test : : RandomSeed ( ) + 1 ) ;
Random rnd ( test : : RandomSeed ( ) + 1 ) ;
@ -753,7 +752,7 @@ TEST(Harness, SimpleEmptyKey) {
}
}
TEST ( Harness , SimpleSingle ) {
TEST ( Harness , SimpleSingle ) {
std : : vector < TestArgs > args = Generate_ Arg_ List ( ) ;
std : : vector < TestArgs > args = GenerateArgList ( ) ;
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
Init ( args [ i ] ) ;
Init ( args [ i ] ) ;
Random rnd ( test : : RandomSeed ( ) + 2 ) ;
Random rnd ( test : : RandomSeed ( ) + 2 ) ;
@ -763,7 +762,7 @@ TEST(Harness, SimpleSingle) {
}
}
TEST ( Harness , SimpleMulti ) {
TEST ( Harness , SimpleMulti ) {
std : : vector < TestArgs > args = Generate_ Arg_ List ( ) ;
std : : vector < TestArgs > args = GenerateArgList ( ) ;
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
Init ( args [ i ] ) ;
Init ( args [ i ] ) ;
Random rnd ( test : : RandomSeed ( ) + 3 ) ;
Random rnd ( test : : RandomSeed ( ) + 3 ) ;
@ -775,7 +774,7 @@ TEST(Harness, SimpleMulti) {
}
}
TEST ( Harness , SimpleSpecialKey ) {
TEST ( Harness , SimpleSpecialKey ) {
std : : vector < TestArgs > args = Generate_ Arg_ List ( ) ;
std : : vector < TestArgs > args = GenerateArgList ( ) ;
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
Init ( args [ i ] ) ;
Init ( args [ i ] ) ;
Random rnd ( test : : RandomSeed ( ) + 4 ) ;
Random rnd ( test : : RandomSeed ( ) + 4 ) ;
@ -814,7 +813,7 @@ TEST(TableTest, BasicTableProperties) {
std : : vector < std : : string > keys ;
std : : vector < std : : string > keys ;
KVMap kvmap ;
KVMap kvmap ;
Options options = GetDefaultOptions ( ) ;
Options options ;
options . compression = kNoCompression ;
options . compression = kNoCompression ;
options . block_restart_interval = 1 ;
options . block_restart_interval = 1 ;
@ -848,7 +847,7 @@ TEST(TableTest, FilterPolicyNameProperties) {
c . Add ( " a1 " , " val1 " ) ;
c . Add ( " a1 " , " val1 " ) ;
std : : vector < std : : string > keys ;
std : : vector < std : : string > keys ;
KVMap kvmap ;
KVMap kvmap ;
Options options = GetDefaultOptions ( ) ;
Options options ;
std : : unique_ptr < const FilterPolicy > filter_policy (
std : : unique_ptr < const FilterPolicy > filter_policy (
NewBloomFilterPolicy ( 10 )
NewBloomFilterPolicy ( 10 )
) ;
) ;
@ -891,7 +890,7 @@ TEST(TableTest, IndexSizeStat) {
std : : vector < std : : string > ks ;
std : : vector < std : : string > ks ;
KVMap kvmap ;
KVMap kvmap ;
Options options = GetDefaultOptions ( ) ;
Options options ;
options . compression = kNoCompression ;
options . compression = kNoCompression ;
options . block_restart_interval = 1 ;
options . block_restart_interval = 1 ;
@ -910,11 +909,6 @@ TEST(TableTest, NumBlockStat) {
options . compression = kNoCompression ;
options . compression = kNoCompression ;
options . block_restart_interval = 1 ;
options . block_restart_interval = 1 ;
options . block_size = 1000 ;
options . block_size = 1000 ;
options . SetUpDefaultFlushBlockPolicyFactory ( ) ;
// Block Size changed, need to set up a new flush policy to reflect the
// change.
options . SetUpDefaultFlushBlockPolicyFactory ( ) ;
for ( int i = 0 ; i < 10 ; + + i ) {
for ( int i = 0 ; i < 10 ; + + i ) {
// the key/val are slightly smaller than block size, so that each block
// the key/val are slightly smaller than block size, so that each block
@ -979,7 +973,7 @@ class BlockCacheProperties {
TEST ( TableTest , BlockCacheTest ) {
TEST ( TableTest , BlockCacheTest ) {
// -- Table construction
// -- Table construction
Options options = GetDefaultOptions ( ) ;
Options options ;
options . create_if_missing = true ;
options . create_if_missing = true ;
options . statistics = CreateDBStatistics ( ) ;
options . statistics = CreateDBStatistics ( ) ;
options . block_cache = NewLRUCache ( 1024 ) ;
options . block_cache = NewLRUCache ( 1024 ) ;
@ -1117,9 +1111,8 @@ TEST(TableTest, ApproximateOffsetOfPlain) {
c . Add ( " k07 " , std : : string ( 100000 , ' x ' ) ) ;
c . Add ( " k07 " , std : : string ( 100000 , ' x ' ) ) ;
std : : vector < std : : string > keys ;
std : : vector < std : : string > keys ;
KVMap kvmap ;
KVMap kvmap ;
Options options = GetDefaultOptions ( ) ;
Options options ;
options . block_size = 1024 ;
options . block_size = 1024 ;
options . SetUpDefaultFlushBlockPolicyFactory ( ) ;
options . compression = kNoCompression ;
options . compression = kNoCompression ;
c . Finish ( options , & keys , & kvmap ) ;
c . Finish ( options , & keys , & kvmap ) ;
@ -1147,9 +1140,8 @@ static void Do_Compression_Test(CompressionType comp) {
c . Add ( " k04 " , test : : CompressibleString ( & rnd , 0.25 , 10000 , & tmp ) ) ;
c . Add ( " k04 " , test : : CompressibleString ( & rnd , 0.25 , 10000 , & tmp ) ) ;
std : : vector < std : : string > keys ;
std : : vector < std : : string > keys ;
KVMap kvmap ;
KVMap kvmap ;
Options options = GetDefaultOptions ( ) ;
Options options ;
options . block_size = 1024 ;
options . block_size = 1024 ;
options . SetUpDefaultFlushBlockPolicyFactory ( ) ;
options . compression = comp ;
options . compression = comp ;
c . Finish ( options , & keys , & kvmap ) ;
c . Finish ( options , & keys , & kvmap ) ;
@ -1190,9 +1182,8 @@ TEST(TableTest, BlockCacheLeak) {
// in the cache. This test checks whether the Table actually makes use of the
// in the cache. This test checks whether the Table actually makes use of the
// unique ID from the file.
// unique ID from the file.
Options opt = GetDefaultOptions ( ) ;
Options opt ;
opt . block_size = 1024 ;
opt . block_size = 1024 ;
opt . SetUpDefaultFlushBlockPolicyFactory ( ) ;
opt . compression = kNoCompression ;
opt . compression = kNoCompression ;
opt . block_cache = NewLRUCache ( 16 * 1024 * 1024 ) ; // big enough so we don't ever
opt . block_cache = NewLRUCache ( 16 * 1024 * 1024 ) ; // big enough so we don't ever
// lose cached values.
// lose cached values.
@ -1225,7 +1216,7 @@ TEST(TableTest, BlockCacheLeak) {
}
}
TEST ( Harness , Randomized ) {
TEST ( Harness , Randomized ) {
std : : vector < TestArgs > args = Generate_ Arg_ List ( ) ;
std : : vector < TestArgs > args = GenerateArgList ( ) ;
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
for ( unsigned int i = 0 ; i < args . size ( ) ; i + + ) {
Init ( args [ i ] ) ;
Init ( args [ i ] ) ;
Random rnd ( test : : RandomSeed ( ) + 5 ) ;
Random rnd ( test : : RandomSeed ( ) + 5 ) ;
@ -1277,7 +1268,7 @@ TEST(MemTableTest, Simple) {
MemTable * memtable = new MemTable ( cmp , table_factory ) ;
MemTable * memtable = new MemTable ( cmp , table_factory ) ;
memtable - > Ref ( ) ;
memtable - > Ref ( ) ;
WriteBatch batch ;
WriteBatch batch ;
Options options = GetDefaultOptions ( ) ;
Options options ;
WriteBatchInternal : : SetSequence ( & batch , 100 ) ;
WriteBatchInternal : : SetSequence ( & batch , 100 ) ;
batch . Put ( std : : string ( " k1 " ) , std : : string ( " v1 " ) ) ;
batch . Put ( std : : string ( " k1 " ) , std : : string ( " v1 " ) ) ;
batch . Put ( std : : string ( " k2 " ) , std : : string ( " v2 " ) ) ;
batch . Put ( std : : string ( " k2 " ) , std : : string ( " v2 " ) ) ;