@ -98,21 +98,15 @@ static void Free(char** ptr) {
}
}
static void CheckValue (
char * err ,
const char * expected ,
char * * actual ,
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,11 +116,8 @@ 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 ,
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 ;
@ -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,9 +176,8 @@ 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 ) {
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 ) {
@ -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,10 +434,8 @@ static char* MergeOperatorPartialMerge(
return result ;
}
static void CheckTxnGet (
rocksdb_transaction_t * txn ,
const rocksdb_readoptions_t * options ,
const char * key ,
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 ;
@ -502,10 +490,8 @@ 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 ,
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 ;
@ -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 ( ) ,
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 ) ;
@ -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 ) ;
@ -1162,7 +1147,8 @@ int main(int argc, char** argv) {
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 ) ;
}
@ -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 ) ;
@ -1486,8 +1474,7 @@ int main(int argc, char** argv) {
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 " ) ;
@ -1525,12 +1512,14 @@ int main(int argc, char** argv) {
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 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 + + ) {
@ -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,7 +1740,8 @@ 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 ) > =
CheckCondition (
rocksdb_approximate_memory_usage_get_mem_table_unflushed ( mu2 ) > =
rocksdb_approximate_memory_usage_get_mem_table_unflushed ( mu1 ) ) ;
rocksdb_memory_consumers_destroy ( consumers ) ;
@ -2839,10 +2833,14 @@ 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
{
@ -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 ) ) ;