Skip to content
Advertisement

Aerospike: atomically create a list if it does not exists and append items to this list

The bin in aerospike is a Map[String -> List]

I am trying to achieve the behavior as such:

JavaScript

Is there a way to do this atomically in Aerospike without implementing a UDF? If I read the documentation correctly, if it was a Map[String -> Map], I could have used CTX.mapKeyCreate to create the inner Map on demand, but I don’t see anything similar for creating a List

UPD: Here is what I am trying to do

I have a stream of triplets:

JavaScript

I need to sink this stream into aerospike set aggregating by pk and attr in the following format:

JavaScript

So let’s say there are three items in the stream: {"pk","attr1","value1"},{"pk","attr2","value2"},{"pk","attr1","value3"}

They need to land in the aerospike as such:

JavaScript

To insert a new item {"pk","attr2","value2"} I need to perform several actions:

  1. Get the list at mapBin[attr2]
  2. If it does not exist, insert empty List into the map
  3. Do ListOperation.append to append the item to existing list

Question is: is there a way to do it atomically without UDF?

Advertisement

Answer

You should be able to perform these actions atomically with the following (Java syntax):

JavaScript

You can use ListOperation.appendItems() if there are multiple items to be appended to a list, and multiple ListOperations for different lists in the map within the same operate(), all of which will be executed atomically.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement