@ -5,14 +5,16 @@
# ifndef ROCKSDB_LITE
# include <vector>
# include <string>
# include "table/cuckoo/cuckoo_table_builder.h"
# include <map>
# include <string>
# include <utility>
# include <vector>
# include "file/random_access_file_reader.h"
# include "file/writable_file_writer.h"
# include "table/cuckoo/cuckoo_table_builder .h"
# include "rocksdb/file_system .h"
# include "table/meta_blocks.h"
# include "test_util/testharness.h"
# include "test_util/testutil.h"
@ -35,7 +37,7 @@ class CuckooBuilderTest : public testing::Test {
env_ = Env : : Default ( ) ;
Options options ;
options . allow_mmap_reads = true ;
env _options_ = Env Options( options ) ;
fil e_options_ = File Options( options ) ;
}
void CheckFileContents ( const std : : vector < std : : string > & keys ,
@ -54,10 +56,11 @@ class CuckooBuilderTest : public testing::Test {
}
}
// Read file
std : : unique_ptr < RandomAccessFile > read_file ;
ASSERT_OK ( env_ - > NewRandomAccessFile ( fname , & read_file , env_options_ ) ) ;
uint64_t read_file_size ;
ASSERT_OK ( env_ - > GetFileSize ( fname , & read_file_size ) ) ;
std : : unique_ptr < RandomAccessFileReader > file_reader ;
ASSERT_OK ( RandomAccessFileReader : : Create (
env_ - > GetFileSystem ( ) , fname , file_options_ , & file_reader , nullptr ) ) ;
Options options ;
options . allow_mmap_reads = true ;
@ -65,9 +68,6 @@ class CuckooBuilderTest : public testing::Test {
// Assert Table Properties.
TableProperties * props = nullptr ;
std : : unique_ptr < RandomAccessFileReader > file_reader (
new RandomAccessFileReader ( NewLegacyRandomAccessFileWrapper ( read_file ) ,
fname ) ) ;
ASSERT_OK ( ReadTableProperties ( file_reader . get ( ) , read_file_size ,
kCuckooTableMagicNumber , ioptions ,
& props , true /* compression_type_missing */ ) ) ;
@ -158,7 +158,7 @@ class CuckooBuilderTest : public testing::Test {
Env * env_ ;
EnvOptions env _options_;
FileOptions file _options_;
std : : string fname ;
const double kHashTableRatio = 0.9 ;
} ;
@ -166,10 +166,9 @@ class CuckooBuilderTest : public testing::Test {
TEST_F ( CuckooBuilderTest , SuccessWithEmptyFile ) {
std : : unique_ptr < WritableFile > writable_file ;
fname = test : : PerThreadDBPath ( " EmptyFile " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , 4 , 100 ,
BytewiseComparator ( ) , 1 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,
@ -207,12 +206,10 @@ TEST_F(CuckooBuilderTest, WriteSuccessNoCollisionFullKey) {
}
uint64_t expected_table_size = GetExpectedTableSize ( keys . size ( ) ) ;
std : : unique_ptr < WritableFile > writable_file ;
fname = test : : PerThreadDBPath ( " NoCollisionFullKey " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , num_hash_fun ,
100 , BytewiseComparator ( ) , 1 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,
@ -257,12 +254,10 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionFullKey) {
}
uint64_t expected_table_size = GetExpectedTableSize ( keys . size ( ) ) ;
std : : unique_ptr < WritableFile > writable_file ;
fname = test : : PerThreadDBPath ( " WithCollisionFullKey " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , num_hash_fun ,
100 , BytewiseComparator ( ) , 1 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,
@ -306,13 +301,11 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionAndCuckooBlock) {
}
uint64_t expected_table_size = GetExpectedTableSize ( keys . size ( ) ) ;
std : : unique_ptr < WritableFile > writable_file ;
std : : unique_ptr < WritableFileWriter > file_writer ;
uint32_t cuckoo_block_size = 2 ;
fname = test : : PerThreadDBPath ( " WithCollisionFullKey2 " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder (
file_writer . get ( ) , kHashTableRatio , num_hash_fun , 100 ,
BytewiseComparator ( ) , cuckoo_block_size , false , false , GetSliceHash ,
@ -361,12 +354,10 @@ TEST_F(CuckooBuilderTest, WithCollisionPathFullKey) {
}
uint64_t expected_table_size = GetExpectedTableSize ( keys . size ( ) ) ;
std : : unique_ptr < WritableFile > writable_file ;
std : : unique_ptr < WritableFileWriter > file_writer ;
fname = test : : PerThreadDBPath ( " WithCollisionPathFullKey " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , num_hash_fun ,
100 , BytewiseComparator ( ) , 1 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,
@ -412,12 +403,10 @@ TEST_F(CuckooBuilderTest, WithCollisionPathFullKeyAndCuckooBlock) {
}
uint64_t expected_table_size = GetExpectedTableSize ( keys . size ( ) ) ;
std : : unique_ptr < WritableFile > writable_file ;
std : : unique_ptr < WritableFileWriter > file_writer ;
fname = test : : PerThreadDBPath ( " WithCollisionPathFullKeyAndCuckooBlock " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , num_hash_fun ,
100 , BytewiseComparator ( ) , 2 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,
@ -456,12 +445,11 @@ TEST_F(CuckooBuilderTest, WriteSuccessNoCollisionUserKey) {
std : : vector < uint64_t > expected_locations = { 0 , 1 , 2 , 3 } ;
uint64_t expected_table_size = GetExpectedTableSize ( user_keys . size ( ) ) ;
std : : unique_ptr < WritableFile > writable_file ;
std : : unique_ptr < WritableFileWriter > file_writer ;
fname = test : : PerThreadDBPath ( " NoCollisionUserKey " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , num_hash_fun ,
100 , BytewiseComparator ( ) , 1 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,
@ -501,12 +489,11 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionUserKey) {
std : : vector < uint64_t > expected_locations = { 0 , 1 , 2 , 3 } ;
uint64_t expected_table_size = GetExpectedTableSize ( user_keys . size ( ) ) ;
std : : unique_ptr < WritableFile > writable_file ;
std : : unique_ptr < WritableFileWriter > file_writer ;
fname = test : : PerThreadDBPath ( " WithCollisionUserKey " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , num_hash_fun ,
100 , BytewiseComparator ( ) , 1 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,
@ -548,12 +535,11 @@ TEST_F(CuckooBuilderTest, WithCollisionPathUserKey) {
std : : vector < uint64_t > expected_locations = { 0 , 1 , 3 , 4 , 2 } ;
uint64_t expected_table_size = GetExpectedTableSize ( user_keys . size ( ) ) ;
std : : unique_ptr < WritableFile > writable_file ;
std : : unique_ptr < WritableFileWriter > file_writer ;
fname = test : : PerThreadDBPath ( " WithCollisionPathUserKey " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , num_hash_fun ,
2 , BytewiseComparator ( ) , 1 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,
@ -594,12 +580,10 @@ TEST_F(CuckooBuilderTest, FailWhenCollisionPathTooLong) {
} ;
hash_map = std : : move ( hm ) ;
std : : unique_ptr < WritableFile > writable_file ;
std : : unique_ptr < WritableFileWriter > file_writer ;
fname = test : : PerThreadDBPath ( " WithCollisionPathUserKey " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , num_hash_fun ,
2 , BytewiseComparator ( ) , 1 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,
@ -623,12 +607,10 @@ TEST_F(CuckooBuilderTest, FailWhenSameKeyInserted) {
uint32_t num_hash_fun = 4 ;
std : : string user_key = " repeatedkey " ;
std : : unique_ptr < WritableFile > writable_file ;
std : : unique_ptr < WritableFileWriter > file_writer ;
fname = test : : PerThreadDBPath ( " FailWhenSameKeyInserted " ) ;
ASSERT_OK ( env_ - > NewWritableFile ( fname , & writable_file , env_options_ ) ) ;
std : : unique_ptr < WritableFileWriter > file_writer ( new WritableFileWriter (
NewLegacyWritableFileWrapper ( std : : move ( writable_file ) ) , fname ,
EnvOptions ( ) ) ) ;
ASSERT_OK ( WritableFileWriter : : Create ( env_ - > GetFileSystem ( ) , fname ,
file_options_ , & file_writer , nullptr ) ) ;
CuckooTableBuilder builder ( file_writer . get ( ) , kHashTableRatio , num_hash_fun ,
100 , BytewiseComparator ( ) , 1 , false , false ,
GetSliceHash , 0 /* column_family_id */ ,