{"action":"created","comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/23110935","id":23110935,"diff_hunk":"@@ -0,0 +1,20 @@\n+module NamingIndexMixin\n+  extend ActiveSupport::Concern\n+\n+  NAMING = 'naming'\n+\n+  included do\n+    has_many :naming_indexes, :as => :resource, :dependent => :destroy, :class_name => \"CustomAttribute\", :conditions => {:source => NAMING}\n+  end\n+\n+  def next_naming_index(name)\n+    with_lock do","path":"vmdb/app/models/mixins/naming_index_mixin.rb","position":11,"original_position":11,"commit_id":"d937d71e62232fdfa59da4a0edd664f9e9e25e0f","original_commit_id":"57117477684e4e5fa6694554d35efc88101607d8","user":{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false},"body":"First off, sorry for the length, but... @bzwei, @matthewd\r\n\r\n> Then why don't we switch to use with_lock, or at least stick with with_lock here?\r\n\r\nBecause with_timeout doesn't have the timeout and it doesn't have the simplicity of saying `:shared` or `:exclusive`.  The timeout is what makes our lock code \"safer\" (safer as in safety net).\r\n\r\nAdditionally, for me, the parameter on with_lock is confusing because the caller has to give a raw SQL string when they want to do a different kind of lock, and then the caller is responsible for SQL fragments, which is generally avoided.  Also, saying lock(true) is meaningless when reading the code.  What does a \"true\" lock mean?  For that matter what is a \"false\" lock? o_O  We felt that by providing :shared or :exclusive as the parameter and then let the lock method figure out the actual SQL it was clearer from the calling side.  This is what the ActiveRecordQueryParts module is for, as well as to support multiple databases like we used to in the past.  My long term goal was to push that part into Rails, but alas, I never got there.\r\n\r\n> The database should deal with deadlocks itself, so do we have situations where we do other potentially-slow things while holding a lock? Things that can be safely/usefully aborted?\r\n\r\nOpening a transaction, acquiring a lock, and then holding it forever is totally possible with with_lock.  Databases don't determine that to be a deadlock situation; it's a normal mutual exclusion setup, so the database will just stay in that state forever.  A deadlock is process X holds lock A, then asks for lock B, while process Y holds lock B and asks for lock A.  That isn't what's happening here.  Here we have process X holds lock A, then process Y asks for lock A and just waits in line.  So if you do something like `Account.first.with_lock { sleep(1.day) }` or `Account.first.with_lock { execute \"SELECT pg_sleep(seconds)\" }`, the database will hold that lock for a day, and you're just stuck.\r\n\r\nIn fairness, on the database configuration side you can set a parameter for the max lock holding time, but it's for the entire database.  I think ours is set for 10 minutes (maybe even more)...this is because an especially long query in reporting is technically valid, and is sometimes necessary (though we usually discourage it).  So, a client side timeout is useful when we know it should never take longer than some value, because it lets us limit a particular query in Ruby and not have it lock up the entire system (at least for the timeout length).\r\n\r\n> What's the history of the timeout?\r\n\r\nI searched the source history and found the timeout was added in the below commit in zone.rb, and was later extracted out to a mixin to be used on other models.\r\n\r\n```\r\ncommit cd9eca9469db13092287278966ca2c831a069d8b\r\nAuthor: Gregg Tanzillo <gtanzillo@manageiq.com>\r\nDate:   Wed Jun 17 00:35:34 2009 +0000\r\n\r\n    BugzID: 5033\r\n    -Removed all shared locks fro queue code because they were not necessary.\r\n    -Changed exclusive lock to shared lock in lock_in_my_zone because the exclusive locking was excessive.\r\n    -Added a 60 timeout around block in lock_in_my_zone to prevent blocking other processes when the execution does not return.\r\n```\r\nASIDE: ping @gtanzillo (hi!)\r\n\r\nUnfortunately, the trail ends there and I can't find more info on the issue that was in question.  My guess is something went crazy, the lock was held for an inordinate amount of time and locked up the entire system.  These locks are heavily used on startup when the database needs to seed, where multiple workers are trying to seed the system.  If one locks up permanently, the system effectively never starts.\r\n\r\n> lying debug message\r\n\r\nIs it?  How so?","created_at":"2015-01-16T21:32:01Z","updated_at":"2015-01-16T21:32:01Z","html_url":"https://github.com/ManageIQ/manageiq/pull/1387#discussion_r23110935","pull_request_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/1387","_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/23110935"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/1387#discussion_r23110935"},"pull_request":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/1387"}}},"pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/1387","id":27447169,"html_url":"https://github.com/ManageIQ/manageiq/pull/1387","diff_url":"https://github.com/ManageIQ/manageiq/pull/1387.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/1387.patch","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/1387","number":1387,"state":"open","locked":false,"title":"Store next naming index in custom_attributes","user":{"login":"bzwei","id":7047579,"avatar_url":"https://avatars.githubusercontent.com/u/7047579?v=3","gravatar_id":"","url":"https://api.github.com/users/bzwei","html_url":"https://github.com/bzwei","followers_url":"https://api.github.com/users/bzwei/followers","following_url":"https://api.github.com/users/bzwei/following{/other_user}","gists_url":"https://api.github.com/users/bzwei/gists{/gist_id}","starred_url":"https://api.github.com/users/bzwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bzwei/subscriptions","organizations_url":"https://api.github.com/users/bzwei/orgs","repos_url":"https://api.github.com/users/bzwei/repos","events_url":"https://api.github.com/users/bzwei/events{/privacy}","received_events_url":"https://api.github.com/users/bzwei/received_events","type":"User","site_admin":false},"body":"With this implemenation naming indexes are global through current region.\r\nThe binding can be changed to other models through NamingIndexMixin.\r\n\r\nhttps://bugzilla.redhat.com/show_bug.cgi?id=1173336","created_at":"2015-01-15T17:42:24Z","updated_at":"2015-01-16T21:32:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"33903c2791e4c1c0160f4da7fc116ed3373fe00c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/1387/commits","review_comments_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/1387/comments","review_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/1387/comments","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/d937d71e62232fdfa59da4a0edd664f9e9e25e0f","head":{"label":"bzwei:naming_racing","ref":"naming_racing","sha":"d937d71e62232fdfa59da4a0edd664f9e9e25e0f","user":{"login":"bzwei","id":7047579,"avatar_url":"https://avatars.githubusercontent.com/u/7047579?v=3","gravatar_id":"","url":"https://api.github.com/users/bzwei","html_url":"https://github.com/bzwei","followers_url":"https://api.github.com/users/bzwei/followers","following_url":"https://api.github.com/users/bzwei/following{/other_user}","gists_url":"https://api.github.com/users/bzwei/gists{/gist_id}","starred_url":"https://api.github.com/users/bzwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bzwei/subscriptions","organizations_url":"https://api.github.com/users/bzwei/orgs","repos_url":"https://api.github.com/users/bzwei/repos","events_url":"https://api.github.com/users/bzwei/events{/privacy}","received_events_url":"https://api.github.com/users/bzwei/received_events","type":"User","site_admin":false},"repo":{"id":20813025,"name":"manageiq","full_name":"bzwei/manageiq","owner":{"login":"bzwei","id":7047579,"avatar_url":"https://avatars.githubusercontent.com/u/7047579?v=3","gravatar_id":"","url":"https://api.github.com/users/bzwei","html_url":"https://github.com/bzwei","followers_url":"https://api.github.com/users/bzwei/followers","following_url":"https://api.github.com/users/bzwei/following{/other_user}","gists_url":"https://api.github.com/users/bzwei/gists{/gist_id}","starred_url":"https://api.github.com/users/bzwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bzwei/subscriptions","organizations_url":"https://api.github.com/users/bzwei/orgs","repos_url":"https://api.github.com/users/bzwei/repos","events_url":"https://api.github.com/users/bzwei/events{/privacy}","received_events_url":"https://api.github.com/users/bzwei/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bzwei/manageiq","description":"ManageIQ Cloud Management Platform","fork":true,"url":"https://api.github.com/repos/bzwei/manageiq","forks_url":"https://api.github.com/repos/bzwei/manageiq/forks","keys_url":"https://api.github.com/repos/bzwei/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bzwei/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bzwei/manageiq/teams","hooks_url":"https://api.github.com/repos/bzwei/manageiq/hooks","issue_events_url":"https://api.github.com/repos/bzwei/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/bzwei/manageiq/events","assignees_url":"https://api.github.com/repos/bzwei/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/bzwei/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/bzwei/manageiq/tags","blobs_url":"https://api.github.com/repos/bzwei/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bzwei/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bzwei/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/bzwei/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bzwei/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/bzwei/manageiq/languages","stargazers_url":"https://api.github.com/repos/bzwei/manageiq/stargazers","contributors_url":"https://api.github.com/repos/bzwei/manageiq/contributors","subscribers_url":"https://api.github.com/repos/bzwei/manageiq/subscribers","subscription_url":"https://api.github.com/repos/bzwei/manageiq/subscription","commits_url":"https://api.github.com/repos/bzwei/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/bzwei/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/bzwei/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/bzwei/manageiq/issues/comments/{number}","contents_url":"https://api.github.com/repos/bzwei/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/bzwei/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bzwei/manageiq/merges","archive_url":"https://api.github.com/repos/bzwei/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bzwei/manageiq/downloads","issues_url":"https://api.github.com/repos/bzwei/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/bzwei/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/bzwei/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/bzwei/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bzwei/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/bzwei/manageiq/releases{/id}","created_at":"2014-06-13T18:02:48Z","updated_at":"2014-06-24T18:52:43Z","pushed_at":"2015-01-16T16:33:59Z","git_url":"git://github.com/bzwei/manageiq.git","ssh_url":"git@github.com:bzwei/manageiq.git","clone_url":"https://github.com/bzwei/manageiq.git","svn_url":"https://github.com/bzwei/manageiq","homepage":null,"size":61057,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ManageIQ:master","ref":"master","sha":"8db75872df0beb8893957154c9d7e4cfb23c1cbf","user":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"repo":{"id":20789757,"name":"manageiq","full_name":"ManageIQ/manageiq","owner":{"login":"ManageIQ","id":1125575,"avatar_url":"https://avatars.githubusercontent.com/u/1125575?v=3","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ManageIQ/manageiq","description":"ManageIQ Cloud Management Platform","fork":false,"url":"https://api.github.com/repos/ManageIQ/manageiq","forks_url":"https://api.github.com/repos/ManageIQ/manageiq/forks","keys_url":"https://api.github.com/repos/ManageIQ/manageiq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ManageIQ/manageiq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ManageIQ/manageiq/teams","hooks_url":"https://api.github.com/repos/ManageIQ/manageiq/hooks","issue_events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/events{/number}","events_url":"https://api.github.com/repos/ManageIQ/manageiq/events","assignees_url":"https://api.github.com/repos/ManageIQ/manageiq/assignees{/user}","branches_url":"https://api.github.com/repos/ManageIQ/manageiq/branches{/branch}","tags_url":"https://api.github.com/repos/ManageIQ/manageiq/tags","blobs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ManageIQ/manageiq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ManageIQ/manageiq/git/refs{/sha}","trees_url":"https://api.github.com/repos/ManageIQ/manageiq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ManageIQ/manageiq/statuses/{sha}","languages_url":"https://api.github.com/repos/ManageIQ/manageiq/languages","stargazers_url":"https://api.github.com/repos/ManageIQ/manageiq/stargazers","contributors_url":"https://api.github.com/repos/ManageIQ/manageiq/contributors","subscribers_url":"https://api.github.com/repos/ManageIQ/manageiq/subscribers","subscription_url":"https://api.github.com/repos/ManageIQ/manageiq/subscription","commits_url":"https://api.github.com/repos/ManageIQ/manageiq/commits{/sha}","git_commits_url":"https://api.github.com/repos/ManageIQ/manageiq/git/commits{/sha}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/comments{/number}","issue_comment_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments/{number}","contents_url":"https://api.github.com/repos/ManageIQ/manageiq/contents/{+path}","compare_url":"https://api.github.com/repos/ManageIQ/manageiq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ManageIQ/manageiq/merges","archive_url":"https://api.github.com/repos/ManageIQ/manageiq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ManageIQ/manageiq/downloads","issues_url":"https://api.github.com/repos/ManageIQ/manageiq/issues{/number}","pulls_url":"https://api.github.com/repos/ManageIQ/manageiq/pulls{/number}","milestones_url":"https://api.github.com/repos/ManageIQ/manageiq/milestones{/number}","notifications_url":"https://api.github.com/repos/ManageIQ/manageiq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/labels{/name}","releases_url":"https://api.github.com/repos/ManageIQ/manageiq/releases{/id}","created_at":"2014-06-13T02:31:26Z","updated_at":"2015-01-16T21:11:48Z","pushed_at":"2015-01-16T21:11:48Z","git_url":"git://github.com/ManageIQ/manageiq.git","ssh_url":"git@github.com:ManageIQ/manageiq.git","clone_url":"https://github.com/ManageIQ/manageiq.git","svn_url":"https://github.com/ManageIQ/manageiq","homepage":"manageiq.org","size":85083,"stargazers_count":78,"watchers_count":78,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":81,"mirror_url":null,"open_issues_count":223,"forks":81,"open_issues":223,"watchers":78,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/1387"},"html":{"href":"https://github.com/ManageIQ/manageiq/pull/1387"},"issue":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/1387"},"comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/issues/1387/comments"},"review_comments":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/1387/comments"},"review_comment":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ManageIQ/manageiq/pulls/1387/commits"},"statuses":{"href":"https://api.github.com/repos/ManageIQ/manageiq/statuses/d937d71e62232fdfa59da4a0edd664f9e9e25e0f"}}}}