Re: [ZODB-Dev] newbie ZEO first try. ConflictError.

2009-11-26 Thread Christian Theune
Hi,

On 11/26/2009 10:55 PM, tsmiller wrote:
>
> Christian,
> Thanks. How painfully obvious.  I have written the words
> 'transaction.begin()' about a thousand times or so!  But I get
> discombobulated when I start looking at something new ( ZEO ) and forget the
> obvious.  Final code for this little test that works perfectly:
>
> while True:
>  transaction.begin()
>  root[ "one" ] = "program 2 - " + time.asctime()
>  while True:
>  try:
>  transaction.commit()
>  except POSException.ConflictError:
>  time.sleep(.2)
>  else:
>  break
>
>  time.sleep(5)

Two notes:

First, I'd leave the transaction.abort() right before the time.sleep(). 
Just to be explicit.

Second, the second while loop is superfluous - it doesn't do what it 
looks like and what you might think it does. ;)

You can try committing exactly once. If you commit after a conflict 
error, that will give you a different exception.

On the framework level conflict errors are usually handled by re-trying 
the *whole* transaction once more. E.g. in Zope it means:

- abort the transaction
- start a new transaction
- process the request as it was again

If it fails for three times then Zope gives up and hands the conflict 
error to the user.

Christian

-- 
Christian Theune · c...@gocept.com
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 0 · fax +49 345 1229889 1
Zope and Plone consulting and development

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] newbie ZEO first try. ConflictError.

2009-11-26 Thread tsmiller

Christian,
Thanks. How painfully obvious.  I have written the words
'transaction.begin()' about a thousand times or so!  But I get
discombobulated when I start looking at something new ( ZEO ) and forget the
obvious.  Final code for this little test that works perfectly:

while True:
transaction.begin()
root[ "one" ] = "program 2 - " + time.asctime()
while True:
try:
transaction.commit()
except POSException.ConflictError:
time.sleep(.2)
else:
break

time.sleep(5)

tom



Christian Theune-2 wrote:
> 
> Hi,
> 
> On 11/26/2009 10:08 PM, James Bergstra wrote:
>> On Thu, Nov 26, 2009 at 1:51 PM, tsmiller 
>> wrote:
>>>
>>> Laurence,
>>> Thank you for your very quick reply.  I did as you suggested and now the
>>> ConflictError is now handled.  And that is a most excellent thing
>>> because
>>> now ConflictError is raised every time.  So it still seems to be
>>> confused.
>>> I am trying to figure out if I will be able to use ZEO in my
>>> application.
>>>
>>> Now my program reads:
>>>
>>> while True:
>>> root[ "one" ] = time.asctime()
>>> while True:
>>> try:
>>> print "Try to commit transaction"
>>> transaction.commit()
>>> print "root is",  root
>>> except POSException.ConflictError:
>>> print "we have a conflict"
>>> transaction.abort()
>>> time.sleep(.2)
>>> else:
>>> break
>>>
>>> time.sleep(10)
>>>
>>
>> I have a related question about this code... in the inner loop tom is
>> calling abort() ; sleep(); commit().  Does that make sense?
>>
>> I thought that abort() would revert the root to the database's version
>> of things, and discard any change that the client had tried to make.
>> So what does it mean to call commit() again immediately and why that
>> commit cause a conflict when the client hasn't actually changed
>> anything since abort() ?
> 
> The abort() actually also marks the point when the next transaction 
> begins implicitly.
> 
> Your code would work perfectly if whenever you start a transaction, you 
> simply call transaction.begin():
> 
> while True:
>  transaction.begin()
>  root[
> 
> This will cause the time.sleep(2) to not be included in the transaction 
> and your conflict rate will quickly go down for your example. If you 
> also use a random factor for the sleep (e.g. between 0.2 and 0.3) then 
> you'll have a lesser chance of subsequent conflicts in your example 
> because all your transactions are very similar. In real life 
> transactions would be distinct enough to cause different offsets in
> runtime.
> 
> Hope this helps,
> Christian
> 
> -- 
> Christian Theune · c...@gocept.com
> gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
> http://gocept.com · tel +49 345 1229889 0 · fax +49 345 1229889 1
> Zope and Plone consulting and development
> 
> ___
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
> 
> ZODB-Dev mailing list  -  ZODB-Dev@zope.org
> https://mail.zope.org/mailman/listinfo/zodb-dev
> 
> 

-- 
View this message in context: 
http://old.nabble.com/newbie-ZEO-first-try.--ConflictError.-tp26532984p26535390.html
Sent from the Zope - ZODB-Dev mailing list archive at Nabble.com.

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] newbie ZEO first try. ConflictError.

