Ejemplo n.º 1
0
int lset_create_test (char * keystr, char * ldt_bin ){
    static char * meth = "lset_create_test()";
    if( LSET_DEBUG ) {
        INFO("      [ENTER]:<%s:%s>:From %s", MOD, LDT, meth );
    }

    cl_cluster * c     = lset_g_config->asc;
    cl_object  o_key;
    char       * ns    = lset_g_config->ns;
    char       * set   = lset_g_config->set;
    char       * bname = ldt_bin;

    char * create_package = "StandardList";
    as_map *create_spec = as_hashmap_new(2);
    as_map_set(create_spec, (as_val *) as_string_new("Package", false),
    (as_val *) as_string_new( create_package, false));

    citrusleaf_object_init_str( &o_key, keystr );

    cl_rv rv = 0;
    rv = aerospike_lset_create( c, ns, set, &o_key, bname, create_spec, lset_g_config->timeout_ms);

    citrusleaf_object_free( &o_key );
    as_val_destroy( create_spec );
    return rv;

}
Ejemplo n.º 2
0
// Sets the key value in the hashmap
void * set_cb(char * key, char * value, void * context) {
	
	// Make as_val for key and value
	as_val * k = (as_val *) as_string_new((char *) key, false);
	as_val * v = (as_val *) as_string_new(strdup(value), true);

	// Set k, v in the map
	as_map_set((as_map*)context, k, v);

	// Return the updated map again
	return context;
}
Ejemplo n.º 3
0
int lset_generate_value( as_val ** return_valpp, int seed, int val_type ){
    static char * meth = "generate_value()";

    int rc = 0;
    *return_valpp = NULL;  // Start with nothing.
    char * mallocd_buf = NULL;
    char sourceChars[26] = "abcdefghijklmnopqrstuvwxyz";
    switch( val_type ){
        case LIST_FORMAT:
            *return_valpp = lset_gen_list_val( seed );
            break;
        case NUMBER_FORMAT:
            // We have to malloc an int here because someone else will have
            // to reclaim (destroy) it.
            srand( seed );
            as_integer * intp = as_integer_new( rand() % lset_g_config->key_max);
            *return_valpp = (as_val *) intp;
            break;
        case STRING_FORMAT:
            // Malloc a string buffer, write in it, and then create a 
            // as_string object for it.
            // NOTE: RIght now, this is just a simple, variable size string
            // based on the value_len parameter in the config structure.
            mallocd_buf = (char *) malloc( lset_g_config->value_len+1);
            srand( seed );

            //generate random string length from the given value_len
            int new_val = rand() % lset_g_config->value_len;
            int i;
            for (i=0; i<new_val; ++i) {
                mallocd_buf[i] = sourceChars[rand()%26];
            }
            mallocd_buf[new_val] = '\0';

            as_string * str_val = as_string_new( mallocd_buf, true );
            *return_valpp = (as_val *) str_val;
            break;
//        case COMPLEX_1_FORMAT:
//        case COMPLEX_2_FORMAT:
//        case COMPLEX_3_FORMAT:
//            printf("[ERROR]<%s:%s>WE ARE NOT YET HANDLING COMPLEX FORMATS\n",
//                    MOD, meth );
//            break;
        case NO_FORMAT:
        default:
            printf("[ERROR]<%s:%s>UNKNOWN FORMAT: %d \n",
                    MOD, meth, val_type );
    } // end switch object type

    return rc;
} // end generate_value()
Ejemplo n.º 4
0
// Local utility.
static as_val *
as_val_from_flat_key(uint8_t * flat_key, uint32_t size)
{
	uint8_t type = *flat_key;
	uint8_t * key = flat_key + 1;

	switch ( type ) {
		case AS_PARTICLE_TYPE_INTEGER:
			// TODO - verify size is (1 + 8) ???
			// Flat integer keys are in big-endian order.
			return (as_val *) as_integer_new(cf_swap_from_be64(*(int64_t *)key));
		case AS_PARTICLE_TYPE_STRING:
		{
			// Key length is size - 1, then +1 for null-termination.
			char * buf = cf_malloc(size);
			if (! buf) {
				return NULL;
			}

			uint32_t len = size - 1;
			memcpy(buf, key, len);
			buf[len] = '\0';

			return (as_val *) as_string_new(buf, true);
		}
		case AS_PARTICLE_TYPE_BLOB:
		{
			uint32_t blob_size = size - 1;
			uint8_t *buf = cf_malloc(blob_size);
			if (! buf) {
				return NULL;
			}

			memcpy(buf, key, blob_size);

			return (as_val *) as_bytes_new_wrap(buf, blob_size, true);
		}
		default:
			return NULL;
	}
}
Ejemplo n.º 5
0
/**
 *  LSET Insert WITH_TRANSFORM TEST
 *  For a single record, perform a series of SET Insert of BYTE-PACKED data.
 *  Create a new record, then repeatedly call stack insert.
 */
