Hi,

I am developing an OTP (One time password) API for my company, and using
Riak with riak-python-client to store used passwords. Everytime users try
to login, a function will delete all used passwords that are older than 5
minutes:

def delete_old_otps(username, pid, EPOCHTIME):
    client, bucket = open_otp_db(pid, username)
    for key in bucket.get_keys():
        cached_otp = bucket.get(key)
        if not cached_otp.exists():
            continue
        otp_time = int(cached_otp.get_data().get('EPOCHTIME'))
        if (EPOCHTIME - otp_time) > 30:
            cached_otp.delete()

If there are 2 (or more) threads use this function at a same time, it will
cause error. Assume that both thread A and thread B have retrieved the keys
list (use bucket.get_keys()), and thread A deleted all of the old passwords
in the bucket, then when thread B tried to execute:

    cached_otp = bucket.get(key)

cached_otp.get_data() would return None, causing error in this line:

   otp_time = int(cached_otp.get_data().get('EPOCHTIME'))

Anyone can help me with this problem?

Thanks for any hint/comment,
Lưu Tuấn Hải

P/S: Sorry for my bad English
_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to