{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/21754","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/21754/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/21754/comments","events_url":"https://api.github.com/repos/apache/spark/issues/21754/events","html_url":"https://github.com/apache/spark/pull/21754","id":340471216,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAwODc1MTI2","number":21754,"title":"[SPARK-24705][SQL] ExchangeCoordinator broken when duplicate exchanges reused","user":{"login":"maropu","id":692303,"node_id":"MDQ6VXNlcjY5MjMwMw==","avatar_url":"https://avatars3.githubusercontent.com/u/692303?v=4","gravatar_id":"","url":"https://api.github.com/users/maropu","html_url":"https://github.com/maropu","followers_url":"https://api.github.com/users/maropu/followers","following_url":"https://api.github.com/users/maropu/following{/other_user}","gists_url":"https://api.github.com/users/maropu/gists{/gist_id}","starred_url":"https://api.github.com/users/maropu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maropu/subscriptions","organizations_url":"https://api.github.com/users/maropu/orgs","repos_url":"https://api.github.com/users/maropu/repos","events_url":"https://api.github.com/users/maropu/events{/privacy}","received_events_url":"https://api.github.com/users/maropu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2018-07-12T02:53:11Z","updated_at":"2018-08-02T07:05:52Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/21754","html_url":"https://github.com/apache/spark/pull/21754","diff_url":"https://github.com/apache/spark/pull/21754.diff","patch_url":"https://github.com/apache/spark/pull/21754.patch"},"body":"## What changes were proposed in this pull request?\r\nIn the current master, `EnsureRequirements` sets the number of exchanges in `ExchangeCoordinator` before `ReuseExchange`. Then, `ReuseExchange` removes some duplicate exchange and the actual number of registered exchanges changes. Finally, the assertion in `ExchangeCoordinator` fails because the logical number of exchanges and the actual number of registered exchanges become different;\r\nhttps://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/ExchangeCoordinator.scala#L201\r\n\r\nThis pr fixed the issue and the code to reproduce this is as follows;\r\n```\r\nscala> sql(\"SET spark.sql.adaptive.enabled=true\")\r\nscala> sql(\"SET spark.sql.autoBroadcastJoinThreshold=-1\")\r\nscala> val df = spark.range(1).selectExpr(\"id AS key\", \"id AS value\")\r\nscala> val resultDf = df.join(df, \"key\").join(df, \"key\")\r\nscala> resultDf.show\r\n...\r\n  at org.apache.spark.sql.execution.exchange.ShuffleExchangeExec$$anonfun$doExecute$1.apply(ShuffleExchangeExec.scala:119)\r\n  at org.apache.spark.sql.catalyst.errors.package$.attachTree(package.scala:52)\r\n  ... 101 more\r\nCaused by: java.lang.AssertionError: assertion failed\r\n  at scala.Predef$.assert(Predef.scala:156)\r\n  at org.apache.spark.sql.execution.exchange.ExchangeCoordinator.doEstimationIfNecessary(ExchangeCoordinator.scala:201)\r\n  at org.apache.spark.sql.execution.exchange.ExchangeCoordinator.postShuffleRDD(ExchangeCoordinator.scala:259)\r\n  at org.apache.spark.sql.execution.exchange.ShuffleExchangeExec$$anonfun$doExecute$1.apply(ShuffleExchangeExec.scala:124)\r\n  at org.apache.spark.sql.execution.exchange.ShuffleExchangeExec$$anonfun$doExecute$1.apply(ShuffleExchangeExec.scala:119)\r\n  at org.apache.spark.sql.catalyst.errors.package$.attachTree(package.scala:52)\r\n...\r\n```\r\n\r\n## How was this patch tested?\r\nAdded tests in `ExchangeCoordinatorSuite`."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/409828041","html_url":"https://github.com/apache/spark/pull/21754#issuecomment-409828041","issue_url":"https://api.github.com/repos/apache/spark/issues/21754","id":409828041,"node_id":"MDEyOklzc3VlQ29tbWVudDQwOTgyODA0MQ==","user":{"login":"AmplabJenkins","id":4031291,"node_id":"MDQ6VXNlcjQwMzEyOTE=","avatar_url":"https://avatars3.githubusercontent.com/u/4031291?v=4","gravatar_id":"","url":"https://api.github.com/users/AmplabJenkins","html_url":"https://github.com/AmplabJenkins","followers_url":"https://api.github.com/users/AmplabJenkins/followers","following_url":"https://api.github.com/users/AmplabJenkins/following{/other_user}","gists_url":"https://api.github.com/users/AmplabJenkins/gists{/gist_id}","starred_url":"https://api.github.com/users/AmplabJenkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AmplabJenkins/subscriptions","organizations_url":"https://api.github.com/users/AmplabJenkins/orgs","repos_url":"https://api.github.com/users/AmplabJenkins/repos","events_url":"https://api.github.com/users/AmplabJenkins/events{/privacy}","received_events_url":"https://api.github.com/users/AmplabJenkins/received_events","type":"User","site_admin":false},"created_at":"2018-08-02T07:05:52Z","updated_at":"2018-08-02T07:05:52Z","author_association":"NONE","body":"Merged build finished. Test FAILed."}}
{"actor":{"display_login":"AmplabJenkins"}}