<br>Sorry again , think i didn't confirm the inscription before sending the mail... :)<br><br><div class="gmail_quote">2010/6/8 Alberto Casado <span dir="ltr"><<a href="mailto:alberto.casado.martin@gmail.com">alberto.casado.martin@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;"><div><br></div><div><br></div><div>I forgot one step in the code, sorry.</div>
<div><br></div><br><div><div>El 08/06/2010, a las 02:08, Alberto Casado escribió:</div><div class="im"><br><blockquote type="cite"><div style="word-wrap: break-word;">Hi all<div><span style="white-space: pre;">        </span>I don't know if this is the list where I have to ask, if isn't it, sorry.</div>
<div><br></div><div>In the last weeks I am having a lot of problems trying to figure out how ZODB should interact with a multithread app.</div><div>In short, basically the App is a GUI that receives data from sensors. It is a distributed system, built with omniORB, when the info comes from the sensors it is store in ZODB and it is shown in a GUI where can be modify by an operator (human) and this changes are commited to ZODB and send back to the sensor.</div>
<div><br></div><div><span style="white-space: pre;">        </span>I have a connection for each thread, due to that sometimes the thread is created in c++, I don't have the control of the pool. But i am pretty sure that before any change is done, I create a new connection for this thread (and also getting the root object).</div>
<div>Almost every time i try to commit to ZODB I have an error</div><div><span style="white-space: pre;">        </span> Duplicate tpc_begin calls for same transaction</div><div><br></div><div>I have observed that when info comes from the sensors (one call, one thread , I am dealing only with one message now) and I update the data , different objects (ZODB persistent classes), these distinct objects are registered in several connections, so when I try to commit them, always end up in the same error...</div>
<div><br></div><div>As I can see in the code, the first time goes fine, but the second is going to fail always, because the transaction is assigned to the storage.</div><div><br></div><div>from _transaction.py:</div><div>
<div style="margin: 0px;"><span style="color: rgb(44, 38, 249);">def</span> _commitResources(self):</div><div style="margin: 0px; color: rgb(203, 203, 203);"><span style="color: rgb(0, 0, 0);"> </span># Execute the two-phase commit protocol.</div>
<div style="margin: 0px; min-height: 21px;"><br></div><div style="margin: 0px;"> L = list(self._resources)</div><div style="margin: 0px;"> L.sort(rm_cmp)</div><div style="margin: 0px;"> <span style="color: rgb(44, 38, 249);">try</span>:</div>
<div style="margin: 0px;"> <span style="color: rgb(44, 38, 249);">for</span> rm <span style="color: rgb(44, 38, 249);">in</span> L:</div><div style="margin: 0px;"> rm.tpc_begin(self)------- tpc_begin always with self.</div>
<div style="margin: 0px;"> <span style="color: rgb(44, 38, 249);">for</span> rm <span style="color: rgb(44, 38, 249);">in</span> L:</div><div style="margin: 0px;"> rm.commit(self)</div><div style="margin: 0px;">
self.log.debug(<span style="color: rgb(0, 182, 38);">"commit %r"</span> % rm)</div><div style="margin: 0px;"> <span style="color: rgb(44, 38, 249);">for</span> rm <span style="color: rgb(44, 38, 249);">in</span> L:</div>
<div style="margin: 0px;"> rm.tpc_vote(self)</div><div style="margin: 0px;"> self._voted[id(rm)] = <span style="color: rgb(44, 38, 249);">True</span></div></div></div></blockquote><div><br></div>
</div><div>from Connection.py.</div><div><br></div><div><div style="margin: 0px;"><span style="color: rgb(44, 38, 249);">def</span> tpc_begin(self, transaction):</div><div style="margin: 0px; color: rgb(0, 182, 38);"><span style="color: rgb(0, 0, 0);"> </span>"""Begin commit of a transaction, starting the two-phase commit."""</div>
<div style="margin: 0px;"> self._modified = []</div><div style="margin: 0px; min-height: 21px;"><br></div><div style="margin: 0px; color: rgb(203, 203, 203);"><span style="color: rgb(0, 0, 0);"> </span># _creating is a list of <span style="text-decoration: underline;">oids</span> of new objects, which is used to</div>
<div style="margin: 0px; color: rgb(203, 203, 203);"><span style="color: rgb(0, 0, 0);"> </span># remove them from the cache if a transaction aborts.</div><div style="margin: 0px;"> self._creating.clear()</div>
<div style="margin: 0px;"> self._normal_storage.tpc_begin(transaction)</div></div><div class="im"><div><br></div><div><br></div><div><br></div><br><blockquote type="cite"><div style="word-wrap: break-word;"><div><div style="margin: 0px;">
<font color="#2c26f9"><br></font></div><div style="margin: 0px;"><font color="#2c26f9">From BasicStorage.py</font></div><div style="margin: 0px;"><font color="#2c26f9"><div style="margin: 0px;"><span style="color: rgb(44, 38, 249);">def</span> tpc_begin(self, transaction, tid=<span style="color: rgb(44, 38, 249);">None</span>, status=<span style="color: rgb(0, 182, 38);">' '</span>):</div>
<div style="margin: 0px;"> <span style="color: rgb(44, 38, 249);">if</span> self._is_read_only:</div><div style="margin: 0px;"> <span style="color: rgb(44, 38, 249);">raise</span> POSException.ReadOnlyError()</div>
<div style="margin: 0px;"> self._lock_acquire()</div><div style="margin: 0px;"> <span style="color: rgb(44, 38, 249);">try</span>:</div><div style="margin: 0px;"> <span style="color: rgb(44, 38, 249);">if</span> self._transaction <span style="color: rgb(44, 38, 249);">is</span> transaction:------------ the fisrt time goes fine,but the second always fail</div>
<div style="margin: 0px;"> <span style="color: rgb(44, 38, 249);">raise</span> POSException.StorageTransactionError(</div><div style="margin: 0px; color: rgb(0, 182, 38);"><span style="color: rgb(0, 0, 0);"> </span>"Duplicate tpc_begin calls for same transaction"<span style="color: rgb(0, 0, 0);">)</span></div>
<div style="margin: 0px;"> self._lock_release()</div><div style="margin: 0px;"> self._commit_lock_acquire()</div><div style="margin: 0px;"> self._lock_acquire()</div><div style="margin: 0px;">
self._transaction = transaction------------</div><div style="margin: 0px;"> self._clear_temp()</div><div style="margin: 0px;"><div style="margin: 0px;"><br></div><div style="margin: 0px;">This is killing me, I don't know if it is an error registering modifications that are happening in one thread, to several connections and I dont know why this is happening...</div>
<div style="margin: 0px;"><br></div><div style="margin: 0px;">I someone can give me some clue...</div><div><br></div></div><div style="margin: 0px;"><br></div><div style="margin: 0px;">BR.</div><div style="margin: 0px;"><br>
</div><div style="margin: 0px;">Alberto.</div><div style="margin: 0px;">PD: sorry for my English.</div><div style="margin: 0px;"><br></div><div style="margin: 0px;"><br></div><div style="margin: 0px;"><br></div></font></div>
</div></div></blockquote></div></div></div></blockquote></div>