{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/11455","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/11455/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/11455/comments","events_url":"https://api.github.com/repos/apache/spark/issues/11455/events","html_url":"https://github.com/apache/spark/pull/11455","id":137736269,"number":11455,"title":"[SPARK-13604][Core]Sync worker's state after registering with master","user":{"login":"zsxwing","id":1000778,"avatar_url":"https://avatars.githubusercontent.com/u/1000778?v=3","gravatar_id":"","url":"https://api.github.com/users/zsxwing","html_url":"https://github.com/zsxwing","followers_url":"https://api.github.com/users/zsxwing/followers","following_url":"https://api.github.com/users/zsxwing/following{/other_user}","gists_url":"https://api.github.com/users/zsxwing/gists{/gist_id}","starred_url":"https://api.github.com/users/zsxwing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zsxwing/subscriptions","organizations_url":"https://api.github.com/users/zsxwing/orgs","repos_url":"https://api.github.com/users/zsxwing/repos","events_url":"https://api.github.com/users/zsxwing/events{/privacy}","received_events_url":"https://api.github.com/users/zsxwing/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2016-03-02T00:43:56Z","updated_at":"2016-03-10T20:17:59Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/11455","html_url":"https://github.com/apache/spark/pull/11455","diff_url":"https://github.com/apache/spark/pull/11455.diff","patch_url":"https://github.com/apache/spark/pull/11455.patch"},"body":"## What changes were proposed in this pull request?\r\n\r\nHere lists all cases that Master cannot talk with Worker for a while and then network is back.\r\n\r\n1. Master doesn't know the network issue (not yet timeout)\r\n\r\n  a. Worker doesn't know the network issue (onDisconnected is not called)\r\n    - Worker keeps sending Heartbeat. Both Worker and Master don't know the network issue. Nothing to do. (Finally, Master will notice the heartbeat timeout if network is not recovered)\r\n\r\n  b. Worker knows the network issue (onDisconnected is called)\r\n    - Worker stops sending Heartbeat and sends `RegisterWorker` to master. Master will reply `RegisterWorkerFailed(\"Duplicate worker ID\")`. Worker calls \"System.exit(1)\" (Finally, Master will notice the heartbeat timeout if network is not recovered) (May leak driver processes. See [SPARK-13602](https://issues.apache.org/jira/browse/SPARK-13602))\r\n\r\n2. Worker timeout (Master knows the network issue). In such case,  master removes Worker and its executors and drivers.\r\n\r\n  a. Worker doesn't know the network issue (onDisconnected is not called)\r\n    - Worker keeps sending Heartbeat.\r\n    - If the network is back, say Master receives Heartbeat, Master sends `ReconnectWorker` to Worker\r\n    - Worker send `RegisterWorker` to master.\r\n    - Master accepts `RegisterWorker` but doesn't know executors and drivers in Worker. (may leak executors)\r\n\r\n  b. Worker knows the network issue (onDisconnected is called)\r\n    - Worker stop sending `Heartbeat`. Worker will send \"RegisterWorker\" to master.\r\n    - Master accepts `RegisterWorker` but doesn't know executors and drivers in Worker. (may leak executors)\r\n\r\nThis PR fixes executors and drivers leak in 2.a and 2.b when Worker reregisters with Master. The approach is making Worker send `WorkerLatestState` to sync the state after registering with master successfully. Then Master will ask Worker to kill unknown executors and drivers. \r\n\r\nNote:  Worker cannot just kill executors after registering with master because in the worker, `LaunchExecutor` and `RegisteredWorker` are processed in two threads. If `LaunchExecutor` happens before `RegisteredWorker`, Worker's executor list will contain new executors after Master accepts `RegisterWorker`. We should not kill these executors. So sending the list to Master and let Master tell Worker which executors should be killed. \r\n\r\n## How was this patch tested?\r\n\r\ntest(\"SPARK-13604: Master should ask Worker kill unknown executors and drivers\")"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/195030235","html_url":"https://github.com/apache/spark/pull/11455#issuecomment-195030235","issue_url":"https://api.github.com/repos/apache/spark/issues/11455","id":195030235,"user":{"login":"AmplabJenkins","id":4031291,"avatar_url":"https://avatars.githubusercontent.com/u/4031291?v=3","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":"2016-03-10T20:17:58Z","updated_at":"2016-03-10T20:17:58Z","body":"Merged build finished. Test FAILed."}}