[PVE-User] Simultaneous API call

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


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();

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

Solving that could be done in several ways:

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


new_vmid = call-to-nextid();


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


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


new_vmid = call-to-nextid();

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


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?


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