<div dir="ltr"><div><div><div><div><div><div><div><div>Hello,<br></div>to describe my purpose, i'm supposed to create a commercial plateform for providing IAAS and PAAS using proxmox.<br></div>For this step, i'm planning to develop a full API for third pary users, the development will be done in PHP as start.<br></div>The API will contain 3 main parts (clustering and managing hosts and nodes, Actions on CT's and VM's, Authorisations handling)<br></div>The issue i'm facing here happens when i run simultaneous API call to create CT's on the same host because i'm using call-to-nextid() that returns the same id.<br></div>I think semaphores or mutex are not a good options because once not well implemented, i will have deadlocks which is worst than simple error.<br></div>I simply think to implement call-to-nextid() myself and get a list of used id's and add a random number for security but it's not a perfect choice.<br><br></div>Thanks<br></div>Sadok<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 13 February 2016 at 10:07, Thomas Lamprecht <span dir="ltr"><<a href="mailto:t.lamprecht@proxmox.com" target="_blank">t.lamprecht@proxmox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
can you show a (simple) example how you do it? Are you making next id<br>
calls from all over the cluster (in parallel)?<br>
<br>
If you're doing it in serial like:<br>
<br>
new_vmid = call-to-nextid();<br>
create-ct(new_vmid)<br>
<br>
you're fine, doing parallel calls you get race conditions and atomicity<br>
violations.<br>
<br>
Solving that could be done in several ways:<br>
<br>
* Locking from your side (with semaphore, mutex, ...)<br>
<br>
<br>
LOCK(CREATE)<br>
<br>
new_vmid = call-to-nextid();<br>
create-ct(new_vmid)<br>
<br>
UNLOCK(CREATE)<br>
<br>
<br>
this is a pit of an overkill though, as you only need to lock until the<br>
container config is created in:<br>
<br>
/etc/pve/nodes/<yournode>/lxc/<neew_vmid>.conf<br>
<br>
Ther should be also the possibility to force create a CT, AFAIK, then<br>
you could do the following:<br>
<br>
LOCK(CREATE)<br>
<br>
new_vmid = call-to-nextid();<br>
<br>
// create the cfg file before calling pct create<br>
touch /etc/pve/nodes/<yournode>/lxc/<new_vmid>.conf<br>
<br>
UNLOCK(CREATE)<br>
<br>
create-ct(new_vmid, force=true)<br>
<br>
<br>
The locked context here would be magnitudes shorter and thus everything<br>
more responsive, BUT I didn't tested that sod it could be that I'm miss<br>
a check we do, will quickly test it on Monday.<br>
<br>
Third way would be to hold a possible free list "bitmap" of VMIDs in<br>
your program which you use to determine the next free. This would be<br>
synced with the real one from time to time, not that nice but a possibility.<br>
<br>
Out of interest, in what language do you make this? And what's the goal,<br>
if I may ask?<br>
<br>
cheers,<br>
Thomas<br>
<div><div class="h5"><br>
<br>
On 10.02.2016 10:08, Mohamed Sadok Ben Jazia wrote:<br>
> Hello list,<br>
> I'm creating LXC container using the API on proxmox 4.1<br>
> I use get("/cluster/nextid") to get the next free id to use.<br>
> The issue i encountered is when i do simultaneous number of API calls<br>
> I get proxmox trying to create containers with the same ID which gave me<br>
> this error<br>
><br>
> trying to aquire lock...TASK ERROR: can't lock file<br>
> '/run/lock/lxc/pve-config-147.lock' - got timeout<br>
><br>
> are there a standard way to deal with this?<br>
><br>
><br>
</div></div>> _______________________________________________<br>
> pve-user mailing list<br>
> <a href="mailto:pve-user@pve.proxmox.com">pve-user@pve.proxmox.com</a><br>
> <a href="http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user" rel="noreferrer" target="_blank">http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user</a><br>
><br>
<br>
_______________________________________________<br>
pve-user mailing list<br>
<a href="mailto:pve-user@pve.proxmox.com">pve-user@pve.proxmox.com</a><br>
<a href="http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user" rel="noreferrer" target="_blank">http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user</a><br>
</blockquote></div><br></div>