Commit 9d8b5394 authored by Tim Peters's avatar Tim Peters

_PackWhileWriting() and class ClientThread: Dumping in some prints showed

that the first thread to launch managed to commit each time, while the
other 3 threads got nothing but conflict errors.  Added some randomization
to boost the odds of success, and to prevent systematic favoring of any
thread.  That appears to work.
parent a441cc72
...@@ -398,12 +398,13 @@ class PackableStorage(PackableStorageBase): ...@@ -398,12 +398,13 @@ class PackableStorage(PackableStorageBase):
snooze() snooze()
packt = time.time() packt = time.time()
for j in range(10): choices = range(10)
for i in range(10): for dummy in choices:
for i in choices:
root[i].value = MinPO(i) root[i].value = MinPO(i)
get_transaction().commit() get_transaction().commit()
threads = [ClientThread(db) for i in range(4)] threads = [ClientThread(db, choices) for i in range(4)]
for t in threads: for t in threads:
t.start() t.start()
...@@ -504,16 +505,20 @@ class PackableStorage(PackableStorageBase): ...@@ -504,16 +505,20 @@ class PackableStorage(PackableStorageBase):
for r in self._storage.undoLog(): print r for r in self._storage.undoLog(): print r
# what can we assert about that? # what can we assert about that?
class ClientThread(threading.Thread): class ClientThread(threading.Thread):
def __init__(self, db): def __init__(self, db, choices):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.root = db.open().root() self.root = db.open().root()
self.choices = choices
def run(self): def run(self):
from random import choice
for j in range(50): for j in range(50):
try: try:
self.root[j % 10].value = MinPO(j) self.root[choice(self.choices)].value = MinPO(j)
get_transaction().commit() get_transaction().commit()
except ConflictError: except ConflictError:
get_transaction().abort() get_transaction().abort()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment