Re: Atomic Operations?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm using a different scheme (might be suboptimal in your case).

I store object version id in object attributes. Every update increases version number. So the update first reads object version from rados and then creates transaction like this

```python
wop = ctx.write_op_create()
wop.assert_exists()
wop.cmpxattr('version', rados.CmpXattrOp.eq, current_version)
wop.setxattr('version', new_version)
wop.write_full(data)
```

If it fails because of the condition, I just retry. Creating new object is similar

```
wop = ctx.write_op_create()
wop.create(True)
wop.setxattr('version', version)
wop.write_full(data)
```

If it fails, it's because something just created that object before me and I just retry.

On 2016-12-24 13:56, Wido den Hollander wrote:
Op 23 december 2016 om 21:14 schreef Kent Borg <kentborg@xxxxxxxx>:


Hello, a newbie here!

Doing some playing with Python and librados, and it is mostly easy to
use, but I am confused about atomic operations. The documentation isn't
clear to me, and Google isn't giving me obvious answers either...

I would like to do some locking. The data structures I am playing with
in RADOS should work great if I don't accidentally fire up more than one
instance of myself. So I would like to drop an attribute on a central
object saying it's mine, all mine--but only if another copy of myself
hasn't done so already.

Is there some sample code to show me the safe way to do this?


You might want to use a RADOS watcher in this case? Your application
would be registered as a watcher and while it is running you can check
if there are other watchers on a object before you proceed.

I don't have a code example right now, but you might want to look in
that direction.

Wido

Thanks,

-kb, the Kent who is reluctant to just play around with locking to see
what works...because it might look like it is working, yet still have a
race susceptibility.

_______________________________________________
ceph-users mailing list
ceph-users@xxxxxxxxxxxxxx
http://lists.ceph.com/listinfo.cgi/ceph-users-ceph.com
_______________________________________________
ceph-users mailing list
ceph-users@xxxxxxxxxxxxxx
http://lists.ceph.com/listinfo.cgi/ceph-users-ceph.com
_______________________________________________
ceph-users mailing list
ceph-users@xxxxxxxxxxxxxx
http://lists.ceph.com/listinfo.cgi/ceph-users-ceph.com



[Index of Archives]     [Information on CEPH]     [Linux Filesystem Development]     [Ceph Development]     [Ceph Large]     [Linux USB Development]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [xfs]


  Powered by Linux