How to achieve atomic update on a map inside a Aerospike Model?

@AerospikeEntity(nameSpace = Constants.NAMESPACE, setName = Constants.NDC_SET) public class NDCModel implements Serializable {

private static final long serialVersionUID = 1L;
private String cycle;
private long  debitAmount;
private long  creditAmount;
private Map<String, AtomicDouble> map;

} suppose atomically i want to update one key inside this given map ,how to do it in Aerospike java client ?

Hi @avinashk8083,

Here’s a Jupyter Notebook that explains how to work with maps in Aerospike, if you want it in an interactive Jupyter Notebook environment, click here, if you want just the information, here’s the github repo.

Aerospike supports a standard double data type. I expect you will need to do a type conversion or send it to Aerospike as Binary.

Since you care about atomic updates on the app, it might be helpful to know that an Aerospike Record can be updated in an ACID-compliant fashion inside the database. Here is another notebook on simple transactions. Binder | Git.

Binder can take a few minutes to load. You might enjoy installing the repo in Docker, so you can work with your own local interactive copy of the notebooks.

Let me know if you have any additional questions,


Just to add to Mark’s response, a single record request (which can have multiple read and writes on bins) is always atomic. If you are trying to achieve read-write transaction isolation (that is, a write is not overwritten and lost due to concurrent updates), please check out this blog post.

1 Like
© 2021 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.