I have 2 tables Cluster and Node, each having a volume_limit and 
volume_count column in it.
To atomically check and increment the volume count for a Cluster and Node I 
do the following
updated = Cluster.objects.filter(id=cluster_id, 
volume_count__lt==F('volume_limit')).update(volume_count = 
F('volume_count')+1)
if not updated:
    raise Validation('limit reached ......')
updated = Node.objects.filter(id=node_id, 
volume_count__lt==F('volume_limit')).update(volume_count = 
F('volume_count')+1)
if not updated:
    Cluster.objects.filter(id=cluser_id).update(volume_count = 
F('volume_count')-1)
    raise Validation('limit reached ......')


I am wondering if there is way to do both of this atomically?

Basically I want to 
   1. create a query for Cluster, Node, etc, N such objects/tables queries, 
that each filter match one row by pk and volume_count__lt=F('volume_count')
   2. Check that the union of all these queries translates to exactly N 
objects, one for each Object/Table. i.e. the counts are within limit for 
each object/table
   3. Do a volume_count=F('volume_count')+1 for all those objects/table 
together.

How do I do this?

Thanks,
Sarvi

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f47d5d55-d97a-4e63-85b2-4740e56c10ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to