fixes inventory update deadlock

* all inventory updates continue to occur in parallel up to the point
that they update the database with their results.
* the "funnel" is achieved by using a global per-inventory postgres
named lock
This commit is contained in:
chris meyers
2019-03-27 16:35:16 -04:00
parent 196a6ff36c
commit cb4d55b47a

View File

@@ -41,6 +41,7 @@ from awx.main.utils import (
from awx.main.utils.common import _get_ansible_version from awx.main.utils.common import _get_ansible_version
from awx.main.signals import disable_activity_stream from awx.main.signals import disable_activity_stream
from awx.main.constants import STANDARD_INVENTORY_UPDATE_ENV from awx.main.constants import STANDARD_INVENTORY_UPDATE_ENV
from awx.main.utils.pglock import advisory_lock
logger = logging.getLogger('awx.main.commands.inventory_import') logger = logging.getLogger('awx.main.commands.inventory_import')
@@ -870,6 +871,7 @@ class Command(BaseCommand):
Load inventory from in-memory groups to the database, overwriting or Load inventory from in-memory groups to the database, overwriting or
merging as appropriate. merging as appropriate.
''' '''
with advisory_lock('inventory_{}_update'.format(self.inventory.id)):
# FIXME: Attribute changes to superuser? # FIXME: Attribute changes to superuser?
# Perform __in queries in batches (mainly for unit tests using SQLite). # Perform __in queries in batches (mainly for unit tests using SQLite).
self._batch_size = 500 self._batch_size = 500