[PVE-User] Simultaneous API call

Thomas Lamprecht t.lamprecht at proxmox.com
Sat Feb 13 10:07:53 CET 2016


Hi,

can you show a (simple) example how you do it? Are you making next id
calls from all over the cluster (in parallel)?

If you're doing it in serial like:

new_vmid = call-to-nextid();
create-ct(new_vmid)

you're fine, doing parallel calls you get race conditions and atomicity
violations.

Solving that could be done in several ways:

* Locking from your side (with semaphore, mutex, ...)


LOCK(CREATE)

new_vmid = call-to-nextid();
create-ct(new_vmid)

UNLOCK(CREATE)


this is a pit of an overkill though, as you only need to lock until the
container config is created in:

/etc/pve/nodes/<yournode>/lxc/<neew_vmid>.conf

Ther should be also the possibility to force create a CT, AFAIK, then
you could do the following:

LOCK(CREATE)

new_vmid = call-to-nextid();

// create the cfg file before calling pct create
touch /etc/pve/nodes/<yournode>/lxc/<new_vmid>.conf

UNLOCK(CREATE)

create-ct(new_vmid, force=true)


The locked context here would be magnitudes shorter and thus everything
more responsive, BUT I didn't tested that sod it could be that I'm miss
a check we do, will quickly test it on Monday.

Third way would be to hold a possible free list "bitmap" of VMIDs in
your program which you use to determine the next free. This would be
synced with the real one from time to time, not that nice but a possibility.

Out of interest, in what language do you make this? And what's the goal,
if I may ask?

cheers,
Thomas


On 10.02.2016 10:08, Mohamed Sadok Ben Jazia wrote:
> Hello list,
> I'm creating LXC container using the API on proxmox 4.1
> I use get("/cluster/nextid") to get the next free id to use.
> The issue i encountered is when i do simultaneous number of API calls
> I get proxmox trying to create containers with the same ID which gave me
> this error
> 
> trying to aquire lock...TASK ERROR: can't lock file
> '/run/lock/lxc/pve-config-147.lock' - got timeout
> 
> are there a standard way to deal with this?
> 
> 
> _______________________________________________
> pve-user mailing list
> pve-user at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user
> 




More information about the pve-user mailing list