Inserting nested map

Dear team, I’m using aerospike-server-community-4.6.0.2 and aerospike-client-c-4.6.6 on Red Hat Enterprise Linux Server release 7.5. I’m facing some difficulties while trying to insert a nested map in Aerospike.

Please find below a sample c++ function that I’m using:

int insertNestedMap(aerospike* aero)
{
    as_cdt_ctx ctx;
    as_cdt_ctx_inita(&ctx, 1);
    as_string str;
    as_string_init(&str,(char*) "outer_key", false);
    as_cdt_ctx_add_map_key(&ctx, (as_val*)&str);
    
    as_operations ops;
    as_operations_inita(&ops, 1);
    
    as_string l_key;
    as_string_init(&l_key, (char*)"inner_key", false);
    as_integer l_val;
    as_integer_init(&l_val, 11);

    as_map_policy map_policy;
    as_map_policy_init(&map_policy);
   
    as_operations_map_put(&ops, "bin_name", &ctx, &map_policy, (as_val*)&l_key, (as_val*)&l_val);
    as_error l_asError;
    as_record* rec = NULL;
    as_key key;
    as_key_init_str(&key, "test", "test_nested_map", "k1");

    as_status l_operateStatus = aerospike_key_operate(aero, &l_asError, NULL, &key, &ops, &rec);
    if(l_operateStatus != AEROSPIKE_OK)
    {
      printf("\n[%s::%d]Error [%d] , Error_Msg-->%s-- \n",__FILE__,__LINE__,l_asError.code, l_asError.message);
      as_operations_destroy(&ops);
      as_record_destroy(rec);
      return -1;
    }
    else
    {
      printf("\nNested Map successfully inserted\n");
      as_operations_destroy(&ops);
      as_record_destroy(rec);
      return 0;
    }  
}

My client program is getting the below error: Error [4] , Error_Msg-->172.16.129.68:3000 AEROSPIKE_ERR_REQUEST_INVALID--

In the server logs, I see the following: WARNING (rw): (write.c:1891) {test} write_master: failed as_bin_cdt_alloc_modify_from_client() <Digest>:0xd09c52914e9b556c651769606812bf5040108bed

Please let me know what’s going wrong here. Also, I don’t understand understand how to use as_map_policy except the default values. The documentation is not very clear as to how to set the required policy in the structure. Kindly guide me on that as well.

Thanks!

as_cdt_ctx is used to identify the entry in nested list/maps that the operation will apply to. as_cdt_ctx is not used to create the initial list/map.

See map_nested test in map_basics.c for an example on how to create a nested map and operate on an entry in that nested map.

See map_put_items test in map_basics.c for an example on how to use as_map_policy to create a key ordered map.

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.

© 2015 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.