Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
aecf1bca
Commit
aecf1bca
authored
Dec 15, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d8fe835f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
10 deletions
+68
-10
lib/zodb.py
lib/zodb.py
+9
-4
zopenrace4.py
zopenrace4.py
+59
-6
No files found.
lib/zodb.py
View file @
aecf1bca
...
...
@@ -145,11 +145,16 @@ def _zversion():
dzodb
=
pkg_resources
.
working_set
.
find
(
pkg_resources
.
Requirement
.
parse
(
'ZODB'
))
v311
=
pkg_resources
.
parse_version
(
'3.11dev'
)
vzodb3
=
dzodb3
.
parsed_version
if
dzodb3
is
not
None
and
vzodb3
>=
v311
:
vzodb
=
dzodb
.
parsed_version
# ZODB 3.11 just requires latest ZODB & ZEO
if
dzodb3
is
None
and
dzodb
is
None
:
raise
RuntimeError
(
'ZODB is not installed'
)
if
dzodb3
is
not
None
:
if
dzodb3
.
parsed_version
>=
v311
:
vzodb
=
dzodb
.
parsed_version
# ZODB 3.11 just requires latest ZODB & ZEO
else
:
vzodb
=
dzodb3
.
parsed_version
else
:
vzodb
=
vzodb3
vzodb
=
dzodb
.
parsed_version
assert
vzodb
is
not
None
return
vzodb
...
...
zopenrace4.py
View file @
aecf1bca
...
...
@@ -8,6 +8,7 @@ from ZODB.MappingStorage import MappingStorage
import
transaction
from
persistent
import
Persistent
from
golang
import
func
,
defer
,
select
,
default
from
golang
import
sync
,
context
...
...
@@ -16,14 +17,41 @@ class PInt(Persistent):
def
__init__
(
self
,
i
):
self
.
i
=
i
from
wendelin.lib.testing
import
TestDB_ZEO
@
func
def
main
():
zstor
=
MappingStorage
()
db
=
DB
(
zstor
)
"""
if 0:
zstor = MappingStorage()
db = DB(zstor)
else:
tdb = TestDB_ZEO('<zeo>')
tdb.setup()
defer(tdb.teardown)
zstor = tdb.getZODBStorage()
db = DB(zstor)
#zstor.app.poll_thread.name = 'C.poll'
"""
tdb
=
TestDB_ZEO
(
'<zeo>'
)
tdb
.
setup
()
defer
(
tdb
.
teardown
)
def
dbopen
():
zstor
=
tdb
.
getZODBStorage
()
db
=
DB
(
zstor
)
return
db
# init initializes the database with two integer objects - obj1/obj2 that are set to 0.
@
func
def
init
():
db
=
dbopen
()
defer
(
db
.
close
)
transaction
.
begin
()
zconn
=
db
.
open
()
...
...
@@ -39,7 +67,11 @@ def main():
#
# access to obj1 is organized to always trigger loading from zstor.
# access to obj2 goes through zconn cache and so verifies whether the cache is not stale.
def
T1
(
ctx
,
N
):
@
func
def
T1
(
ctx
,
name
,
N
):
db
=
dbopen
()
defer
(
db
.
close
)
def
t1
():
transaction
.
begin
()
zconn
=
db
.
open
()
...
...
@@ -62,14 +94,20 @@ def main():
zconn
.
close
()
for
i
in
range
(
N
):
#print('T1
.%d' % i
)
#print('T1
%s.%d' % (name, i)
)
t1
()
raise
RuntimeError
(
"T1: done"
)
# T2 changes obj1/obj2 in a loop by doing `objX.i += 1`.
#
# Since both objects start from 0, the invariant that `obj1.i == obj2.i` is always preserved.
@
func
def
T2
(
ctx
,
N
):
db
=
dbopen
()
defer
(
db
.
close
)
def
t2
():
transaction
.
begin
()
zconn
=
db
.
open
()
...
...
@@ -85,6 +123,8 @@ def main():
zconn
.
close
()
for
i
in
range
(
N
):
if
ready
(
ctx
.
done
()):
break
#print('T2.%d' % i)
t2
()
...
...
@@ -93,12 +133,25 @@ def main():
# Connection.open, it triggers the bug where T1 sees stale obj2 with obj1.i != obj2.i
init
()
N
=
1000
N
=
1000
00
wg
=
sync
.
WorkGroup
(
context
.
background
())
wg
.
go
(
T1
,
N
)
for
x
in
'abcdefgh'
:
wg
.
go
(
T1
,
x
,
N
)
wg
.
go
(
T2
,
N
)
wg
.
wait
()
print
(
'OK'
)
# ready returns whether channel ch is ready.
def
ready
(
ch
):
_
,
_rx
=
select
(
default
,
# 0
ch
.
recv
,
# 1
)
if
_
==
0
:
return
False
return
True
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment