@ -49,32 +49,32 @@ static void StartPhase(const char* name) {
}
# ifdef _MSC_VER
# pragma warning(push)
# pragma warning (disable: 4996) // getenv security warning
# pragma warning(disable : 4996) // getenv security warning
# endif
static const char * GetTempDir ( void ) {
const char * ret = getenv ( " TEST_TMPDIR " ) ;
if ( ret = = NULL | | ret [ 0 ] = = ' \0 ' )
const char * ret = getenv ( " TEST_TMPDIR " ) ;
if ( ret = = NULL | | ret [ 0 ] = = ' \0 ' )
# ifdef OS_WIN
ret = getenv ( " TEMP " ) ;
ret = getenv ( " TEMP " ) ;
# else
ret = " /tmp " ;
ret = " /tmp " ;
# endif
return ret ;
return ret ;
}
# ifdef _MSC_VER
# pragma warning(pop)
# endif
# define CheckNoError(err) \
if ( ( err ) ! = NULL ) { \
# define CheckNoError(err) \
if ( ( err ) ! = NULL ) { \
fprintf ( stderr , " %s:%d: %s: %s \n " , __FILE__ , __LINE__ , phase , ( err ) ) ; \
abort ( ) ; \
abort ( ) ; \
}
# define CheckCondition(cond) \
if ( ! ( cond ) ) { \
# define CheckCondition(cond) \
if ( ! ( cond ) ) { \
fprintf ( stderr , " %s:%d: %s: %s \n " , __FILE__ , __LINE__ , phase , # cond ) ; \
abort ( ) ; \
abort ( ) ; \
}
static void CheckEqual ( const char * expected , const char * v , size_t n ) {
@ -98,21 +98,15 @@ static void Free(char** ptr) {
}
}
static void CheckValue (
char * err ,
const char * expected ,
char * * actual ,
size_t actual_length ) {
static void CheckValue ( char * err , const char * expected , char * * actual ,
size_t actual_length ) {
CheckNoError ( err ) ;
CheckEqual ( expected , * actual , actual_length ) ;
Free ( actual ) ;
}
static void CheckGet (
rocksdb_t * db ,
const rocksdb_readoptions_t * options ,
const char * key ,
const char * expected ) {
static void CheckGet ( rocksdb_t * db , const rocksdb_readoptions_t * options ,
const char * key , const char * expected ) {
char * err = NULL ;
size_t val_len ;
char * val ;
@ -122,12 +116,9 @@ static void CheckGet(
Free ( & val ) ;
}
static void CheckGetCF (
rocksdb_t * db ,
const rocksdb_readoptions_t * options ,
rocksdb_column_family_handle_t * handle ,
const char * key ,
const char * expected ) {
static void CheckGetCF ( rocksdb_t * db , const rocksdb_readoptions_t * options ,
rocksdb_column_family_handle_t * handle , const char * key ,
const char * expected ) {
char * err = NULL ;
size_t val_len ;
char * val ;
@ -174,8 +165,8 @@ static void CheckMultiGetValues(size_t num_keys, char** values,
}
}
static void CheckIter ( rocksdb_iterator_t * iter ,
const char * key , const char * val ) {
static void CheckIter ( rocksdb_iterator_t * iter , const char * key ,
const char * val ) {
size_t len ;
const char * str ;
str = rocksdb_iter_key ( iter , & len ) ;
@ -185,10 +176,9 @@ static void CheckIter(rocksdb_iterator_t* iter,
}
// Callback from rocksdb_writebatch_iterate()
static void CheckPut ( void * ptr ,
const char * k , size_t klen ,
const char * v , size_t vlen ) {
int * state = ( int * ) ptr ;
static void CheckPut ( void * ptr , const char * k , size_t klen , const char * v ,
size_t vlen ) {
int * state = ( int * ) ptr ;
CheckCondition ( * state < 2 ) ;
switch ( * state ) {
case 0 :
@ -205,7 +195,7 @@ static void CheckPut(void* ptr,
// Callback from rocksdb_writebatch_iterate()
static void CheckDel ( void * ptr , const char * k , size_t klen ) {
int * state = ( int * ) ptr ;
int * state = ( int * ) ptr ;
CheckCondition ( * state = = 2 ) ;
CheckEqual ( " bar " , k , klen ) ;
( * state ) + + ;
@ -213,14 +203,16 @@ static void CheckDel(void* ptr, const char* k, size_t klen) {
static void CmpDestroy ( void * arg ) { ( void ) arg ; }
static int CmpCompare ( void * arg , const char * a , size_t alen ,
const char * b , size_t blen ) {
static int CmpCompare ( void * arg , const char * a , size_t alen , const char * b ,
size_t blen ) {
( void ) arg ;
size_t n = ( alen < blen ) ? alen : blen ;
int r = memcmp ( a , b , n ) ;
if ( r = = 0 ) {
if ( alen < blen ) r = - 1 ;
else if ( alen > blen ) r = + 1 ;
if ( alen < blen )
r = - 1 ;
else if ( alen > blen )
r = + 1 ;
}
return r ;
}
@ -405,11 +397,9 @@ static const char* MergeOperatorName(void* arg) {
return " TestMergeOperator " ;
}
static char * MergeOperatorFullMerge (
void * arg ,
const char * key , size_t key_length ,
const char * existing_value , size_t existing_value_length ,
const char * const * operands_list , const size_t * operands_list_length ,
int num_operands ,
void * arg , const char * key , size_t key_length , const char * existing_value ,
size_t existing_value_length , const char * const * operands_list ,
const size_t * operands_list_length , int num_operands ,
unsigned char * success , size_t * new_value_length ) {
( void ) arg ;
( void ) key ;
@ -425,12 +415,12 @@ static char* MergeOperatorFullMerge(
memcpy ( result , " fake " , 4 ) ;
return result ;
}
static char * MergeOperatorPartialMerge (
void * arg ,
const char * key , size_t key_length ,
const char * const * operands_list , const size_t * operands_list_length ,
int num_operands ,
unsigned char * success , size_t * new_value_length ) {
static char * MergeOperatorPartialMerge ( void * arg , const char * key ,
size_t key_length ,
const char * const * operands_list ,
const size_t * operands_list_length ,
int num_operands , unsigned char * succes s ,
size_t * new_value_length ) {
( void ) arg ;
( void ) key ;
( void ) key_length ;
@ -444,18 +434,16 @@ static char* MergeOperatorPartialMerge(
return result ;
}
static void CheckTxnGet (
rocksdb_transaction_t * txn ,
const rocksdb_readoptions_t * options ,
const char * key ,
const char * expected ) {
char * err = NULL ;
size_t val_len ;
char * val ;
val = rocksdb_transaction_get ( txn , options , key , strlen ( key ) , & val_len , & err ) ;
CheckNoError ( err ) ;
CheckEqual ( expected , val , val_len ) ;
Free ( & val ) ;
static void CheckTxnGet ( rocksdb_transaction_t * txn ,
const rocksdb_readoptions_t * options , const char * key ,
const char * expected ) {
char * err = NULL ;
size_t val_len ;
char * val ;
val = rocksdb_transaction_get ( txn , options , key , strlen ( key ) , & val_len , & err ) ;
CheckNoError ( err ) ;
CheckEqual ( expected , val , val_len ) ;
Free ( & val ) ;
}
static void CheckTxnGetCF ( rocksdb_transaction_t * txn ,
@ -502,11 +490,9 @@ static void CheckTxnPinGetCF(rocksdb_transaction_t* txn,
rocksdb_pinnableslice_destroy ( p ) ;
}
static void CheckTxnDBGet (
rocksdb_transactiondb_t * txn_db ,
const rocksdb_readoptions_t * options ,
const char * key ,
const char * expected ) {
static void CheckTxnDBGet ( rocksdb_transactiondb_t * txn_db ,
const rocksdb_readoptions_t * options , const char * key ,
const char * expected ) {
char * err = NULL ;
size_t val_len ;
char * val ;
@ -632,7 +618,7 @@ int main(int argc, char** argv) {
rocksdb_t * db ;
rocksdb_comparator_t * cmp ;
rocksdb_cache_t * cache ;
rocksdb_dbpath_t * dbpath ;
rocksdb_dbpath_t * dbpath ;
rocksdb_env_t * env ;
rocksdb_options_t * options ;
rocksdb_compactoptions_t * coptions ;
@ -649,30 +635,20 @@ int main(int argc, char** argv) {
char * err = NULL ;
int run = - 1 ;
snprintf ( dbname , sizeof ( dbname ) ,
" %s/rocksdb_c_test-%d " ,
GetTempDir ( ) ,
( ( int ) geteuid ( ) ) ) ;
snprintf ( dbname , sizeof ( dbname ) , " %s/rocksdb_c_test-%d " , GetTempDir ( ) ,
( ( int ) geteuid ( ) ) ) ;
snprintf ( dbbackupname , sizeof ( dbbackupname ) ,
" %s/rocksdb_c_test-%d-backup " ,
GetTempDir ( ) ,
( ( int ) geteuid ( ) ) ) ;
snprintf ( dbbackupname , sizeof ( dbbackupname ) , " %s/rocksdb_c_test-%d-backup " ,
GetTempDir ( ) , ( ( int ) geteuid ( ) ) ) ;
snprintf ( dbcheckpointname , sizeof ( dbcheckpointname ) ,
" %s/rocksdb_c_test-%d-checkpoint " ,
GetTempDir ( ) ,
( ( int ) geteuid ( ) ) ) ;
" %s/rocksdb_c_test-%d-checkpoint " , GetTempDir ( ) , ( ( int ) geteuid ( ) ) ) ;
snprintf ( sstfilename , sizeof ( sstfilename ) ,
" %s/rocksdb_c_test-%d-sst " ,
GetTempDir ( ) ,
( ( int ) geteuid ( ) ) ) ;
snprintf ( sstfilename , sizeof ( sstfilename ) , " %s/rocksdb_c_test-%d-sst " ,
GetTempDir ( ) , ( ( int ) geteuid ( ) ) ) ;
snprintf ( dbpathname , sizeof ( dbpathname ) ,
" %s/rocksdb_c_test-%d-dbpath " ,
GetTempDir ( ) ,
( ( int ) geteuid ( ) ) ) ;
snprintf ( dbpathname , sizeof ( dbpathname ) , " %s/rocksdb_c_test-%d-dbpath " ,
GetTempDir ( ) , ( ( int ) geteuid ( ) ) ) ;
StartPhase ( " create_objects " ) ;
cmp = rocksdb_comparator_create ( NULL , CmpDestroy , CmpCompare , CmpName ) ;
@ -746,7 +722,8 @@ int main(int argc, char** argv) {
rocksdb_destroy_db ( options , dbbackupname , & err ) ;
CheckNoError ( err ) ;
rocksdb_backup_engine_t * be = rocksdb_backup_engine_open ( options , dbbackupname , & err ) ;
rocksdb_backup_engine_t * be =
rocksdb_backup_engine_open ( options , dbbackupname , & err ) ;
CheckNoError ( err ) ;
rocksdb_backup_engine_create_new_backup ( be , db , & err ) ;
@ -759,7 +736,8 @@ int main(int argc, char** argv) {
rocksdb_backup_engine_create_new_backup ( be , db , & err ) ;
CheckNoError ( err ) ;
const rocksdb_backup_engine_info_t * bei = rocksdb_backup_engine_get_backup_info ( be ) ;
const rocksdb_backup_engine_info_t * bei =
rocksdb_backup_engine_get_backup_info ( be ) ;
CheckCondition ( rocksdb_backup_engine_info_count ( bei ) > 1 ) ;
rocksdb_backup_engine_info_destroy ( bei ) ;
@ -778,9 +756,11 @@ int main(int argc, char** argv) {
rocksdb_destroy_db ( options , dbname , & err ) ;
CheckNoError ( err ) ;
rocksdb_restore_options_t * restore_options = rocksdb_restore_options_create ( ) ;
rocksdb_restore_options_t * restore_options =
rocksdb_restore_options_create ( ) ;
rocksdb_restore_options_set_keep_log_files ( restore_options , 0 ) ;
rocksdb_backup_engine_restore_db_from_latest_backup ( be , dbname , dbname , restore_options , & err ) ;
rocksdb_backup_engine_restore_db_from_latest_backup ( be , dbname , dbname ,
restore_options , & err ) ;
CheckNoError ( err ) ;
rocksdb_restore_options_destroy ( restore_options ) ;
@ -799,7 +779,8 @@ int main(int argc, char** argv) {
rocksdb_destroy_db ( options , dbcheckpointname , & err ) ;
CheckNoError ( err ) ;
rocksdb_checkpoint_t * checkpoint = rocksdb_checkpoint_object_create ( db , & err ) ;
rocksdb_checkpoint_t * checkpoint =
rocksdb_checkpoint_object_create ( db , & err ) ;
CheckNoError ( err ) ;
rocksdb_checkpoint_create ( checkpoint , dbcheckpointname , 0 , & err ) ;
@ -976,10 +957,10 @@ int main(int argc, char** argv) {
StartPhase ( " writebatch_vectors " ) ;
{
rocksdb_writebatch_t * wb = rocksdb_writebatch_create ( ) ;
const char * k_list [ 2 ] = { " z " , " ap " } ;
const size_t k_sizes [ 2 ] = { 1 , 2 } ;
const char * v_list [ 3 ] = { " x " , " y " , " z " } ;
const size_t v_sizes [ 3 ] = { 1 , 1 , 1 } ;
const char * k_list [ 2 ] = { " z " , " ap " } ;
const size_t k_sizes [ 2 ] = { 1 , 2 } ;
const char * v_list [ 3 ] = { " x " , " y " , " z " } ;
const size_t v_sizes [ 3 ] = { 1 , 1 , 1 } ;
rocksdb_writebatch_putv ( wb , 2 , k_list , k_sizes , 3 , v_list , v_sizes ) ;
rocksdb_write ( db , woptions , wb , & err ) ;
CheckNoError ( err ) ;
@ -1041,13 +1022,17 @@ int main(int argc, char** argv) {
CheckCondition ( count = = 3 ) ;
size_t size ;
char * value ;
value = rocksdb_writebatch_wi_get_from_batch ( wbi , options , " box " , 3 , & size , & err ) ;
value = rocksdb_writebatch_wi_get_from_batch ( wbi , options , " box " , 3 , & size ,
& err ) ;
CheckValue ( err , " c " , & value , size ) ;
value = rocksdb_writebatch_wi_get_from_batch ( wbi , options , " bar " , 3 , & size , & err ) ;
value = rocksdb_writebatch_wi_get_from_batch ( wbi , options , " bar " , 3 , & size ,
& err ) ;
CheckValue ( err , NULL , & value , size ) ;
value = rocksdb_writebatch_wi_get_from_batch_and_db ( wbi , db , roptions , " foo " , 3 , & size , & err ) ;
value = rocksdb_writebatch_wi_get_from_batch_and_db ( wbi , db , roptions ,
" foo " , 3 , & size , & err ) ;
CheckValue ( err , " hello " , & value , size ) ;
value = rocksdb_writebatch_wi_get_from_batch_and_db ( wbi , db , roptions , " box " , 3 , & size , & err ) ;
value = rocksdb_writebatch_wi_get_from_batch_and_db ( wbi , db , roptions ,
" box " , 3 , & size , & err ) ;
CheckValue ( err , " c " , & value , size ) ;
rocksdb_write_writebatch_wi ( db , woptions , wbi , & err ) ;
CheckNoError ( err ) ;
@ -1064,10 +1049,10 @@ int main(int argc, char** argv) {
StartPhase ( " writebatch_wi_vectors " ) ;
{
rocksdb_writebatch_wi_t * wb = rocksdb_writebatch_wi_create ( 0 , 1 ) ;
const char * k_list [ 2 ] = { " z " , " ap " } ;
const size_t k_sizes [ 2 ] = { 1 , 2 } ;
const char * v_list [ 3 ] = { " x " , " y " , " z " } ;
const size_t v_sizes [ 3 ] = { 1 , 1 , 1 } ;
const char * k_list [ 2 ] = { " z " , " ap " } ;
const size_t k_sizes [ 2 ] = { 1 , 2 } ;
const char * v_list [ 3 ] = { " x " , " y " , " z " } ;
const size_t v_sizes [ 3 ] = { 1 , 1 , 1 } ;
rocksdb_writebatch_wi_putv ( wb , 2 , k_list , k_sizes , 3 , v_list , v_sizes ) ;
rocksdb_write_writebatch_wi ( db , woptions , wb , & err ) ;
CheckNoError ( err ) ;
@ -1156,13 +1141,14 @@ int main(int argc, char** argv) {
StartPhase ( " multiget " ) ;
{
const char * keys [ 3 ] = { " box " , " foo " , " notfound " } ;
const size_t keys_sizes [ 3 ] = { 3 , 3 , 8 } ;
const char * keys [ 3 ] = { " box " , " foo " , " notfound " } ;
const size_t keys_sizes [ 3 ] = { 3 , 3 , 8 } ;
char * vals [ 3 ] ;
size_t vals_sizes [ 3 ] ;
char * errs [ 3 ] ;
const char * expected [ 3 ] = { " c " , " hello " , NULL } ;
rocksdb_multi_get ( db , roptions , 3 , keys , keys_sizes , vals , vals_sizes , errs ) ;
rocksdb_multi_get ( db , roptions , 3 , keys , keys_sizes , vals , vals_sizes ,
errs ) ;
CheckMultiGetValues ( 3 , vals , vals_sizes , errs , expected ) ;
}
@ -1180,10 +1166,10 @@ int main(int argc, char** argv) {
char keybuf [ 100 ] ;
char valbuf [ 100 ] ;
uint64_t sizes [ 2 ] ;
const char * start [ 2 ] = { " a " , " k00000000000000010000 " } ;
size_t start_len [ 2 ] = { 1 , 21 } ;
const char * limit [ 2 ] = { " k00000000000000010000 " , " z " } ;
size_t limit_len [ 2 ] = { 21 , 1 } ;
const char * start [ 2 ] = { " a " , " k00000000000000010000 " } ;
size_t start_len [ 2 ] = { 1 , 21 } ;
const char * limit [ 2 ] = { " k00000000000000010000 " , " z " } ;
size_t limit_len [ 2 ] = { 21 , 1 } ;
rocksdb_writeoptions_set_sync ( woptions , 0 ) ;
for ( i = 0 ; i < n ; i + + ) {
snprintf ( keybuf , sizeof ( keybuf ) , " k%020d " , i ) ;
@ -1393,8 +1379,8 @@ int main(int argc, char** argv) {
factory ) ;
db = CheckCompaction ( db , options_with_filter_factory , roptions , woptions ) ;
rocksdb_options_set_compaction_filter_factory (
options_with_filter_factory , NULL ) ;
rocksdb_options_set_compaction_filter_factory ( options_with_filter_factory ,
NULL ) ;
rocksdb_options_destroy ( options_with_filter_factory ) ;
}
@ -1449,7 +1435,8 @@ int main(int argc, char** argv) {
rocksdb_close ( db ) ;
size_t cflen ;
char * * column_fams = rocksdb_list_column_families ( db_options , dbname , & cflen , & err ) ;
char * * column_fams =
rocksdb_list_column_families ( db_options , dbname , & cflen , & err ) ;
CheckNoError ( err ) ;
CheckEqual ( " default " , column_fams [ 0 ] , 7 ) ;
CheckEqual ( " cf1 " , column_fams [ 1 ] , 3 ) ;
@ -1465,7 +1452,8 @@ int main(int argc, char** argv) {
LoadAndCheckLatestOptions ( dbname , env , false , cache , NULL , 2 , cf_names ,
NULL ) ;
db = rocksdb_open_column_families ( db_options , dbname , 2 , cf_names , cf_opts , handles , & err ) ;
db = rocksdb_open_column_families ( db_options , dbname , 2 , cf_names , cf_opts ,
handles , & err ) ;
CheckNoError ( err ) ;
rocksdb_put_cf ( db , woptions , handles [ 1 ] , " foo " , 3 , " hello " , 5 , & err ) ;
@ -1483,11 +1471,10 @@ int main(int argc, char** argv) {
& err ) ;
CheckNoError ( err ) ;
rocksdb_flushoptions_t * flush_options = rocksdb_flushoptions_create ( ) ;
rocksdb_flushoptions_t * flush_options = rocksdb_flushoptions_create ( ) ;
rocksdb_flushoptions_set_wait ( flush_options , 1 ) ;
rocksdb_flush_cf ( db , flush_options , handles [ 1 ] , & err ) ;
CheckNoError ( err )
rocksdb_flushoptions_destroy ( flush_options ) ;
CheckNoError ( err ) rocksdb_flushoptions_destroy ( flush_options ) ;
CheckGetCF ( db , roptions , handles [ 1 ] , " foo " , " hello " ) ;
CheckPinGetCF ( db , roptions , handles [ 1 ] , " foo " , " hello " ) ;
@ -1524,27 +1511,29 @@ int main(int argc, char** argv) {
rocksdb_flush_wal ( db , 1 , & err ) ;
CheckNoError ( err ) ;
const char * keys [ 3 ] = { " box " , " box " , " barfooxx " } ;
const rocksdb_column_family_handle_t * get_handles [ 3 ] = { handles [ 0 ] , handles [ 1 ] , handles [ 1 ] } ;
const size_t keys_sizes [ 3 ] = { 3 , 3 , 8 } ;
const char * keys [ 3 ] = { " box " , " box " , " barfooxx " } ;
const rocksdb_column_family_handle_t * get_handles [ 3 ] = {
handles [ 0 ] , handles [ 1 ] , handles [ 1 ] } ;
const size_t keys_sizes [ 3 ] = { 3 , 3 , 8 } ;
char * vals [ 3 ] ;
size_t vals_sizes [ 3 ] ;
char * errs [ 3 ] ;
rocksdb_multi_get_cf ( db , roptions , get_handles , 3 , keys , keys_sizes , vals , vals_sizes , errs ) ;
rocksdb_multi_get_cf ( db , roptions , get_handles , 3 , keys , keys_sizes , vals ,
vals_sizes , errs ) ;
int i ;
for ( i = 0 ; i < 3 ; i + + ) {
CheckEqual ( NULL , errs [ i ] , 0 ) ;
switch ( i ) {
case 0 :
CheckEqual ( NULL , vals [ i ] , vals_sizes [ i ] ) ; // wrong cf
break ;
case 1 :
CheckEqual ( " c " , vals [ i ] , vals_sizes [ i ] ) ; // bingo
break ;
case 2 :
CheckEqual ( NULL , vals [ i ] , vals_sizes [ i ] ) ; // normal not found
break ;
case 0 :
CheckEqual ( NULL , vals [ i ] , vals_sizes [ i ] ) ; // wrong cf
break ;
case 1 :
CheckEqual ( " c " , vals [ i ] , vals_sizes [ i ] ) ; // bingo
break ;
case 2 :
CheckEqual ( NULL , vals [ i ] , vals_sizes [ i ] ) ; // normal not found
break ;
}
Free ( & vals [ i ] ) ;
}
@ -1592,7 +1581,8 @@ int main(int argc, char** argv) {
}
}
rocksdb_iterator_t * iter = rocksdb_create_iterator_cf ( db , roptions , handles [ 1 ] ) ;
rocksdb_iterator_t * iter =
rocksdb_create_iterator_cf ( db , roptions , handles [ 1 ] ) ;
CheckCondition ( ! rocksdb_iter_valid ( iter ) ) ;
rocksdb_iter_seek_to_first ( iter ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
@ -1605,9 +1595,11 @@ int main(int argc, char** argv) {
CheckNoError ( err ) ;
rocksdb_iter_destroy ( iter ) ;
rocksdb_column_family_handle_t * iters_cf_handles [ 2 ] = { handles [ 0 ] , handles [ 1 ] } ;
rocksdb_column_family_handle_t * iters_cf_handles [ 2 ] = { handles [ 0 ] ,
handles [ 1 ] } ;
rocksdb_iterator_t * iters_handles [ 2 ] ;
rocksdb_create_iterators ( db , roptions , iters_cf_handles , iters_handles , 2 , & err ) ;
rocksdb_create_iterators ( db , roptions , iters_cf_handles , iters_handles , 2 ,
& err ) ;
CheckNoError ( err ) ;
iter = iters_handles [ 0 ] ;
@ -1652,7 +1644,8 @@ int main(int argc, char** argv) {
{
// Create new database
rocksdb_options_set_allow_mmap_reads ( options , 1 ) ;
rocksdb_options_set_prefix_extractor ( options , rocksdb_slicetransform_create_fixed_prefix ( 3 ) ) ;
rocksdb_options_set_prefix_extractor (
options , rocksdb_slicetransform_create_fixed_prefix ( 3 ) ) ;
rocksdb_options_set_hash_skip_list_rep ( options , 5000 , 4 , 4 ) ;
rocksdb_options_set_plain_table_factory ( options , 4 , 10 , 0.75 , 16 ) ;
rocksdb_options_set_allow_concurrent_memtable_write ( options , 0 ) ;
@ -1747,8 +1740,9 @@ int main(int argc, char** argv) {
// amount of memory used within memtables should grow
CheckCondition ( rocksdb_approximate_memory_usage_get_mem_table_total ( mu2 ) > =
rocksdb_approximate_memory_usage_get_mem_table_total ( mu1 ) ) ;
CheckCondition ( rocksdb_approximate_memory_usage_get_mem_table_unflushed ( mu2 ) > =
rocksdb_approximate_memory_usage_get_mem_table_unflushed ( mu1 ) ) ;
CheckCondition (
rocksdb_approximate_memory_usage_get_mem_table_unflushed ( mu2 ) > =
rocksdb_approximate_memory_usage_get_mem_table_unflushed ( mu1 ) ) ;
rocksdb_memory_consumers_destroy ( consumers ) ;
rocksdb_approximate_memory_usage_destroy ( mu1 ) ;
@ -2839,53 +2833,57 @@ int main(int argc, char** argv) {
db = rocksdb_open ( options , dbname , & err ) ;
CheckNoError ( err ) ;
rocksdb_put ( db , woptions , " a " , 1 , " 0 " , 1 , & err ) ; CheckNoError ( err ) ;
rocksdb_put ( db , woptions , " foo " , 3 , " bar " , 3 , & err ) ; CheckNoError ( err ) ;
rocksdb_put ( db , woptions , " foo1 " , 4 , " bar1 " , 4 , & err ) ; CheckNoError ( err ) ;
rocksdb_put ( db , woptions , " g1 " , 2 , " 0 " , 1 , & err ) ; CheckNoError ( err ) ;
rocksdb_put ( db , woptions , " a " , 1 , " 0 " , 1 , & err ) ;
CheckNoError ( err ) ;
rocksdb_put ( db , woptions , " foo " , 3 , " bar " , 3 , & err ) ;
CheckNoError ( err ) ;
rocksdb_put ( db , woptions , " foo1 " , 4 , " bar1 " , 4 , & err ) ;
CheckNoError ( err ) ;
rocksdb_put ( db , woptions , " g1 " , 2 , " 0 " , 1 , & err ) ;
CheckNoError ( err ) ;
// testing basic case with no iterate_upper_bound and no prefix_extractor
{
rocksdb_readoptions_set_iterate_upper_bound ( roptions , NULL , 0 ) ;
rocksdb_iterator_t * iter = rocksdb_create_iterator ( db , roptions ) ;
rocksdb_readoptions_set_iterate_upper_bound ( roptions , NULL , 0 ) ;
rocksdb_iterator_t * iter = rocksdb_create_iterator ( db , roptions ) ;
rocksdb_iter_seek ( iter , " foo " , 3 ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " foo " , " bar " ) ;
rocksdb_iter_seek ( iter , " foo " , 3 ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " foo " , " bar " ) ;
rocksdb_iter_next ( iter ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " foo1 " , " bar1 " ) ;
rocksdb_iter_next ( iter ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " foo1 " , " bar1 " ) ;
rocksdb_iter_next ( iter ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " g1 " , " 0 " ) ;
rocksdb_iter_next ( iter ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " g1 " , " 0 " ) ;
rocksdb_iter_destroy ( iter ) ;
rocksdb_iter_destroy ( iter ) ;
}
// testing iterate_upper_bound and forward iterator
// to make sure it stops at bound
{
// iterate_upper_bound points beyond the last expected entry
rocksdb_readoptions_set_iterate_upper_bound ( roptions , " foo2 " , 4 ) ;
// iterate_upper_bound points beyond the last expected entry
rocksdb_readoptions_set_iterate_upper_bound ( roptions , " foo2 " , 4 ) ;
rocksdb_iterator_t * iter = rocksdb_create_iterator ( db , roptions ) ;
rocksdb_iterator_t * iter = rocksdb_create_iterator ( db , roptions ) ;
rocksdb_iter_seek ( iter , " foo " , 3 ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " foo " , " bar " ) ;
rocksdb_iter_seek ( iter , " foo " , 3 ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " foo " , " bar " ) ;
rocksdb_iter_next ( iter ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " foo1 " , " bar1 " ) ;
rocksdb_iter_next ( iter ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;
CheckIter ( iter , " foo1 " , " bar1 " ) ;
rocksdb_iter_next ( iter ) ;
// should stop here...
CheckCondition ( ! rocksdb_iter_valid ( iter ) ) ;
rocksdb_iter_next ( iter ) ;
// should stop here...
CheckCondition ( ! rocksdb_iter_valid ( iter ) ) ;
rocksdb_iter_destroy ( iter ) ;
rocksdb_readoptions_set_iterate_upper_bound ( roptions , NULL , 0 ) ;
rocksdb_iter_destroy ( iter ) ;
rocksdb_readoptions_set_iterate_upper_bound ( roptions , NULL , 0 ) ;
}
}
@ -3009,7 +3007,7 @@ int main(int argc, char** argv) {
snapshot = rocksdb_transactiondb_create_snapshot ( txn_db ) ;
rocksdb_readoptions_set_snapshot ( roptions , snapshot ) ;
rocksdb_transactiondb_put ( txn_db , woptions , " foo " , 3 , " hey " , 3 , & err ) ;
rocksdb_transactiondb_put ( txn_db , woptions , " foo " , 3 , " hey " , 3 , & err ) ;
CheckNoError ( err ) ;
CheckTxnDBGet ( txn_db , roptions , " foo " , " hello " ) ;
@ -3021,7 +3019,8 @@ int main(int argc, char** argv) {
// iterate
rocksdb_transaction_put ( txn , " bar " , 3 , " hi " , 2 , & err ) ;
rocksdb_iterator_t * iter = rocksdb_transaction_create_iterator ( txn , roptions ) ;
rocksdb_iterator_t * iter =
rocksdb_transaction_create_iterator ( txn , roptions ) ;
CheckCondition ( ! rocksdb_iter_valid ( iter ) ) ;
rocksdb_iter_seek_to_first ( iter ) ;
CheckCondition ( rocksdb_iter_valid ( iter ) ) ;