2009-11-26 Thread Christian Theune
Hi,

On 11/26/2009 10:08 PM, James Bergstra wrote:
> On Thu, Nov 26, 2009 at 1:51 PM, tsmiller  wrote:
>>
>> Laurence,
>> Thank you for your very quick reply.  I did as you suggested and now the
>> ConflictError is now handled.  And that is a most excellent thing because
>> now ConflictError is raised every time.  So it still seems to be confused.
>> I am trying to figure out if I will be able to use ZEO in my application.
>>
>> Now my program reads:
>>
>> while True:
>> root[ "one" ] = time.asctime()
>> while True:
>> try:
>> print "Try to commit transaction"
>> transaction.commit()
>> print "root is",  root
>> except POSException.ConflictError:
>> print "we have a conflict"
>> transaction.abort()
>> time.sleep(.2)
>> else:
>> break
>>
>> time.sleep(10)
>>
>
> I have a related question about this code... in the inner loop tom is
> calling abort() ; sleep(); commit().  Does that make sense?
>
> I thought that abort() would revert the root to the database's version
> of things, and discard any change that the client had tried to make.
> So what does it mean to call commit() again immediately and why that
> commit cause a conflict when the client hasn't actually changed
> anything since abort() ?

The abort() actually also marks the point when the next transaction 
begins implicitly.

Your code would work perfectly if whenever you start a transaction, you 
simply call transaction.begin():

while True:
 transaction.begin()
 root[

This will cause the time.sleep(2) to not be included in the transaction 
and your conflict rate will quickly go down for your example. If you 
also use a random factor for the sleep (e.g. between 0.2 and 0.3) then 
you'll have a lesser chance of subsequent conflicts in your example 
because all your transactions are very similar. In real life 
transactions would be distinct enough to cause different offsets in runtime.

Hope this helps,
Christian

-- 
Christian Theune · c...@gocept.com
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 0 · fax +49 345 1229889 1
Zope and Plone consulting and development

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] newbie ZEO first try. ConflictError.

2009-11-26 Thread tsmiller

James,
You were right.  I moved the assignment into the inner loop where is is
reassigned each time after the abort.  However, if I do not put the abort()
in, then the ZODB comes back with a ConflictError and actually dies with a
TransactionFailedError.  The commit() is the purpose of the entire thing. 
To save my changes to the database.  And if the commit() does not work the
first time, then the loop waits a little while and trys the commit() again.

I have two programs now so that I could differentiate which one was actually
committing, and I still get a ConflictError every time a transaction is
tried.


while True:
while True:
## one program prints out program 1 and the other
program 2 to show origin of commit
root[ "one" ] = "program 2 - " + time.asctime()
try:
print "Try to commit transaction"
transaction.commit()
print "root is",  root
except POSException.ConflictError:
print "we have a conflict"
transaction.abort()
time.sleep(.2)
else:
break

time.sleep(10)


output:

we have a conflict
Try to commit transaction
root is {'one': 'program 2 - Thu Nov 26 14:29:02 2009'}
Try to commit transaction
we have a conflict
Try to commit transaction
root is {'one': 'program 2 - Thu Nov 26 14:29:12 2009'}
Try to commit transaction
we have a conflict
Try to commit transaction
root is {'one': 'program 2 - Thu Nov 26 14:29:22 2009'}
Try to commit transaction
we have a conflict




