{"action":"created","issue":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/24885","repository_url":"https://api.github.com/repos/cockroachdb/cockroach","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/24885/labels{/name}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/24885/comments","events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/24885/events","html_url":"https://github.com/cockroachdb/cockroach/issues/24885","id":315223925,"node_id":"MDU6SXNzdWUzMTUyMjM5MjU=","number":24885,"title":"sql: rollback to savepoint after schema change can lead to deadlock","user":{"login":"andreimatei","id":377201,"node_id":"MDQ6VXNlcjM3NzIwMQ==","avatar_url":"https://avatars1.githubusercontent.com/u/377201?v=4","gravatar_id":"","url":"https://api.github.com/users/andreimatei","html_url":"https://github.com/andreimatei","followers_url":"https://api.github.com/users/andreimatei/followers","following_url":"https://api.github.com/users/andreimatei/following{/other_user}","gists_url":"https://api.github.com/users/andreimatei/gists{/gist_id}","starred_url":"https://api.github.com/users/andreimatei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreimatei/subscriptions","organizations_url":"https://api.github.com/users/andreimatei/orgs","repos_url":"https://api.github.com/users/andreimatei/repos","events_url":"https://api.github.com/users/andreimatei/events{/privacy}","received_events_url":"https://api.github.com/users/andreimatei/received_events","type":"User","site_admin":false},"labels":[{"id":1002858167,"node_id":"MDU6TGFiZWwxMDAyODU4MTY3","url":"https://api.github.com/repos/cockroachdb/cockroach/labels/A-schema-changes","name":"A-schema-changes","color":"22c97b","default":false},{"id":78928345,"node_id":"MDU6TGFiZWw3ODkyODM0NQ==","url":"https://api.github.com/repos/cockroachdb/cockroach/labels/C-bug","name":"C-bug","color":"c5def5","default":false}],"state":"open","locked":false,"assignee":{"login":"vivekmenezes","id":11774212,"node_id":"MDQ6VXNlcjExNzc0MjEy","avatar_url":"https://avatars1.githubusercontent.com/u/11774212?v=4","gravatar_id":"","url":"https://api.github.com/users/vivekmenezes","html_url":"https://github.com/vivekmenezes","followers_url":"https://api.github.com/users/vivekmenezes/followers","following_url":"https://api.github.com/users/vivekmenezes/following{/other_user}","gists_url":"https://api.github.com/users/vivekmenezes/gists{/gist_id}","starred_url":"https://api.github.com/users/vivekmenezes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vivekmenezes/subscriptions","organizations_url":"https://api.github.com/users/vivekmenezes/orgs","repos_url":"https://api.github.com/users/vivekmenezes/repos","events_url":"https://api.github.com/users/vivekmenezes/events{/privacy}","received_events_url":"https://api.github.com/users/vivekmenezes/received_events","type":"User","site_admin":false},"assignees":[{"login":"vivekmenezes","id":11774212,"node_id":"MDQ6VXNlcjExNzc0MjEy","avatar_url":"https://avatars1.githubusercontent.com/u/11774212?v=4","gravatar_id":"","url":"https://api.github.com/users/vivekmenezes","html_url":"https://github.com/vivekmenezes","followers_url":"https://api.github.com/users/vivekmenezes/followers","following_url":"https://api.github.com/users/vivekmenezes/following{/other_user}","gists_url":"https://api.github.com/users/vivekmenezes/gists{/gist_id}","starred_url":"https://api.github.com/users/vivekmenezes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vivekmenezes/subscriptions","organizations_url":"https://api.github.com/users/vivekmenezes/orgs","repos_url":"https://api.github.com/users/vivekmenezes/repos","events_url":"https://api.github.com/users/vivekmenezes/events{/privacy}","received_events_url":"https://api.github.com/users/vivekmenezes/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/cockroachdb/cockroach/milestones/13","html_url":"https://github.com/cockroachdb/cockroach/milestone/13","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones/13/labels","id":2745639,"node_id":"MDk6TWlsZXN0b25lMjc0NTYzOQ==","number":13,"title":"2.1","description":"","creator":{"login":"knz","id":642886,"node_id":"MDQ6VXNlcjY0Mjg4Ng==","avatar_url":"https://avatars3.githubusercontent.com/u/642886?v=4","gravatar_id":"","url":"https://api.github.com/users/knz","html_url":"https://github.com/knz","followers_url":"https://api.github.com/users/knz/followers","following_url":"https://api.github.com/users/knz/following{/other_user}","gists_url":"https://api.github.com/users/knz/gists{/gist_id}","starred_url":"https://api.github.com/users/knz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knz/subscriptions","organizations_url":"https://api.github.com/users/knz/orgs","repos_url":"https://api.github.com/users/knz/repos","events_url":"https://api.github.com/users/knz/events{/privacy}","received_events_url":"https://api.github.com/users/knz/received_events","type":"User","site_admin":false},"open_issues":622,"closed_issues":1353,"state":"open","created_at":"2017-09-05T15:30:49Z","updated_at":"2018-08-21T16:05:40Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2018-04-17T20:31:09Z","updated_at":"2018-08-21T16:32:28Z","closed_at":null,"author_association":"MEMBER","body":"The following deadlocks:\r\n```\r\nbegin; savepoint cockroach_restart; create table t(x int); rollback to savepoint cockroach_restart;\r\nselect * from t;\r\n```\r\nThe reason why it deadlocks is that the create left an intent on something (probably a table name record); the intent will never commit because txn's epoch is incremented by the rollback to savepoint, but it still exists. The select then tries to resolve that name in order to get a lease on that table - and that name resolution process uses a different txn which gets blocked on the intent.\r\nFunny enough, if you do another `create` after the rollback, that works - probably because all reads/writes are done using the main txn in that case.\r\n\r\nFound while investigating #24785\r\n\r\nOne way to fix this is for transactions that perform schema changes to employ a policy that says that they don't get to keep intents from old epochs - or rather, whenever we would bump the epoch, we'd create a new txn instead. This would mean that they don't get to benefit from the \"reservation\" effect of leaving intents around, but who cares. The moral justification is that these transactions touched \"special\" keys.\r\nAnother way is to do all lease acquisitions and name resolution and such by using the transaction running the statement that caused the lease. But I don't like that at all; it goes against divorcing the table descriptor caching layer from SQL transactions which I think is generally a great thing.\r\n\r\nOpinions?\r\n\r\ncc @vivekmenezes @bdarnell "},"comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments/414738030","html_url":"https://github.com/cockroachdb/cockroach/issues/24885#issuecomment-414738030","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/24885","id":414738030,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNDczODAzMA==","user":{"login":"vivekmenezes","id":11774212,"node_id":"MDQ6VXNlcjExNzc0MjEy","avatar_url":"https://avatars1.githubusercontent.com/u/11774212?v=4","gravatar_id":"","url":"https://api.github.com/users/vivekmenezes","html_url":"https://github.com/vivekmenezes","followers_url":"https://api.github.com/users/vivekmenezes/followers","following_url":"https://api.github.com/users/vivekmenezes/following{/other_user}","gists_url":"https://api.github.com/users/vivekmenezes/gists{/gist_id}","starred_url":"https://api.github.com/users/vivekmenezes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vivekmenezes/subscriptions","organizations_url":"https://api.github.com/users/vivekmenezes/orgs","repos_url":"https://api.github.com/users/vivekmenezes/repos","events_url":"https://api.github.com/users/vivekmenezes/events{/privacy}","received_events_url":"https://api.github.com/users/vivekmenezes/received_events","type":"User","site_admin":false},"created_at":"2018-08-21T16:32:28Z","updated_at":"2018-08-21T16:32:28Z","author_association":"CONTRIBUTOR","body":"@andreimatei I've not studied this issue. It is my intention to move all schema change writes to commit time, which will also fix https://github.com/cockroachdb/cockroach/issues/20526\r\n\r\nI've been holding off on that because of the worry about leases that keep renewing themselves pushing the schema change writer. But I do plan on doing that as soon as epoch based table leases is merged, because epoch based table leases is going to considerably reduce the read demands on the table descriptors\r\n"}}
{"actor":{"display_login":"vivekmenezes"}}