2016-04-09 43 views
2

Aerospike记录UDF是原子的吗?Aerospike记录UDF是原子性的吗?

function increment_and_expire(rec, incValue, expireThreshold, currentTime) 
     if aerospike:exists(rec) then 
      local timesUsed = rec['timesUsed'] 
      if timesUsed == expireThreshold or rec['validUpto'] < currentTime then 
      rec['expired'] = true 
     else 
      rec['timesUsed'] = timesUsed + incValue 
     end 
     aerospike:update(rec) 
     return 1 
    else 
     warn("record doesn't exists") 
     return -1 
    end 
end 

上面的Lua函数增加了令牌的使用,如果它不再有效,它会将其标记为过期。 现在我的疑问是,如果并发请求来自同一条记录,并且此函数正在同时执行,是否会导致任何问题?

回答

3

你在问隔离,而不是真正的原子性。 Aerospike每个密钥以序列化方式执行所有事务。即,在任何给定的时间点,一个写事务可以在一个密钥上激活。其他人都等待。执行顺序不一定是FIFO,而是序列化的。 udf也是如此。