Bug 1344709

Summary: Database deadlock when creating multiple hosts in parallel
Product: Red Hat Satellite Reporter: Lukas Zapletal <lzap>
Component: HostsAssignee: Chris Duryee <cduryee>
Status: CLOSED DUPLICATE QA Contact:
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.2.0CC: bbuckingham, cwelton, jhutar
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-06-15 17:40:06 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Lukas Zapletal 2016-06-10 12:38:53 UTC
Reproducer:

Create several processes that create content hosts (hammer host create) in parallel.

2016-06-10 10:58:53 CEST ERROR:  deadlock detected
2016-06-10 10:58:53 CEST DETAIL:  Process 19805 waits for ShareLock on transaction 1661291; blocked  +by process 24817.
        Process 24817 waits for ExclusiveLock on tuple (0,24) of relation 18010 of database 17659;   +blocked by process 19805.
        Process 19805: UPDATE "hostgroups" SET "hosts_count" = COALESCE("hosts_count", 0) + 1 WHERE  +"hostgroups"."id" = 2
        Process 24817: UPDATE "hostgroups" SET "hosts_count" = COALESCE("hosts_count", 0) + 1 WHERE  +"hostgroups"."id" = 2
2016-06-10 10:58:53 CEST HINT:  See server log for query details.
2016-06-10 10:58:53 CEST STATEMENT:  UPDATE "hostgroups" SET "hosts_count" = COALESCE("hosts_count", +0) + 1 WHERE "hostgroups"."id" = 2

2016-06-10 10:58:53 CEST ERROR:  deadlock detected
2016-06-10 10:58:53 CEST DETAIL:  Process 19784 waits for ShareLock on transaction 1661291; blocked  +by process 24817.
        Process 24817 waits for ExclusiveLock on tuple (0,59) of relation 17911 of database 17659;   +blocked by process 19784.
        Process 19784: UPDATE "operatingsystems" SET "hosts_count" = COALESCE("hosts_count", 0) - 1  +WHERE "operatingsystems"."id" = 4
        Process 24817: UPDATE "operatingsystems" SET "hosts_count" = COALESCE("hosts_count", 0) + 1  +WHERE "operatingsystems"."type" IN ('Redhat') AND "operatingsystems"."id" = 4
2016-06-10 10:58:53 CEST HINT:  See server log for query details.
2016-06-10 10:58:53 CEST STATEMENT:  UPDATE "operatingsystems" SET "hosts_count" =                   +COALESCE("hosts_count", 0) - 1 WHERE "operatingsystems"."id" = 4

Looks like this is related:

http://projects.theforeman.org/issues/10133

# rpm -q satellite katello foreman
satellite-6.2.0-14.2.el7sat.noarch
katello-3.0.0-6.el7sat.noarch
foreman-1.11.0.34-1.el7sat.noarch

Debug tarball (Foreman core team permissions needed to download it):
http://debugs.theforeman.org/foreman-debug-0Qsen.tar.xz

I am able to randomly reproduce on my own box, takes hours to hit with about 100 clients registering.

Comment 1 Lukas Zapletal 2016-06-10 12:44:47 UTC
Note: You may need to configure PassengerMinInstances 2 in /etc/httpd/conf.d/05-foreman-ssl.conf in order to have at least two processes that interfere each other.

Comment 4 Chris Duryee 2016-06-15 17:40:06 UTC
I believe this is the same as 1341338. There are a couple of related queries that rely on the same rails locking mechanisms.

*** This bug has been marked as a duplicate of bug 1341338 ***