{"action":"created","comment":{"url":"https://api.github.com/repos/candlepin/candlepin/pulls/comments/24342003","id":24342003,"diff_hunk":"@@ -0,0 +1,101 @@\n+/**\n+ * Copyright (c) 2009 - 2012 Red Hat, Inc.\n+ *\n+ * This software is licensed to you under the GNU General Public License,\n+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or\n+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS\n+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2\n+ * along with this software; if not, see\n+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.\n+ *\n+ * Red Hat trademarks are not licensed under GPLv2. No permission is\n+ * granted to use or replicate Red Hat trademarks that are incorporated\n+ * in this software or its documentation.\n+ */\n+package org.candlepin.model;\n+\n+import org.hibernate.annotations.ForeignKey;\n+import org.hibernate.annotations.GenericGenerator;\n+import org.hibernate.annotations.Index;\n+\n+import java.util.Date;\n+\n+import javax.persistence.Column;\n+import javax.persistence.Entity;\n+import javax.persistence.GeneratedValue;\n+import javax.persistence.Id;\n+import javax.persistence.JoinColumn;\n+import javax.persistence.ManyToOne;\n+import javax.persistence.Table;\n+import javax.validation.constraints.NotNull;\n+import javax.xml.bind.annotation.XmlAccessType;\n+import javax.xml.bind.annotation.XmlAccessorType;\n+import javax.xml.bind.annotation.XmlRootElement;\n+\n+/**\n+ * Represents a consumer checkin time, created whenever a consumer auths with an identity\n+ * certificate. (as opposed to a password)\n+ *\n+ * Checkins are added to this table, with older entries cleaned out after some configurable\n+ * period of time. We're really only interested in the latest, but trying to update a\n+ * single column was a frequent cause of lock contention in heavily loaded environments.\n+ */\n+@XmlRootElement\n+@XmlAccessorType(XmlAccessType.PROPERTY)\n+@Entity\n+@Table(name = \"cp_consumer_checkin\")\n+public class CheckIn extends AbstractHibernateObject {\n+","path":"server/src/main/java/org/candlepin/model/CheckIn.java","position":48,"original_position":48,"commit_id":"11e31cc8cf8ab21381c7fe28865203058872704d","original_commit_id":"11e31cc8cf8ab21381c7fe28865203058872704d","user":{"login":"dgoodwin","id":51265,"avatar_url":"https://avatars.githubusercontent.com/u/51265?v=3","gravatar_id":"","url":"https://api.github.com/users/dgoodwin","html_url":"https://github.com/dgoodwin","followers_url":"https://api.github.com/users/dgoodwin/followers","following_url":"https://api.github.com/users/dgoodwin/following{/other_user}","gists_url":"https://api.github.com/users/dgoodwin/gists{/gist_id}","starred_url":"https://api.github.com/users/dgoodwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgoodwin/subscriptions","organizations_url":"https://api.github.com/users/dgoodwin/orgs","repos_url":"https://api.github.com/users/dgoodwin/repos","events_url":"https://api.github.com/users/dgoodwin/events{/privacy}","received_events_url":"https://api.github.com/users/dgoodwin/received_events","type":"User","site_admin":false},"body":"Hmm, next up will be something like GuestIdCheckIn, I could go either way, could consider CheckIn just the most common ConsumerCheckIn, or we could be more specific. Think we should go specific?","created_at":"2015-02-09T16:37:54Z","updated_at":"2015-02-09T16:37:54Z","html_url":"https://github.com/candlepin/candlepin/pull/825#discussion_r24342003","pull_request_url":"https://api.github.com/repos/candlepin/candlepin/pulls/825","_links":{"self":{"href":"https://api.github.com/repos/candlepin/candlepin/pulls/comments/24342003"},"html":{"href":"https://github.com/candlepin/candlepin/pull/825#discussion_r24342003"},"pull_request":{"href":"https://api.github.com/repos/candlepin/candlepin/pulls/825"}}},"pull_request":{"url":"https://api.github.com/repos/candlepin/candlepin/pulls/825","id":28822061,"html_url":"https://github.com/candlepin/candlepin/pull/825","diff_url":"https://github.com/candlepin/candlepin/pull/825.diff","patch_url":"https://github.com/candlepin/candlepin/pull/825.patch","issue_url":"https://api.github.com/repos/candlepin/candlepin/issues/825","number":825,"state":"open","locked":false,"title":"Eliminate Lock Contention on Consumer Last Check-In Time","user":{"login":"dgoodwin","id":51265,"avatar_url":"https://avatars.githubusercontent.com/u/51265?v=3","gravatar_id":"","url":"https://api.github.com/users/dgoodwin","html_url":"https://github.com/dgoodwin","followers_url":"https://api.github.com/users/dgoodwin/followers","following_url":"https://api.github.com/users/dgoodwin/following{/other_user}","gists_url":"https://api.github.com/users/dgoodwin/gists{/gist_id}","starred_url":"https://api.github.com/users/dgoodwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgoodwin/subscriptions","organizations_url":"https://api.github.com/users/dgoodwin/orgs","repos_url":"https://api.github.com/users/dgoodwin/repos","events_url":"https://api.github.com/users/dgoodwin/events{/privacy}","received_events_url":"https://api.github.com/users/dgoodwin/received_events","type":"User","site_admin":false},"body":"Problems surface in deployments with extremely high load. Because we update the consumer's row every time they authenticate, any request running long can cause other requests to wait longer than mysql's 50 second limit trying to get the lock to update that row.\r\n\r\nTo work around this I introduced a new table for consumer check-in times. The Consumer's last checkin time is calculated as the max in the table for that consumer.\r\n\r\nA job is included to run periodically (every 8 hours by default) and clean out all but the most recent row for each consumer. In a really big deployment, this could be well into the millions. Multiple attempts were made to delete all but the most recent row for each consumer, none would scale to that level and work on all dbs. Instead we query checkins to be deleted in batches and delete them one chunk (30k) at a time until there are none left.\r\n\r\nEnd result should eliminate lock wait timeouts on cp_consumer.lastcheckin because we're now doing fresh inserts in each request, rather than everyone trying to update the same row.","created_at":"2015-02-06T16:37:35Z","updated_at":"2015-02-09T16:37:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d53a8b15b28f214e278297f91170bcf24e4ab5a8","assignee":{"login":"wottop","id":1753002,"avatar_url":"https://avatars.githubusercontent.com/u/1753002?v=3","gravatar_id":"","url":"https://api.github.com/users/wottop","html_url":"https://github.com/wottop","followers_url":"https://api.github.com/users/wottop/followers","following_url":"https://api.github.com/users/wottop/following{/other_user}","gists_url":"https://api.github.com/users/wottop/gists{/gist_id}","starred_url":"https://api.github.com/users/wottop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wottop/subscriptions","organizations_url":"https://api.github.com/users/wottop/orgs","repos_url":"https://api.github.com/users/wottop/repos","events_url":"https://api.github.com/users/wottop/events{/privacy}","received_events_url":"https://api.github.com/users/wottop/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/candlepin/candlepin/pulls/825/commits","review_comments_url":"https://api.github.com/repos/candlepin/candlepin/pulls/825/comments","review_comment_url":"https://api.github.com/repos/candlepin/candlepin/pulls/comments/{number}","comments_url":"https://api.github.com/repos/candlepin/candlepin/issues/825/comments","statuses_url":"https://api.github.com/repos/candlepin/candlepin/statuses/11e31cc8cf8ab21381c7fe28865203058872704d","head":{"label":"candlepin:dgoodwin/consumer-checkin","ref":"dgoodwin/consumer-checkin","sha":"11e31cc8cf8ab21381c7fe28865203058872704d","user":{"login":"candlepin","id":1749632,"avatar_url":"https://avatars.githubusercontent.com/u/1749632?v=3","gravatar_id":"","url":"https://api.github.com/users/candlepin","html_url":"https://github.com/candlepin","followers_url":"https://api.github.com/users/candlepin/followers","following_url":"https://api.github.com/users/candlepin/following{/other_user}","gists_url":"https://api.github.com/users/candlepin/gists{/gist_id}","starred_url":"https://api.github.com/users/candlepin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/candlepin/subscriptions","organizations_url":"https://api.github.com/users/candlepin/orgs","repos_url":"https://api.github.com/users/candlepin/repos","events_url":"https://api.github.com/users/candlepin/events{/privacy}","received_events_url":"https://api.github.com/users/candlepin/received_events","type":"Organization","site_admin":false},"repo":{"id":4586516,"name":"candlepin","full_name":"candlepin/candlepin","owner":{"login":"candlepin","id":1749632,"avatar_url":"https://avatars.githubusercontent.com/u/1749632?v=3","gravatar_id":"","url":"https://api.github.com/users/candlepin","html_url":"https://github.com/candlepin","followers_url":"https://api.github.com/users/candlepin/followers","following_url":"https://api.github.com/users/candlepin/following{/other_user}","gists_url":"https://api.github.com/users/candlepin/gists{/gist_id}","starred_url":"https://api.github.com/users/candlepin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/candlepin/subscriptions","organizations_url":"https://api.github.com/users/candlepin/orgs","repos_url":"https://api.github.com/users/candlepin/repos","events_url":"https://api.github.com/users/candlepin/events{/privacy}","received_events_url":"https://api.github.com/users/candlepin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/candlepin/candlepin","description":"The Candlepin entitlement engine","fork":false,"url":"https://api.github.com/repos/candlepin/candlepin","forks_url":"https://api.github.com/repos/candlepin/candlepin/forks","keys_url":"https://api.github.com/repos/candlepin/candlepin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/candlepin/candlepin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/candlepin/candlepin/teams","hooks_url":"https://api.github.com/repos/candlepin/candlepin/hooks","issue_events_url":"https://api.github.com/repos/candlepin/candlepin/issues/events{/number}","events_url":"https://api.github.com/repos/candlepin/candlepin/events","assignees_url":"https://api.github.com/repos/candlepin/candlepin/assignees{/user}","branches_url":"https://api.github.com/repos/candlepin/candlepin/branches{/branch}","tags_url":"https://api.github.com/repos/candlepin/candlepin/tags","blobs_url":"https://api.github.com/repos/candlepin/candlepin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/candlepin/candlepin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/candlepin/candlepin/git/refs{/sha}","trees_url":"https://api.github.com/repos/candlepin/candlepin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/candlepin/candlepin/statuses/{sha}","languages_url":"https://api.github.com/repos/candlepin/candlepin/languages","stargazers_url":"https://api.github.com/repos/candlepin/candlepin/stargazers","contributors_url":"https://api.github.com/repos/candlepin/candlepin/contributors","subscribers_url":"https://api.github.com/repos/candlepin/candlepin/subscribers","subscription_url":"https://api.github.com/repos/candlepin/candlepin/subscription","commits_url":"https://api.github.com/repos/candlepin/candlepin/commits{/sha}","git_commits_url":"https://api.github.com/repos/candlepin/candlepin/git/commits{/sha}","comments_url":"https://api.github.com/repos/candlepin/candlepin/comments{/number}","issue_comment_url":"https://api.github.com/repos/candlepin/candlepin/issues/comments/{number}","contents_url":"https://api.github.com/repos/candlepin/candlepin/contents/{+path}","compare_url":"https://api.github.com/repos/candlepin/candlepin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/candlepin/candlepin/merges","archive_url":"https://api.github.com/repos/candlepin/candlepin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/candlepin/candlepin/downloads","issues_url":"https://api.github.com/repos/candlepin/candlepin/issues{/number}","pulls_url":"https://api.github.com/repos/candlepin/candlepin/pulls{/number}","milestones_url":"https://api.github.com/repos/candlepin/candlepin/milestones{/number}","notifications_url":"https://api.github.com/repos/candlepin/candlepin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/candlepin/candlepin/labels{/name}","releases_url":"https://api.github.com/repos/candlepin/candlepin/releases{/id}","created_at":"2012-06-07T14:58:35Z","updated_at":"2015-02-09T14:58:31Z","pushed_at":"2015-02-09T14:58:34Z","git_url":"git://github.com/candlepin/candlepin.git","ssh_url":"git@github.com:candlepin/candlepin.git","clone_url":"https://github.com/candlepin/candlepin.git","svn_url":"https://github.com/candlepin/candlepin","homepage":"http://candlepinproject.org","size":51385,"stargazers_count":24,"watchers_count":24,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":3,"forks":19,"open_issues":3,"watchers":24,"default_branch":"master"}},"base":{"label":"candlepin:master","ref":"master","sha":"023755cd11027e6953ef90da237dd831f6c9a3bb","user":{"login":"candlepin","id":1749632,"avatar_url":"https://avatars.githubusercontent.com/u/1749632?v=3","gravatar_id":"","url":"https://api.github.com/users/candlepin","html_url":"https://github.com/candlepin","followers_url":"https://api.github.com/users/candlepin/followers","following_url":"https://api.github.com/users/candlepin/following{/other_user}","gists_url":"https://api.github.com/users/candlepin/gists{/gist_id}","starred_url":"https://api.github.com/users/candlepin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/candlepin/subscriptions","organizations_url":"https://api.github.com/users/candlepin/orgs","repos_url":"https://api.github.com/users/candlepin/repos","events_url":"https://api.github.com/users/candlepin/events{/privacy}","received_events_url":"https://api.github.com/users/candlepin/received_events","type":"Organization","site_admin":false},"repo":{"id":4586516,"name":"candlepin","full_name":"candlepin/candlepin","owner":{"login":"candlepin","id":1749632,"avatar_url":"https://avatars.githubusercontent.com/u/1749632?v=3","gravatar_id":"","url":"https://api.github.com/users/candlepin","html_url":"https://github.com/candlepin","followers_url":"https://api.github.com/users/candlepin/followers","following_url":"https://api.github.com/users/candlepin/following{/other_user}","gists_url":"https://api.github.com/users/candlepin/gists{/gist_id}","starred_url":"https://api.github.com/users/candlepin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/candlepin/subscriptions","organizations_url":"https://api.github.com/users/candlepin/orgs","repos_url":"https://api.github.com/users/candlepin/repos","events_url":"https://api.github.com/users/candlepin/events{/privacy}","received_events_url":"https://api.github.com/users/candlepin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/candlepin/candlepin","description":"The Candlepin entitlement engine","fork":false,"url":"https://api.github.com/repos/candlepin/candlepin","forks_url":"https://api.github.com/repos/candlepin/candlepin/forks","keys_url":"https://api.github.com/repos/candlepin/candlepin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/candlepin/candlepin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/candlepin/candlepin/teams","hooks_url":"https://api.github.com/repos/candlepin/candlepin/hooks","issue_events_url":"https://api.github.com/repos/candlepin/candlepin/issues/events{/number}","events_url":"https://api.github.com/repos/candlepin/candlepin/events","assignees_url":"https://api.github.com/repos/candlepin/candlepin/assignees{/user}","branches_url":"https://api.github.com/repos/candlepin/candlepin/branches{/branch}","tags_url":"https://api.github.com/repos/candlepin/candlepin/tags","blobs_url":"https://api.github.com/repos/candlepin/candlepin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/candlepin/candlepin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/candlepin/candlepin/git/refs{/sha}","trees_url":"https://api.github.com/repos/candlepin/candlepin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/candlepin/candlepin/statuses/{sha}","languages_url":"https://api.github.com/repos/candlepin/candlepin/languages","stargazers_url":"https://api.github.com/repos/candlepin/candlepin/stargazers","contributors_url":"https://api.github.com/repos/candlepin/candlepin/contributors","subscribers_url":"https://api.github.com/repos/candlepin/candlepin/subscribers","subscription_url":"https://api.github.com/repos/candlepin/candlepin/subscription","commits_url":"https://api.github.com/repos/candlepin/candlepin/commits{/sha}","git_commits_url":"https://api.github.com/repos/candlepin/candlepin/git/commits{/sha}","comments_url":"https://api.github.com/repos/candlepin/candlepin/comments{/number}","issue_comment_url":"https://api.github.com/repos/candlepin/candlepin/issues/comments/{number}","contents_url":"https://api.github.com/repos/candlepin/candlepin/contents/{+path}","compare_url":"https://api.github.com/repos/candlepin/candlepin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/candlepin/candlepin/merges","archive_url":"https://api.github.com/repos/candlepin/candlepin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/candlepin/candlepin/downloads","issues_url":"https://api.github.com/repos/candlepin/candlepin/issues{/number}","pulls_url":"https://api.github.com/repos/candlepin/candlepin/pulls{/number}","milestones_url":"https://api.github.com/repos/candlepin/candlepin/milestones{/number}","notifications_url":"https://api.github.com/repos/candlepin/candlepin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/candlepin/candlepin/labels{/name}","releases_url":"https://api.github.com/repos/candlepin/candlepin/releases{/id}","created_at":"2012-06-07T14:58:35Z","updated_at":"2015-02-09T14:58:31Z","pushed_at":"2015-02-09T14:58:34Z","git_url":"git://github.com/candlepin/candlepin.git","ssh_url":"git@github.com:candlepin/candlepin.git","clone_url":"https://github.com/candlepin/candlepin.git","svn_url":"https://github.com/candlepin/candlepin","homepage":"http://candlepinproject.org","size":51385,"stargazers_count":24,"watchers_count":24,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":3,"forks":19,"open_issues":3,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/candlepin/candlepin/pulls/825"},"html":{"href":"https://github.com/candlepin/candlepin/pull/825"},"issue":{"href":"https://api.github.com/repos/candlepin/candlepin/issues/825"},"comments":{"href":"https://api.github.com/repos/candlepin/candlepin/issues/825/comments"},"review_comments":{"href":"https://api.github.com/repos/candlepin/candlepin/pulls/825/comments"},"review_comment":{"href":"https://api.github.com/repos/candlepin/candlepin/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/candlepin/candlepin/pulls/825/commits"},"statuses":{"href":"https://api.github.com/repos/candlepin/candlepin/statuses/11e31cc8cf8ab21381c7fe28865203058872704d"}}}}