BurstFS_Meta/src/ds_leveldb.c
int levedb_batch_ranges(void *dbh, char **key, int *key_len,\
		char ***out_key, int **out_key_len,\
			char ***out_val, int **out_val_len,\
				int tot_records, int *out_records_cnt) {

	int i;
	struct mdhim_leveldb_t *mdhim_db = (struct mdhim_leveldb_t *) dbh;

	int tmp_records_cnt = 0; /*the temporary number of out records*/
	int tmp_out_cap = tot_records/2; /* the temporary out capacity*/

	leveldb_iterator_t *iter;
	leveldb_readoptions_t *options;
	options = mdhim_db->read_options;

	iter = leveldb_create_iterator(mdhim_db->db, options);

	*out_val = (char **)malloc(tot_records/2 * sizeof(char *));
	*out_val_len = (int *)malloc(tot_records/2 * sizeof(int));
	*out_key = (char **)malloc(tot_records/2 * sizeof(char *));
	*out_key_len = (int *)malloc(tot_records/2 * sizeof(int));

	/*ToDo: return different error types if leveldb_process_range fails*/

	for (i = 0; i < tot_records/2; i++) {
/*		printf("%dth offset is %ld, fid is %d, %d offset is %ld, len:%ld\n", 2 * i, \
				BURSTFS_OFFSET(key[2 * i]), BURSTFS_FID(key[2 * i]), 2 * i + 1, \
					BURSTFS_OFFSET(key[ 2 * i + 1]), key_len[2 * i]); */
		leveldb_process_range(iter, key[2 * i], key[2 * i + 1], \
				key_len[2 * i], out_key, out_key_len, \
					out_val, out_val_len, &tmp_records_cnt, \
						&tmp_out_cap);

	}

	*out_records_cnt = tmp_records_cnt;

/*	printf("out_records_cnt is %d\n", *out_records_cnt);
	for (i = 0; i < *out_records_cnt; i++) {
		printf("%dth out offset is %ld, fid is %ld, addr is %ld\n", \
				i, BURSTFS_OFFSET((*out_key)[i]), BURSTFS_FID((*out_key)[i]), \
					BURSTFS_ADDR((*out_val)[i]));
		fflush(stdout);
	}
*/

	leveldb_iter_destroy(iter);
	return 0;
}
/**
 * levedb_batch_ranges
 * get a list of key-value pairs that fall in the range of a list of
 * items identified (start_key, end_key)
 *
 * @param dbh         in   pointer to the leveldb db handle
 * @param key         in   a list of start_keys and end_keys.
 * odd indexed is start_key, even indexed key is end_key
 * @param key_len 	  in   a list of key_length for start_keys and end_keys
 * @param out_key	  in   a list keys to be returned corresponding to the start_keys/end_keys
 * @param out_key_len in   a list of key lengths to be returned
 * @param out_val     in   a list of values to be returned
 * @param out_val_len in   a list of value lens to be returned
 * @param tot_records in   number of start_keys and end_keys
 * @param out_records_cnt in number of copied key-value pairs
 * @param out_records_cap in number of allocated key-value pairs
 * @return MDHIM_SUCCESS on success or MDHIM_DB_ERROR on failure
 * @return
 */
levedb_batch_ranges
get a list of key-value pairs that fall in the range of a list of
items identified (start_key, end_key)

@param dbh         in   pointer to the leveldb db handle
@param key         in   a list of start_keys and end_keys.
levedb_batch_ranges get a list of key - value pairs that fall in the range of a list of items identified ( start_key end_key ) @param dbh in pointer to the leveldb db handle @param key in a list of start_keys and end_keys .
int levedb_batch_ranges(void *dbh, char **key, int *key_len,\
		char ***out_key, int **out_key_len,\
			char ***out_val, int **out_val_len,\
				int tot_records, int *out_records_cnt) {
	int i;
	struct mdhim_leveldb_t *mdhim_db = (struct mdhim_leveldb_t *) dbh;
	int tmp_records_cnt = 0; 
	int tmp_out_cap = tot_records/2; 
	leveldb_iterator_t *iter;
	leveldb_readoptions_t *options;
	options = mdhim_db->read_options;
	iter = leveldb_create_iterator(mdhim_db->db, options);
	*out_val = (char **)malloc(tot_records/2 * sizeof(char *));
	*out_val_len = (int *)malloc(tot_records/2 * sizeof(int));
	*out_key = (char **)malloc(tot_records/2 * sizeof(char *));
	*out_key_len = (int *)malloc(tot_records/2 * sizeof(int));
	for (i = 0; i < tot_records/2; i++) {
		leveldb_process_range(iter, key[2 * i], key[2 * i + 1], \
				key_len[2 * i], out_key, out_key_len, \
					out_val, out_val_len, &tmp_records_cnt, \
						&tmp_out_cap);
	}
	*out_records_cnt = tmp_records_cnt;
	leveldb_iter_destroy(iter);
	return 0;
}
int levedb_batch_ranges ( void * dbh , char * * key , int * key_len , char * * * out_key , int * * out_key_len , char * * * out_val , int * * out_val_len , int tot_records , int * out_records_cnt ) { int i ; struct mdhim_leveldb_t * mdhim_db = ( struct mdhim_leveldb_t * ) dbh ; int tmp_records_cnt = 0 ; int tmp_out_cap = tot_records / 2 ; leveldb_iterator_t * iter ; leveldb_readoptions_t * options ; options = mdhim_db -> read_options ; iter = leveldb_create_iterator ( mdhim_db -> db , options ) ; * out_val = ( char * * ) malloc ( tot_records / 2 * sizeof ( char * ) ) ; * out_val_len = ( int * ) malloc ( tot_records / 2 * sizeof ( int ) ) ; * out_key = ( char * * ) malloc ( tot_records / 2 * sizeof ( char * ) ) ; * out_key_len = ( int * ) malloc ( tot_records / 2 * sizeof ( int ) ) ; for ( i = 0 ; i < tot_records / 2 ; i ++ ) { leveldb_process_range ( iter , key [ 2 * i ] , key [ 2 * i + 1 ] , key_len [ 2 * i ] , out_key , out_key_len , out_val , out_val_len , & tmp_records_cnt , & tmp_out_cap ) ; } * out_records_cnt = tmp_records_cnt ; leveldb_iter_destroy ( iter ) ; return 0 ; }
levedb_batch_ranges
 get a list of key-value pairs that fall in the range of a list of
 items identified (start_key, end_key)
levedb_batch_ranges get a list of key - value pairs that fall in the range of a list of items identified ( start_key end_key )
/*the temporary number of out records*/ /* the temporary out capacity*/ /*ToDo: return different error types if leveldb_process_range fails*/ /*		printf("%dth offset is %ld, fid is %d, %d offset is %ld, len:%ld\n", 2 * i, \
				BURSTFS_OFFSET(key[2 * i]), BURSTFS_FID(key[2 * i]), 2 * i + 1, \
					BURSTFS_OFFSET(key[ 2 * i + 1]), key_len[2 * i]); */ /*	printf("out_records_cnt is %d\n", *out_records_cnt);
	for (i = 0; i < *out_records_cnt; i++) {
		printf("%dth out offset is %ld, fid is %ld, addr is %ld\n", \
				i, BURSTFS_OFFSET((*out_key)[i]), BURSTFS_FID((*out_key)[i]), \
					BURSTFS_ADDR((*out_val)[i]));
		fflush(stdout);
	}
*/