Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mikolaï Krol
erp5
Commits
84451d42
Commit
84451d42
authored
Sep 29, 2017
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SQLCatalog: Use reserved_uid_lock as modular object instead of class attribute
parent
e46ade7a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
15 deletions
+10
-15
product/ERP5Catalog/tests/testERP5Catalog.py
product/ERP5Catalog/tests/testERP5Catalog.py
+2
-2
product/ZSQLCatalog/SQLCatalog.py
product/ZSQLCatalog/SQLCatalog.py
+8
-13
No files found.
product/ERP5Catalog/tests/testERP5Catalog.py
View file @
84451d42
...
@@ -349,14 +349,14 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
...
@@ -349,14 +349,14 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
portal_catalog
=
self
.
getCatalogTool
()
portal_catalog
=
self
.
getCatalogTool
()
catalog
=
portal_catalog
.
getSQLCatalog
()
catalog
=
portal_catalog
.
getSQLCatalog
()
self
.
assertTrue
(
catalog
is
not
None
)
self
.
assertTrue
(
catalog
is
not
None
)
from
Products.ZSQLCatalog.SQLCatalog
import
global_reserved_uid_lock
# Clear out the uid buffer.
# Clear out the uid buffer.
#from Products.ZSQLCatalog.SQLCatalog import uid_buffer_dict, get_ident
#from Products.ZSQLCatalog.SQLCatalog import uid_buffer_dict, get_ident
#uid_buffer_key = get_ident()
#uid_buffer_key = get_ident()
#if uid_buffer_key in uid_buffer_dict:
#if uid_buffer_key in uid_buffer_dict:
# del uid_buffer_dict[uid_buffer_key]
# del uid_buffer_dict[uid_buffer_key]
def
getUIDBuffer
(
*
args
,
**
kw
):
def
getUIDBuffer
(
*
args
,
**
kw
):
with
catalog
.
__class__
.
_reserved_uid_lock
:
with
global
_reserved_uid_lock
:
return
catalog
.
getUIDBuffer
(
*
args
,
**
kw
)
return
catalog
.
getUIDBuffer
(
*
args
,
**
kw
)
getUIDBuffer
(
force_new_buffer
=
True
)
getUIDBuffer
(
force_new_buffer
=
True
)
...
...
product/ZSQLCatalog/SQLCatalog.py
View file @
84451d42
...
@@ -155,6 +155,9 @@ manage_addSQLCatalogForm = DTMLFile('dtml/addSQLCatalog',globals())
...
@@ -155,6 +155,9 @@ manage_addSQLCatalogForm = DTMLFile('dtml/addSQLCatalog',globals())
# global_uid_buffer_dict[catalog_path][thread_id] = UidBuffer
# global_uid_buffer_dict[catalog_path][thread_id] = UidBuffer
global_uid_buffer_dict
=
{}
global_uid_buffer_dict
=
{}
# This is used for exclusive access to the list of reserved uids.
global_reserved_uid_lock
=
allocate_lock
()
def
manage_addSQLCatalog
(
self
,
id
,
title
,
def
manage_addSQLCatalog
(
self
,
id
,
title
,
vocab_id
=
'create_default_catalog_'
,
# vocab_id is a strange name - not abbreviation
vocab_id
=
'create_default_catalog_'
,
# vocab_id is a strange name - not abbreviation
REQUEST
=
None
):
REQUEST
=
None
):
...
@@ -636,8 +639,7 @@ class Catalog(Folder,
...
@@ -636,8 +639,7 @@ class Catalog(Folder,
# These are class variable on memory, so shared only by threads in the same Zope instance.
# These are class variable on memory, so shared only by threads in the same Zope instance.
# This is set to the time when reserved uids are cleared in this Zope instance.
# This is set to the time when reserved uids are cleared in this Zope instance.
_local_clear_reserved_time
=
None
_local_clear_reserved_time
=
None
# This is used for exclusive access to the list of reserved uids.
_reserved_uid_lock
=
allocate_lock
()
# This is an instance id which specifies who owns which reserved uids.
# This is an instance id which specifies who owns which reserved uids.
_instance_id
=
getattr
(
getConfiguration
(),
'instance_id'
,
None
)
_instance_id
=
getattr
(
getConfiguration
(),
'instance_id'
,
None
)
...
@@ -1204,7 +1206,7 @@ class Catalog(Folder,
...
@@ -1204,7 +1206,7 @@ class Catalog(Folder,
security
.
declarePrivate
(
'getUIDBuffer'
)
security
.
declarePrivate
(
'getUIDBuffer'
)
def
getUIDBuffer
(
self
,
force_new_buffer
=
False
):
def
getUIDBuffer
(
self
,
force_new_buffer
=
False
):
klass
=
self
.
__class__
klass
=
self
.
__class__
assert
klass
.
_reserved_uid_lock
.
locked
()
assert
global
_reserved_uid_lock
.
locked
()
assert
getattr
(
self
,
'aq_base'
,
None
)
is
not
None
assert
getattr
(
self
,
'aq_base'
,
None
)
is
not
None
instance_key
=
self
.
getPhysicalPath
()
instance_key
=
self
.
getPhysicalPath
()
if
instance_key
not
in
global_uid_buffer_dict
:
if
instance_key
not
in
global_uid_buffer_dict
:
...
@@ -1225,7 +1227,7 @@ class Catalog(Folder,
...
@@ -1225,7 +1227,7 @@ class Catalog(Folder,
Produces reserved uids in advance
Produces reserved uids in advance
"""
"""
klass
=
self
.
__class__
klass
=
self
.
__class__
assert
klass
.
_reserved_uid_lock
.
locked
()
assert
global
_reserved_uid_lock
.
locked
()
# This checks if the list of local reserved uids was cleared after clearReserved
# This checks if the list of local reserved uids was cleared after clearReserved
# had been called.
# had been called.
force_new_buffer
=
(
klass
.
_local_clear_reserved_time
!=
self
.
_last_clear_reserved_time
)
force_new_buffer
=
(
klass
.
_local_clear_reserved_time
!=
self
.
_last_clear_reserved_time
)
...
@@ -1317,8 +1319,7 @@ class Catalog(Folder,
...
@@ -1317,8 +1319,7 @@ class Catalog(Folder,
return
None
return
None
klass
=
self
.
__class__
klass
=
self
.
__class__
try
:
with
global_reserved_uid_lock
:
klass
.
_reserved_uid_lock
.
acquire
()
self
.
produceUid
()
self
.
produceUid
()
uid_buffer
=
self
.
getUIDBuffer
()
uid_buffer
=
self
.
getUIDBuffer
()
if
len
(
uid_buffer
)
>
0
:
if
len
(
uid_buffer
)
>
0
:
...
@@ -1330,8 +1331,6 @@ class Catalog(Folder,
...
@@ -1330,8 +1331,6 @@ class Catalog(Folder,
return
long
(
uid
)
return
long
(
uid
)
else
:
else
:
raise
CatalogError
(
"Could not retrieve new uid"
)
raise
CatalogError
(
"Could not retrieve new uid"
)
finally
:
klass
.
_reserved_uid_lock
.
release
()
security
.
declareProtected
(
manage_zcatalog_entries
,
'manage_catalogObject'
)
security
.
declareProtected
(
manage_zcatalog_entries
,
'manage_catalogObject'
)
def
manage_catalogObject
(
self
,
REQUEST
,
RESPONSE
,
URL1
,
urls
=
None
):
def
manage_catalogObject
(
self
,
REQUEST
,
RESPONSE
,
URL1
,
urls
=
None
):
...
@@ -1564,9 +1563,7 @@ class Catalog(Folder,
...
@@ -1564,9 +1563,7 @@ class Catalog(Folder,
#LOG('catalogObject', 0, 'uid = %r, catalog_path = %r' % (uid, catalog_path))
#LOG('catalogObject', 0, 'uid = %r, catalog_path = %r' % (uid, catalog_path))
if
catalog_path
==
"reserved"
:
if
catalog_path
==
"reserved"
:
# Reserved line in catalog table
# Reserved line in catalog table
lock
=
self
.
__class__
.
_reserved_uid_lock
with
global_reserved_uid_lock
:
try
:
lock
.
acquire
()
uid_buffer
=
self
.
getUIDBuffer
()
uid_buffer
=
self
.
getUIDBuffer
()
if
uid_buffer
is
not
None
:
if
uid_buffer
is
not
None
:
# This is the case where:
# This is the case where:
...
@@ -1581,8 +1578,6 @@ class Catalog(Folder,
...
@@ -1581,8 +1578,6 @@ class Catalog(Folder,
uid_buffer
.
remove
(
uid
)
uid_buffer
.
remove
(
uid
)
except
ValueError
:
except
ValueError
:
pass
pass
finally
:
lock
.
release
()
elif
catalog_path
==
'deleted'
:
elif
catalog_path
==
'deleted'
:
# Two possible cases:
# Two possible cases:
# - Reindexed object's path changed (ie, it or at least one of its
# - Reindexed object's path changed (ie, it or at least one of its
...
...
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