James Bergstra-2 wrote:
> 
> On Thu, Nov 26, 2009 at 1:51 PM, tsmiller 
> wrote:
>>
>> Laurence,
>> Thank you for your very quick reply.  I did as you suggested and now the
>> ConflictError is now handled.  And that is a most excellent thing because
>> now ConflictError is raised every time.  So it still seems to be
>> confused.
>> I am trying to figure out if I will be able to use ZEO in my application.
>>
>> Now my program reads:
>>
>> while True:
>>        root[ "one" ] = time.asctime()
>>        while True:
>>                try:
>>                        print "Try to commit transaction"
>>                        transaction.commit()
>>                        print "root is",  root
>>                except POSException.ConflictError:
>>                        print "we have a conflict"
>>                        transaction.abort()
>>                        time.sleep(.2)
>>                else:
>>                        break
>>
>>        time.sleep(10)
>>
> 
> I have a related question about this code... in the inner loop tom is
> calling abort() ; sleep(); commit().  Does that make sense?
> 
> I thought that abort() would revert the root to the database's version
> of things, and discard any change that the client had tried to make.
> So what does it mean to call commit() again immediately and why that
> commit cause a conflict when the client hasn't actually changed
> anything since abort() ?
> 
> James
> -- 
> http://www-etud.iro.umontreal.ca/~bergstrj
> ___
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
> 
> ZODB-Dev mailing list  -  ZODB-Dev@zope.org
> https://mail.zope.org/mailman/listinfo/zodb-dev
> 
> 

-- 
View this message in context: 
http://old.nabble.com/newbie-ZEO-first-try.--ConflictError.-tp26532984p26535272.html
Sent from the Zope - ZODB-Dev mailing list archive at Nabble.com.

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] newbie ZEO first try. ConflictError.

2009-11-26 Thread James Bergstra
On Thu, Nov 26, 2009 at 1:51 PM, tsmiller  wrote:
>
> Laurence,
> Thank you for your very quick reply.  I did as you suggested and now the
> ConflictError is now handled.  And that is a most excellent thing because
> now ConflictError is raised every time.  So it still seems to be confused.
> I am trying to figure out if I will be able to use ZEO in my application.
>
> Now my program reads:
>
> while True:
>        root[ "one" ] = time.asctime()
>        while True:
>                try:
>                        print "Try to commit transaction"
>                        transaction.commit()
>                        print "root is",  root
>                except POSException.ConflictError:
>                        print "we have a conflict"
>                        transaction.abort()
>                        time.sleep(.2)
>                else:
>                        break
>
>        time.sleep(10)
>

I have a related question about this code... in the inner loop tom is
calling abort() ; sleep(); commit().  Does that make sense?

I thought that abort() would revert the root to the database's version
of things, and discard any change that the client had tried to make.
So what does it mean to call commit() again immediately and why that
commit cause a conflict when the client hasn't actually changed
anything since abort() ?

James
-- 
http://www-etud.iro.umontreal.ca/~bergstrj
___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] newbie ZEO first try. ConflictError.

2009-11-26 Thread tsmiller

Laurence,
There are three things.  First, though I am writing to the same object, I am
only doing a write every 10 seconds.  That is an eternity in cpu time.  I
would not expect many conflicts to occur in eternity.  Secondly, the
conflict happens EVERY time from whichever program was started first.  There
is no randomness to it.  Third, I start the second program a few seconds
after the first, so there should be an offset of when each program writes to
the database.  

I have looked at the chatter page that you referred me to, but It is the way
that I do things to start small.  And small in this case means to be able to
write to a ZEO database from two programs without a conflict.  What you said
doesn't make sense to me.  I would appreciate it if you could expound some
to help me understand why.

thanks again,

tom 



