While creating or updating record in udf, does it support check for Generation Equals which is normally supported in put command via Write Policy? I was expecting UDF honours Write Policy and if generation policy is being set to Generation Equals, it would allow write only if generation is equal to the supplied value. Else will throw Aerospike Exception. However this does not seem to be happening
Generation check while updating is generally required when doing CAS (check (gen) and set) kind of operation where record is fetched by application and attempt is made to write it back. While doing so protection is needed from concurrent write.
With you UDF application need not worry about two round trips the entire logic can be embedded in UDF itself with single call to server. Hence no such support for generation check is provided for UDF.
Can you elaborate on need for such policy support.
We have a bin with data of type map. This map can contain 500-1000 elements of byte array type. Mostly our updates are restricted to one element(key-value pair) in map. To avoid sending all of data for map over network to application, we have written a udf which takes just key-value as argument and updates the map in aerospike bin. Also another udf to get value of a key in map. There can be very large number of requests to these maps. And hence by just sending one key-value pair(instead of entire map) we save lot of network traffic.
So basically we have 2 udfs. One to get value of map from key and another to put a value against a key in map which is part of one bin. Between this get and put, there can be another parallel request which might have updated the same value for the map. To avoid this, we wanted to have generation check as it can throw Aersopike Exception and we can retry at application layer. We can’t move application logic to udf as it’s very complex logic written in java. So we need two calls…one to get existing value and another to update.
For the time being we have handled it manually in udf by checking generation and throwing respective error(using record.gen(rec)). But I was wondering why it’s not part of inbuilt functionality while other parts of write policy like ttl, sendKey etc are supported by default and need not to be handled in udf.