int lset_insert_with_transform_test(char * keystr, char * ldt_bin, int iterations) {
    static char * meth = "lset_insert_with_transform_test()";
    if( LSET_DEBUG ) {
        INFO("      [ENTER]:<%s:%s>:From %s", MOD, LDT, meth );
    }

    int rc = 0;
    int i;

    INFO("[ENTER]:<%s:%s>: It(%d) Key(%s) LSOBin(%s)",
            MOD, meth, iterations, keystr, ldt_bin );

    // Abbreviate for simplicity.
    cl_cluster * c  = lset_g_config->asc;
    char       * ns = lset_g_config->ns;
    char       * set  = lset_g_config->set;
    char       * bname  = ldt_bin;
    cl_object o_key;

    // Set up the Creation Spec parameter -- mostly setting the Package
    // (which is the name for a canned set of settings).
    char * create_package = "ProdListValBinStore";
    as_map *create_spec = as_hashmap_new(2);
    as_map_set(create_spec,
            (as_val *) as_string_new("Package", false),
            (as_val *) as_string_new( create_package, false));

    INFO("[DEBUG]:<%s:%s>: Run insert_with_transform() iterations(%d)",
          MOD, meth, iterations );
    citrusleaf_object_init_str( &o_key, keystr );
    for ( i = 0; i < iterations; i++ ) {
        int val         = i * 10;
        as_list * listp = as_arraylist_new( 5, 5 );
        int64_t urlid   = val + 1;
        as_list_add_integer( listp, urlid );
        int64_t created = val + 2;
        as_list_add_integer( listp, created );
        int64_t meth_a  = val + 3;
        as_list_add_integer( listp, meth_a );
        int64_t meth_b  = val + 4;
        as_list_add_integer( listp, meth_b );
        int64_t status  = val + 5;
        as_list_add_integer( listp, status );

        rc = aerospike_lset_create_and_insert( c, ns, set, &o_key, bname,
                (as_val *)listp, create_spec, lset_g_config->timeout_ms);
        if ( rc != CITRUSLEAF_OK ) {
            INFO("[ERROR]:<%s:%s>:LSO PUSH WITH TRANSFROM Error: i(%d) rc(%d)",
                  MOD, meth, i, rc );
            as_val_destroy ( listp );
            goto cleanup;
        }
        // Count the write operation for stats gathering
        lset_g_config->write_ops_counter += 1;
        lset_g_config->write_vals_counter += 1;
        as_val_destroy( listp ); // must destroy every iteration.
        listp = NULL;
    } // end for

cleanup:
    citrusleaf_object_free( &o_key );
    as_val_destroy( create_spec );

    return rc;
} // end lset_insert_with_transform_test()
Ejemplo n.º 6
0
/**
 *  LSET INSERT TEST
 *  For a single record, perform a series of SET insert.
 *  Create a new record, then repeatedly call lset insert.
 *  This should work for data that is a NUMBER, a STRING or a LIST.
 *  Parms:
 *  + keystr: String Key to find the record
 *  + ldt_bin: Bin Name of the LDT
 *  + iterations: Number of iterations to run this test
 *  + seed:  Seed value for the random number pattern
 *  + data_format: Type of value (number, string, list)
 */