Laurence Rowe wrote:
> 
> With that setup, you would expect a lot of conflicts, you are
> continually writing to the same object from more than one client. You
> will see many fewer conflicts if the different clients wrote to
> different objects or updated an object with conflict resolution (for
> instance inserting into a BTree).
> 
> You may find the example application at
> http://docs.zope.org/zodb/zodbguide/zeo.html#sample-application-chatter-py
> helpful. I've updated the conflict handling and links, but it will
> take a few hours for the update to be published to the website. In the
> meantime it may be downloaded from svn:
> http://svn.zope.org/zodbdocs/trunk/zodbguide/chatter.py?view=auto
> helpful.
> 
> Laurence
> 
> 2009/11/26 tsmiller :
>>
>> Laurence,
>> Thank you for your very quick reply.  I did as you suggested and now the
>> ConflictError is now handled.  And that is a most excellent thing because
>> now ConflictError is raised every time.  So it still seems to be
>> confused.
>> I am trying to figure out if I will be able to use ZEO in my application.
>>
>> Now my program reads:
>>
>> while True:
>>        root[ "one" ] = time.asctime()
>>        while True:
>>                try:
>>                        print "Try to commit transaction"
>>                        transaction.commit()
>>                        print "root is",  root
>>                except POSException.ConflictError:
>>                        print "we have a conflict"
>>                        transaction.abort()
>>                        time.sleep(.2)
>>                else:
>>                        break
>>
>>        time.sleep(10)
>>
>>
>> And the output is:
>>
>> // the program is only running once here
>> Try to commit transaction
>> root is {'one': 'Thu Nov 26 11:37:53 2009'}
>> Try to commit transaction
>> root is {'one': 'Thu Nov 26 11:38:03 2009'}
>> Try to commit transaction
>> root is {'one': 'Thu Nov 26 11:38:13 2009'}
>> Try to commit transaction
>> root is {'one': 'Thu Nov 26 11:38:23 2009'}
>> Try to commit transaction
>> root is {'one': 'Thu Nov 26 11:38:33 2009'}
>>
>> // after I start a second copy, the first copy always has a conflict (
>> the
>> second copy does not get this conflict error).
>> Try to commit transaction
>> we have a conflict
>> Try to commit transaction
>> root is {'one': 'Thu Nov 26 11:38:35 2009'}
>> Try to commit transaction
>> we have a conflict
>> Try to commit transaction
>> root is {'one': 'Thu Nov 26 11:38:46 2009'}
>> Try to commit transaction
>> we have a conflict
>> Try to commit transaction
>> root is {'one': 'Thu Nov 26 11:38:56 2009'}
>> Try to commit transaction
>> we have a conflict
>>
>> thanks,
>> tom
>>
>>
>>
>> Laurence Rowe wrote:
>>>
>>> You must be prepared to abort and retry the whole transaction:
>>>
>>>    while True:
>>>            while True:
>>>                    try:
>>>                            root[ "one" ] = time.asctime()
>>>                            transaction.commit()
>>>                    except POSException.ConflictError:
>>>                            transaction.abort()
>>>                            time.sleep(.2)
>>>                    else:
>>>                            break
>>>
>>>            time.sleep(10)
>>>
>>>
>>> Laurence
>>>
>>> 2009/11/26 tsmiller :

 ZODB Developers,

 Can you please tell me what I am doing wrong in my first simple attempt
 to
 make use of ZEO.  My ZODB and ZEO are both the same version (3.6.0).

 First, I start my ZEO server and it looks like it starts properly:

 python2.4 /usr/lib/python2.4/site-packages/ZEO/runzeo.py -a
 localhost:9100
 -f /home/tom/zeo/test.fs

 --
 2009-11-26T00:05:14 INFO ZEO.runzeo (8192) opening storage '1' using
 FileStorage
 --
 2009-11-26T00:05:14 INFO ZEO.StorageServer (8192) StorageServer created
 RW
 with storages: 1:RW:/home/tom/zeo/test.fs
 --
 2009-11-26T00:05:14 INFO ZEO.zrpc (8192) listening on ('localhost',
 9100)


 Second, I start my client, twice.  The purpose is to write to the same
 test.fs file from both of them.  The idea

Re: [ZODB-Dev] newbie ZEO first try. ConflictError.

2009-11-26 Thread Laurence Rowe
With that setup, you would expect a lot of conflicts, you are
continually writing to the same object from more than one client. You
will see many fewer conflicts if the different clients wrote to
different objects or updated an object with conflict resolution (for
instance inserting into a BTree).

You may find the example application at
http://docs.zope.org/zodb/zodbguide/zeo.html#sample-application-chatter-py
helpful. I've updated the conflict handling and links, but it will
take a few hours for the update to be published to the website. In the
meantime it may be downloaded from svn:
http://svn.zope.org/zodbdocs/trunk/zodbguide/chatter.py?view=auto
helpful.

Laurence

