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
static int mod_lua_map_newindex(lua_State * l) {
	as_map * map = mod_lua_checkmap(l, 1);
	if ( map ) {
		as_val * key = mod_lua_takeval(l, 2);
		as_val * val = mod_lua_takeval(l, 3);
		if ( !key ) {
			as_val_destroy(key);
			as_val_destroy(val);
		}
		else if ( !val ) {
			as_map_remove(map, key);
			as_val_destroy(key);
		}
		else {
			as_map_set(map, key, val);
		}
	}
	return 0;
}
Ejemplo n.º 4
0
static int mod_lua_map_cons(lua_State * l) {
	as_map * map = (as_map *) as_hashmap_new(32);
	int n = lua_gettop(l);
	if ( n == 2 && lua_type(l, 2) == LUA_TTABLE) {
		lua_pushnil(l);
		while ( lua_next(l, 2) != 0 ) {
			// this will leak or crash if these are not as_val, or k is and v isn't
			as_val * k = mod_lua_takeval(l, -2);
			as_val * v = mod_lua_takeval(l, -1);
			if ( !k || !v ) {
				as_val_destroy(k);
				as_val_destroy(v);
			}
			else {
				as_map_set(map, k, v);
			}
			lua_pop(l, 1);
		}
	}
	mod_lua_pushmap(l, map);
	return 1;
}
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
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);
}