int lset_insert_test(char * keystr, char * ldt_bin, int iterations, int seed,
        int data_format ) {
    static char * meth = "lset_insert_test()";
    if( LSET_DEBUG ) {
        INFO("      [ENTER]:<%s:%s>:From %s", MOD, LDT, meth );
    }

    int rc = CITRUSLEAF_OK;
    int i;
    as_val *valp;

    time_t cur_t;
    cur_t = time(NULL);

    //    INFO("[ENTER]:<%s:%s>: It(%d) Key(%s) LSOBin(%s) Seed(%d)",
    //            MOD, meth, iterations, keystr, ldt_bin, seed);

    // We have two choices:  We can create the LSO bin here, and then
    // do a bunch of inserts into it -- or we can just do the combined
    // "create_and_insert" insert, which upon reflection, is really the
    // most likely mode we'll be in. We'll choose the later.

    // Set up the Creation Spec parameter -- mostly setting the Package
    // (which is the name for a canned set of settings).
    char * create_package = "StandardList";
    as_map *create_spec = as_hashmap_new(2);
    as_map_set(create_spec, (as_val *) as_string_new("Package", false),
    (as_val *) as_string_new( create_package, false));

    cl_cluster * c     = lset_g_config->asc;
    cl_object  o_key;
    char       * ns    = lset_g_config->ns;
    char       * set   = lset_g_config->set;
    char       * bname = ldt_bin;
    int          iseed;

    //INFO("[DEBUG]:<%s:%s>: Run insert() iterations(%d)", MOD, meth, iterations );
    citrusleaf_object_init_str( &o_key, keystr );
    for ( i = 0; i < iterations; i++ ) {
        iseed = i * 10;
        lset_generate_value( &valp, iseed, data_format );

        rc = aerospike_lset_create_and_insert(
                c, ns, set, &o_key, bname, valp, create_spec,
                lset_g_config->timeout_ms);

        if ( rc != CITRUSLEAF_OK ) {
        //INFO("[ERROR]:<%s:%s>:H Error: i(%d) rc(%d)", MOD, meth,i,rc );
            as_val_destroy ( valp );
            goto cleanup;
        } 
        // Count the write operation for stats gathering
        lset_g_config->write_ops_counter += 1;
        lset_g_config->write_vals_counter += 1;
        as_val_destroy( valp ); // must destroy every iteration.
        valp = NULL; // unnecessary insurance
    } // end for
cleanup:
    citrusleaf_object_free( &o_key );
    as_val_destroy( create_spec );
    return rc;
} // end lset_insert_test()
Ejemplo n.º 7
0
	as_arraylist_append_int64(&list, 1);
	as_arraylist_append_int64(&list, 2);
	as_arraylist_append_int64(&list, 3);
	
	as_hashmap map;
	as_hashmap_init(&map, 32);
	as_stringmap_set_int64((as_map *) &map, "x", 7);
	as_stringmap_set_int64((as_map *) &map, "y", 8);
	as_stringmap_set_int64((as_map *) &map, "z", 9);

	as_record r, * rec = &r;
	as_record_init(rec, 10);
	as_record_set_int64(rec, "a", 123);
	as_record_set_str(rec, "b", "abc");
	as_record_set_integer(rec, "c", as_integer_new(456));
	as_record_set_string(rec, "d", as_string_new("def",false));
	as_record_set_list(rec, "e", (as_list *) &list);
	as_record_set_map(rec, "f", (as_map *) &map);

	as_key key;
	as_key_init(&key, "test", "test", "foo");

	as_status rc = aerospike_key_put(as, &err, NULL, &key, rec);

	as_key_destroy(&key);

    info("bins: ");
    as_record_foreach(&r, key_basics_print_bins, NULL);

	as_record_destroy(rec);
Ejemplo n.º 8
0
static int map_rec_set(const as_rec * r, const char * name, const as_val * value) {
    as_map * m = (as_map *) as_rec_source(r);
    return as_map_set(m, (as_val *) as_string_new(strdup(name),true), (as_val *) value);
}
Ejemplo n.º 9
0
as_string *as_string_new_strdup(const char * s)
{
	return as_string_new(cf_strdup(s), true);
}
Ejemplo n.º 10
0
void clbin_to_asval(cl_bin * bin, as_serializer * ser, as_val ** val) 
{
	if ( val == NULL ) return;

	switch( bin->object.type ) {
		case CL_NULL :{
			*val = (as_val *) &as_nil;
			break;
		}
		case CL_INT : {
			*val = (as_val *) as_integer_new(bin->object.u.i64);
			break;
		}
		case CL_STR : {
			// steal the pointer from the object into the val
			*val = (as_val *) as_string_new(strdup(bin->object.u.str), true /*ismalloc*/);
			// TODO: re-evaluate the follow zero-copy for strings from cl_bins
			// *val = (as_val *) as_string_new(bin->object.u.str, true /*ismalloc*/);
			// bin->object.free = NULL;
			break;
		}
		case CL_LIST :
		case CL_MAP : {
			// use a temporary buffer, which doesn't need to be destroyed
			as_buffer buf = {
				.capacity = (uint32_t) bin->object.sz,
				.size = (uint32_t) bin->object.sz,
				.data = (uint8_t *) bin->object.u.blob
			};
			// print_buffer(&buf);
			as_serializer_deserialize(ser, &buf, val);
			break;
		}
		case CL_BLOB:
		case CL_JAVA_BLOB:
		case CL_CSHARP_BLOB:
		case CL_PYTHON_BLOB:
		case CL_RUBY_BLOB:
		case CL_ERLANG_BLOB:
		default : {
			*val = NULL;
			uint8_t * raw = malloc(sizeof(bin->object.sz));
			memcpy(raw, bin->object.u.blob, bin->object.sz);
			as_bytes * b = as_bytes_new_wrap(raw, (uint32_t)bin->object.sz, true /*ismalloc*/);
			b->type = (as_bytes_type)bin->object.type;
			*val = (as_val *) b;
			break;
		}
	}
}


void clbin_to_asrecord(cl_bin * bin, as_record * r)
{
	switch(bin->object.type) {
		case CL_NULL: {
			as_record_set_nil(r, bin->bin_name);
			break;
		}
		case CL_INT: {
			as_record_set_int64(r, bin->bin_name, bin->object.u.i64);
			break;
		}
		case CL_STR: {
			as_record_set_strp(r, bin->bin_name, bin->object.u.str, true);
			// the following completes the handoff of the value.
			bin->object.free = NULL;
			break;
		}
		case CL_LIST:
		case CL_MAP: {

			as_val * val = NULL;

			as_buffer buffer;
			buffer.data = (uint8_t *) bin->object.u.blob;
			buffer.size = (uint32_t)bin->object.sz;

			as_serializer ser;
			as_msgpack_init(&ser);
			as_serializer_deserialize(&ser, &buffer, &val);
			as_serializer_destroy(&ser);

			as_record_set(r, bin->bin_name, (as_bin_value *) val);
			break;
		}
		default: {
			as_record_set_rawp(r, bin->bin_name, bin->object.u.blob, (uint32_t)bin->object.sz, true);
			// the following completes the handoff of the value.
			bin->object.free = NULL;
			break;
		}
	}
}


void clbins_to_asrecord(cl_bin * bins, uint32_t nbins, as_record * r) 
{
	uint32_t n = nbins < r->bins.capacity ? nbins : r->bins.capacity;
	for ( int i = 0; i < n; i++ ) {
		clbin_to_asrecord(&bins[i], r);
	}
}