2009/11/26 tsmiller :
>
> Laurence,
> Thank you for your very quick reply.  I did as you suggested and now the
> ConflictError is now handled.  And that is a most excellent thing because
> now ConflictError is raised every time.  So it still seems to be confused.
> I am trying to figure out if I will be able to use ZEO in my application.
>
> Now my program reads:
>
> while True:
>        root[ "one" ] = time.asctime()
>        while True:
>                try:
>                        print "Try to commit transaction"
>                        transaction.commit()
>                        print "root is",  root
>                except POSException.ConflictError:
>                        print "we have a conflict"
>                        transaction.abort()
>                        time.sleep(.2)
>                else:
>                        break
>
>        time.sleep(10)
>
>
> And the output is:
>
> // the program is only running once here
> Try to commit transaction
> root is {'one': 'Thu Nov 26 11:37:53 2009'}
> Try to commit transaction
> root is {'one': 'Thu Nov 26 11:38:03 2009'}
> Try to commit transaction
> root is {'one': 'Thu Nov 26 11:38:13 2009'}
> Try to commit transaction
> root is {'one': 'Thu Nov 26 11:38:23 2009'}
> Try to commit transaction
> root is {'one': 'Thu Nov 26 11:38:33 2009'}
>
> // after I start a second copy, the first copy always has a conflict ( the
> second copy does not get this conflict error).
> Try to commit transaction
> we have a conflict
> Try to commit transaction
> root is {'one': 'Thu Nov 26 11:38:35 2009'}
> Try to commit transaction
> we have a conflict
> Try to commit transaction
> root is {'one': 'Thu Nov 26 11:38:46 2009'}
> Try to commit transaction
> we have a conflict
> Try to commit transaction
> root is {'one': 'Thu Nov 26 11:38:56 2009'}
> Try to commit transaction
> we have a conflict
>
> thanks,
> tom
>
>
>
> Laurence Rowe wrote:
>>
>> You must be prepared to abort and retry the whole transaction:
>>
>>    while True:
>>            while True:
>>                    try:
>>                            root[ "one" ] = time.asctime()
>>                            transaction.commit()
>>                    except POSException.ConflictError:
>>                            transaction.abort()
>>                            time.sleep(.2)
>>                    else:
>>                            break
>>
>>            time.sleep(10)
>>
>>
>> Laurence
>>
>> 2009/11/26 tsmiller :
>>>
>>> ZODB Developers,
>>>
>>> Can you please tell me what I am doing wrong in my first simple attempt
>>> to
>>> make use of ZEO.  My ZODB and ZEO are both the same version (3.6.0).
>>>
>>> First, I start my ZEO server and it looks like it starts properly:
>>>
>>> python2.4 /usr/lib/python2.4/site-packages/ZEO/runzeo.py -a
>>> localhost:9100
>>> -f /home/tom/zeo/test.fs
>>>
>>> --
>>> 2009-11-26T00:05:14 INFO ZEO.runzeo (8192) opening storage '1' using
>>> FileStorage
>>> --
>>> 2009-11-26T00:05:14 INFO ZEO.StorageServer (8192) StorageServer created
>>> RW
>>> with storages: 1:RW:/home/tom/zeo/test.fs
>>> --
>>> 2009-11-26T00:05:14 INFO ZEO.zrpc (8192) listening on ('localhost', 9100)
>>>
>>>
>>> Second, I start my client, twice.  The purpose is to write to the same
>>> test.fs file from both of them.  The idea is to loop continuously,
>>> writing
>>> to test.fs from each program.  If I only start the program once, it
>>> writes
>>> to test.fs fine.  But the first time it tries to commit a transaction
>>> after
>>> starting a second copy of the program, it always gives an error.
>>>
>>>    from ZEO import ClientStorage
>>>    from ZODB import DB
>>>    from ZODB import POSException
>>>    import transaction
>>>    import time
>>>
>>>    addr = 'localhost', 9100
>>>    storage = ClientStorage.ClientStorage( addr )
>>>    db = DB(storage)
>>>    conn = db.open()
>>>    root = conn.root()
>>>    while True:
>>>            root[ "one" ] = time.asctime()
>>>            while True:
>>>                    try:
>>>                            transaction.commit()
>>>                    except POSException.ConflictError:
>>>                            time.sleep(.2)
>>>                    else:
>>>                            break
>>>
>>>            time.sleep(10)
>>>
>>>
>>> The traceback folows. The conflict erro

Re: [ZODB-Dev] newbie ZEO first try. ConflictError.

2009-11-26 Thread tsmiller

Laurence,
Thank you for your very quick reply.  I did as you suggested and now the
ConflictError is now handled.  And that is a most excellent thing because
now ConflictError is raised every time.  So it still seems to be confused. 
I am trying to figure out if I will be able to use ZEO in my application.  

Now my program reads:

while True:
root[ "one" ] = time.asctime()
while True:
try:
print "Try to commit transaction"
transaction.commit()
print "root is",  root
except POSException.ConflictError:
print "we have a conflict"
transaction.abort()
time.sleep(.2)
else:
break

time.sleep(10)


And the output is:

// the program is only running once here
Try to commit transaction
root is {'one': 'Thu Nov 26 11:37:53 2009'}
Try to commit transaction
root is {'one': 'Thu Nov 26 11:38:03 2009'}
Try to commit transaction
root is {'one': 'Thu Nov 26 11:38:13 2009'}
Try to commit transaction
root is {'one': 'Thu Nov 26 11:38:23 2009'}
Try to commit transaction
root is {'one': 'Thu Nov 26 11:38:33 2009'}

// after I start a second copy, the first copy always has a conflict ( the
second copy does not get this conflict error).  
Try to commit transaction
we have a conflict
Try to commit transaction
root is {'one': 'Thu Nov 26 11:38:35 2009'}
Try to commit transaction
we have a conflict
Try to commit transaction
root is {'one': 'Thu Nov 26 11:38:46 2009'}
Try to commit transaction
we have a conflict
Try to commit transaction
root is {'one': 'Thu Nov 26 11:38:56 2009'}
Try to commit transaction
we have a conflict

thanks,
tom



Laurence Rowe wrote:
> 
> You must be prepared to abort and retry the whole transaction:
> 
>while True:
>while True:
>try:
>root[ "one" ] = time.asctime()
>transaction.commit()
>except POSException.ConflictError:
>transaction.abort()
>time.sleep(.2)
>else:
>break
> 
>time.sleep(10)
> 
> 
> Laurence
> 
> 2009/11/26 tsmiller :
>>
>> ZODB Developers,
>>
>> Can you please tell me what I am doing wrong in my first simple attempt
>> to
>> make use of ZEO.  My ZODB and ZEO are both the same version (3.6.0).
>>
>> First, I start my ZEO server and it looks like it starts properly:
>>
>> python2.4 /usr/lib/python2.4/site-packages/ZEO/runzeo.py -a
>> localhost:9100
>> -f /home/tom/zeo/test.fs
>>
>> --
>> 2009-11-26T00:05:14 INFO ZEO.runzeo (8192) opening storage '1' using
>> FileStorage
>> --
>> 2009-11-26T00:05:14 INFO ZEO.StorageServer (8192) StorageServer created
>> RW
>> with storages: 1:RW:/home/tom/zeo/test.fs
>> --
>> 2009-11-26T00:05:14 INFO ZEO.zrpc (8192) listening on ('localhost', 9100)
>>
>>
>> Second, I start my client, twice.  The purpose is to write to the same
>> test.fs file from both of them.  The idea is to loop continuously,
>> writing
>> to test.fs from each program.  If I only start the program once, it
>> writes
>> to test.fs fine.  But the first time it tries to commit a transaction
>> after
>> starting a second copy of the program, it always gives an error.
>>
>>    from ZEO import ClientStorage
>>    from ZODB import DB
>>    from ZODB import POSException
>>    import transaction
>>    import time
>>
>>    addr = 'localhost', 9100
>>    storage = ClientStorage.ClientStorage( addr )
>>    db = DB(storage)
>>    conn = db.open()
>>    root = conn.root()
>>    while True:
>>            root[ "one" ] = time.asctime()
>>            while True:
>>                    try:
>>                            transaction.commit()
>>                    except POSException.ConflictError:
>>                            time.sleep(.2)
>>                    else:
>>                            break
>>
>>            time.sleep(10)
>>
>>
>> The traceback folows. The conflict error is not handled and I don't know
>> why.    I am sure that I am missing something simple.
>>
>> we have a conflict
>> Traceback (most recent call last):
>>  File "zeotest.py", line 17, in ?
>>    transaction.commit()
>>  File "/usr/lib/python2.4/site-packages/transaction/_manager.py", line
>> 96,
>> in commit
>>    return self.get().commit(sub, deprecation_wng=False)
>>  File "/usr/lib/python2.4/site-packages/transaction/_transaction.py",
>> line
>> 370, in commit
>>    self._prior_operation_failed() # doesn't return
>>  File "/usr/lib/python2.4/site-packages/transaction/_transaction.py",
>> line
>> 250, in _prior_operation_failed
>>    raise TransactionFailedError("An operation previously failed, "
>> ZODB.POSException.TransactionFailedError: An operation previously failed,
>> with traceback:
>>
>>  File "zeotest.py", line 17, in ?
>>    transaction.commi

Re: [ZODB-Dev] newbie ZEO first try. ConflictError.

2009-11-26 Thread Laurence Rowe
You must be prepared to abort and retry the whole transaction:

   while True:
   while True:
   try:
   root[ "one" ] = time.asctime()
   transaction.commit()
   except POSException.ConflictError:
   transaction.abort()
   time.sleep(.2)
   else:
   break

   time.sleep(10)


Laurence

2009/11/26 tsmiller :
>
> ZODB Developers,
>
> Can you please tell me what I am doing wrong in my first simple attempt to
> make use of ZEO.  My ZODB and ZEO are both the same version (3.6.0).
>
> First, I start my ZEO server and it looks like it starts properly:
>
> python2.4 /usr/lib/python2.4/site-packages/ZEO/runzeo.py -a localhost:9100
> -f /home/tom/zeo/test.fs
>
> --
> 2009-11-26T00:05:14 INFO ZEO.runzeo (8192) opening storage '1' using
> FileStorage
> --
> 2009-11-26T00:05:14 INFO ZEO.StorageServer (8192) StorageServer created RW
> with storages: 1:RW:/home/tom/zeo/test.fs
> --
> 2009-11-26T00:05:14 INFO ZEO.zrpc (8192) listening on ('localhost', 9100)
>
>
> Second, I start my client, twice.  The purpose is to write to the same
> test.fs file from both of them.  The idea is to loop continuously, writing
> to test.fs from each program.  If I only start the program once, it writes
> to test.fs fine.  But the first time it tries to commit a transaction after
> starting a second copy of the program, it always gives an error.
>
>    from ZEO import ClientStorage
>    from ZODB import DB
>    from ZODB import POSException
>    import transaction
>    import time
>
>    addr = 'localhost', 9100
>    storage = ClientStorage.ClientStorage( addr )
>    db = DB(storage)
>    conn = db.open()
>    root = conn.root()
>    while True:
>            root[ "one" ] = time.asctime()
>            while True:
>                    try:
>                            transaction.commit()
>                    except POSException.ConflictError:
>                            time.sleep(.2)
>                    else:
>                            break
>
>            time.sleep(10)
>
>
> The traceback folows. The conflict error is not handled and I don't know
> why.    I am sure that I am missing something simple.
>
> we have a conflict
> Traceback (most recent call last):
>  File "zeotest.py", line 17, in ?
>    transaction.commit()
>  File "/usr/lib/python2.4/site-packages/transaction/_manager.py", line 96,
> in commit
>    return self.get().commit(sub, deprecation_wng=False)
>  File "/usr/lib/python2.4/site-packages/transaction/_transaction.py", line
> 370, in commit
>    self._prior_operation_failed() # doesn't return
>  File "/usr/lib/python2.4/site-packages/transaction/_transaction.py", line
> 250, in _prior_operation_failed
>    raise TransactionFailedError("An operation previously failed, "
> ZODB.POSException.TransactionFailedError: An operation previously failed,
> with traceback:
>
>  File "zeotest.py", line 17, in ?
>    transaction.commit()
>  File "/usr/lib/python2.4/site-packages/transaction/_manager.py", line 96,
> in commit
>    return self.get().commit(sub, deprecation_wng=False)
>  File "/usr/lib/python2.4/site-packages/transaction/_transaction.py", line
> 380, in commit
>    self._saveCommitishError() # This raises!
>  File "/usr/lib/python2.4/site-packages/transaction/_transaction.py", line
> 378, in commit
>    self._commitResources()
>  File "/usr/lib/python2.4/site-packages/transaction/_transaction.py", line
> 433, in _commitResources
>    rm.commit(self)
>  File "/usr/lib/python2.4/site-packages/ZODB/Connection.py", line 484, in
> commit
>    self._commit(transaction)
>  File "/usr/lib/python2.4/site-packages/ZODB/Connection.py", line 518, in
> _commit
>    raise ConflictError(object=obj)
> ConflictError: database conflict error (oid 0x00, class
> persistent.mapping.PersistentMapping)
>
>
> thanks,
>
> tom
>
>
> --
> View this message in context: 
> http://old.nabble.com/newbie-ZEO-first-try.--ConflictError.-tp26532984p26532984.html
> Sent from the Zope - ZODB-Dev mailing list archive at Nabble.com.
>
> ___
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>
> ZODB-Dev mailing list  -  zodb-...@zope.org
> https://mail.zope.org/mailman/listinfo/zodb-dev
>
___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev