2016-04-09 44 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也是如此。