Commit fa9897db authored by Vincent Pelletier's avatar Vincent Pelletier

Use portal_ids (if available) to generate catalog uids.

This is done to allow removing AUTOINCREMENT property of catalog's uid column, which causes table-level locks on innodb, which badly impairs indexation speed especialy when using multiple indexation nodes. If AUTOINCREMENT is kept on catalog, the system keeps working but the table-level lock will still be held (unless you use MySQL 2.1.22 or higher, which is not advised since at the moment it's a development branch).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16688 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8d3d26b2
......@@ -1245,17 +1245,28 @@ class Catalog( Folder,
elif getattr(self, '_v_uid_buffer', None) is None:
self._v_uid_buffer = UidBuffer()
if len(self._v_uid_buffer) == 0:
method_id = self.sql_catalog_produce_reserved
method = getattr(self, method_id)
# Generate an instance id randomly. Note that there is a small possibility that this
# would conflict with others.
random_factor_list = [time.time(), os.getpid(), os.times()]
try:
random_factor_list.append(os.getloadavg())
except (OSError, AttributeError): # AttributeError is required under cygwin
pass
instance_id = md5.new(str(random_factor_list)).hexdigest()
uid_list = [x.uid for x in method(count = UID_BUFFER_SIZE, instance_id = instance_id) if x.uid != 0]
id_tool = getattr(self.getPortalObject(), 'portal_ids', None)
if id_tool is not None:
if self._max_uid is None:
self._max_uid = Length()
uid_list = id_tool.generateNewLengthIdList(id_group='catalog_uid',
id_count=UID_BUFFER_SIZE, default=self._max_uid())
# TODO: if this method is kept and former uid allocation code is
# discarded, self._max_uid duplicates work done by portal_ids: it
# already keeps track of the highest allocated number for all id
# generator groups.
else:
method_id = self.sql_catalog_produce_reserved
method = getattr(self, method_id)
# Generate an instance id randomly. Note that there is a small possibility that this
# would conflict with others.
random_factor_list = [time.time(), os.getpid(), os.times()]
try:
random_factor_list.append(os.getloadavg())
except (OSError, AttributeError): # AttributeError is required under cygwin
pass
instance_id = md5.new(str(random_factor_list)).hexdigest()
uid_list = [x.uid for x in method(count = UID_BUFFER_SIZE, instance_id = instance_id) if x.uid != 0]
self._v_uid_buffer.extend(uid_list)
def isIndexable(self):
......
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