[ZODB-Dev] Commit seems to succeed but does'nt
Cyril Elkaim
cyril.elkaim@free.fr
Wed, 26 Sep 2001 15:41:21 +0200
Hi Zopistas,
The following code brings us problems. If one of the two jobs must retry
its transaction.commit, this commit SEEMS to succed but, in fact, the
data is not saved on the disk. Has, someone, a clue of what happens there?
If QUANTITY is set at 100 or less there is no retry (depends of your
machine) and everything works as expected.
My problem is not the commit retry by itself it's the fact that I do a
commit that succeed and nothing is saved. I understand that ZODB can't
sustain an heavy load but in this case it should say "I can't".
Thanks in advance
Cyril Elkaim
# ======================================================================
from ZODB import DB
from ZODB.FileStorage import FileStorage
#from Persistence import Persistent
#from Session import Session
import time
import thread
QUANTITY = 1000
storage=FileStorage("/tmp/doldb")
db=DB(storage)
def job1():
print "Job 1 start"
cx = db.open()
root = cx.root()
get_transaction().begin()
for i in range(QUANTITY):
root["JobOne" + str(i)] = "JobOne" + str(i)
for a in root.values():
print a
c=3
while(c > 0):
try:
print "Commit 1: " + str(c)
get_transaction().commit()
print "Commit 1 Succeed"
break
except:
print "retry 1"
time.sleep(5)
c = c - 1
cx.close()
print "job1 end"
def job2():
print "job2 start"
cx = db.open()
root = cx.root()
get_transaction().begin()
for i in range(QUANTITY):
root["JobTwo" + str(i)] = "JobTwo" + str(i)
for a in root.values():
print a
c=3
while(c > 0):
try:
print "Commit 2: " + str(c)
get_transaction().commit()
print "Commit 2 Succeed"
break
except:
print "retry 2"
time.sleep(5)
c = c - 1
cx.close()
print("job2 end")
thread.start_new_thread(job1, ())
thread.start_new_thread(job2, ())
time.sleep(20)
print "main end"