Atomic map update using java object mapper

Is it possible to do atomic update on maps stored in aerospike using java object mapper ? I am aware about the atomic updates using java client operate method, wondering if there is a way to do the same using AeroMapper.

@AerospikeRecord (namespace = "test", set = "someset")
public class Document {
    @AerospikeKey
    private String key;

    private String createdBy;

    private String updatedBy;

    private Map<String, SomeObject> dataMap;
}

Hi Divik,

What sort of operations are you trying to do atomically? We have a facility called Virtual Lists which allows multiple operations to be performed on lists and will perform these atomically through the operate() call.

Note that it’s called a “Virtual List”, but as the example in that link shows those lists can be contained in maps. However, it’s really designed to store business objects i the list / map rather than unstructured data. From your example above I think this is what you’re using, but I would have expected an @AerospikeEmbed annotation on your Map.

Does this meet your need? If not, can you please give me more details about what you’re trying to achieve? It is of course possible to fall down to the native API where you can get the record key using AeroMapper.getKey(Object) but we would prefer to have the most used functionality in the AeroMapper itself, hence the request for more information.

Sorry for delayed response, but I decided to go ahead with java client instead of mapper.

My use case was inserting keys into the map without doing a get operation, this is pretty straightforward using client.operate in aerospike java client.

Virtual lists does looks promising and does seems to fit the use case here. Do they work irrespective what the type of field is in Java POJO and aerospike (could be Map in java POJO, map in aerospike or Map in java pojo, List in aerospike etc.)

Also have added detailed question about my use case here

in case you have any inputs on this, please share

Thanks Divik, much appreciated.

You asked:

Virtual lists does looks promising and does seems to fit the use case here. Do they work irrespective what the type of field is in Java POJO and aerospike (could be Map in java POJO, map in aerospike or Map in java pojo, List in aerospike etc.)

They’re really designed for more of a list semantic than a map, but we could probably make them work with maps. Typically they will become Maps in the Aerospike database. This does however assume that your map key is the @AerospikeKey of your object. Is that the case in your use case?

I can foresee a use case where you do want objects stored in a map against an arbitrary key, so I might look at how we could support these semantics anyway. In the meantime however, you can still use the object mapper to do the bulk of your work, combined with the operate() command. Let’s say you have an existing map and want to store myCustomObject : CustomObject in the map with a string key of key1. This can be achieved using:

IAerospikeClient client = new AerospikeClient(...);
AeroMapper mapper = new AeroMapper.Builder(client).build();
...
mapper.getClient().operate(null, 
    builder.getRecordKey(myDocument), 
    MapOperation.put(MapPolicy.Default, "mapBin", Value.get("key1"), 
        Value.get(builder.getMappingConverter().convertToMap(myCustomObject))));

In this case we’re using the object mapper to get the record key of you document, and to convert the CustomObject into a map, ready to be inserted into the map in your record.

It should be remembered that the object mapper is designed to augment the power of the native Aerospike client, not replace it and I think this is a great example of this. When there are common use cases we can enhance the mapper to do natively, we will do so, but I hope is a good interim solution.