コード例 #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;

}
コード例 #2
0
static int mod_lua_map_new(lua_State * l) {
	int n = lua_gettop(l);
	if (n != 1) {
		return 0;
	}
	lua_Integer capacity = luaL_optinteger(l, 1, 0);
	if (capacity < 1) {
		return 0;
	}
	as_map * map = (as_map *) as_hashmap_new((uint32_t)capacity);
	mod_lua_pushmap(l, map);
	return 1;
}
コード例 #3
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;
}
コード例 #4
0
static bool
unpack_map(serial_context *ser_cont, uint32_t size, as_val **value)
{
	if (VERBOSE) {
		ver("%sMap, %u element(s)", indent(ser_cont), size);
	}

	as_hashmap *map = as_hashmap_new(size > 32 ? size : 32);

	if (map == NULL) {
		err("Error while allocating map");
		return false;
	}

	ser_cont->indent += 2;

	for (uint32_t i = 0; i < size; ++i) {
		as_val *key, *val;

		if (!UNPACK_VALUE(ser_cont, &key) || !UNPACK_VALUE(ser_cont, &val)) {
			err("Error while unpacking map key or value");
			as_hashmap_destroy(map);
			return false;
		}

		if (as_hashmap_set(map, key, val) < 0) {
			err("Error while populating map");
			as_hashmap_destroy(map);
			return false;
		}
	}

	ser_cont->indent -= 2;
	*value = (as_val *)map;
	return true;
}
コード例 #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()
コード例 #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()
コード例 #7
0
ファイル: map_rec.c プロジェクト: Benguang/aerospike-client-c
as_rec * map_rec_init(as_rec * r) {
    as_map * m = (as_map *) as_hashmap_new(32);
    return as_rec_init(r, m, &map_rec_hooks);
}
コード例 #8
0
ファイル: map_rec.c プロジェクト: Benguang/aerospike-client-c
as_rec * map_rec_new() {
    as_map * m = (as_map *) as_hashmap_new(32);
    return as_rec_new(m, &map_rec_hooks);
}