Is Record UDF calling thread safe?


#1

If multi-threads call UDF function(with write-operation) on same record, there have internal locks or something else to protect the data?


#2

Yes, records are locked during write operations (from either the client or from record UDF).


#3

Locked when writing operation. How about reading?

Calling as_operations_add_incr(ops, “bin”, 1) from client should be thread-safe.

But calling a lua function below thread-safe ? :

if aerospike:exists(rec) then

    local v = rec['bin']
    rec['bin'] = v + 1

	return aerospike:update(rec)
else
    ...    
end

#4

Yes.

More info here:

http://stackoverflow.com/questions/25920610/aerospike-acid-clarification


#5

Thanks. The link is helpful


#6

I am recently doing a POC on UDP with a similar use case. Can someone explain how aersopike avoids race condition when multiple threads call this UDP on same record?


#7

Ahead of executing a record UDF on a specified key a record lock is obtained. If other threads are trying to do the same they will queue up.