{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/48311290","id":48311290,"diff_hunk":"@@ -1415,6 +1415,185 @@ Note that the connections in the pool should be lazily created on demand and tim\n \n ***\n \n+## Accumulator and Broadcast\n+\n+Accumulator and Broadcast cannot be recovered from checkpoint in Spark Streaming. If you enable checkpointing and use Accumulator or Broadcast as well, you'll have to create lazily instantiated singleton instances for Accumulator and Broadcast so that they can be restarted on driver failures. This is shown in the following example.\n+\n+<div class=\"codetabs\">\n+<div data-lang=\"scala\" markdown=\"1\">\n+{% highlight scala %}\n+\n+object WordBlacklist {\n+\n+  @volatile private var instance: Broadcast[Seq[String]] = null\n+\n+  def getInstance(sc: SparkContext): Broadcast[Seq[String]] = {\n+    if (instance == null) {\n+      synchronized {\n+        if (instance == null) {\n+          val wordBlacklist = Seq(\"a\", \"b\", \"c\")\n+          instance = sc.broadcast(wordBlacklist)\n+        }\n+      }\n+    }\n+    instance\n+  }\n+}\n+\n+object DroppedWordsCounter {\n+\n+  @volatile private var instance: Accumulator[Long] = null","path":"docs/streaming-programming-guide.md","position":31,"original_position":31,"commit_id":"9e241e791e5ce2cb0cc3dd7c609339ca8ea11129","original_commit_id":"9e241e791e5ce2cb0cc3dd7c609339ca8ea11129","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},"body":"Oh, no. We need `sc` here. So it cannot be a val.","created_at":"2015-12-22T23:47:56Z","updated_at":"2015-12-22T23:47:56Z","html_url":"https://github.com/apache/spark/pull/10385#discussion_r48311290","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/10385","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/48311290"},"html":{"href":"https://github.com/apache/spark/pull/10385#discussion_r48311290"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/10385"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/10385","id":54142904,"html_url":"https://github.com/apache/spark/pull/10385","diff_url":"https://github.com/apache/spark/pull/10385.diff","patch_url":"https://github.com/apache/spark/pull/10385.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/10385","number":10385,"state":"open","locked":false,"title":"[SPARK-12429][Streaming][Doc]Add Accumulator and Broadcast example for Streaming","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},"body":"This PR adds Scala, Java and Python examples to show how to use Accumulator and Broadcast in Spark Streaming to support checkpointing.","created_at":"2015-12-18T19:54:07Z","updated_at":"2015-12-22T23:47:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1819f7dc12fc655bd758b4d3f1273b17660ad665","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/10385/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/10385/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/10385/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/9e241e791e5ce2cb0cc3dd7c609339ca8ea11129","head":{"label":"zsxwing:accumulator-broadcast-example","ref":"accumulator-broadcast-example","sha":"9e241e791e5ce2cb0cc3dd7c609339ca8ea11129","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},"repo":{"id":17894272,"name":"spark","full_name":"zsxwing/spark","owner":{"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},"private":false,"html_url":"https://github.com/zsxwing/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/zsxwing/spark","forks_url":"https://api.github.com/repos/zsxwing/spark/forks","keys_url":"https://api.github.com/repos/zsxwing/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zsxwing/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zsxwing/spark/teams","hooks_url":"https://api.github.com/repos/zsxwing/spark/hooks","issue_events_url":"https://api.github.com/repos/zsxwing/spark/issues/events{/number}","events_url":"https://api.github.com/repos/zsxwing/spark/events","assignees_url":"https://api.github.com/repos/zsxwing/spark/assignees{/user}","branches_url":"https://api.github.com/repos/zsxwing/spark/branches{/branch}","tags_url":"https://api.github.com/repos/zsxwing/spark/tags","blobs_url":"https://api.github.com/repos/zsxwing/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zsxwing/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zsxwing/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/zsxwing/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zsxwing/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/zsxwing/spark/languages","stargazers_url":"https://api.github.com/repos/zsxwing/spark/stargazers","contributors_url":"https://api.github.com/repos/zsxwing/spark/contributors","subscribers_url":"https://api.github.com/repos/zsxwing/spark/subscribers","subscription_url":"https://api.github.com/repos/zsxwing/spark/subscription","commits_url":"https://api.github.com/repos/zsxwing/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/zsxwing/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/zsxwing/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/zsxwing/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/zsxwing/spark/contents/{+path}","compare_url":"https://api.github.com/repos/zsxwing/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zsxwing/spark/merges","archive_url":"https://api.github.com/repos/zsxwing/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zsxwing/spark/downloads","issues_url":"https://api.github.com/repos/zsxwing/spark/issues{/number}","pulls_url":"https://api.github.com/repos/zsxwing/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/zsxwing/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/zsxwing/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zsxwing/spark/labels{/name}","releases_url":"https://api.github.com/repos/zsxwing/spark/releases{/id}","created_at":"2014-03-19T06:21:04Z","updated_at":"2015-03-09T07:52:42Z","pushed_at":"2015-12-22T21:45:25Z","git_url":"git://github.com/zsxwing/spark.git","ssh_url":"git@github.com:zsxwing/spark.git","clone_url":"https://github.com/zsxwing/spark.git","svn_url":"https://github.com/zsxwing/spark","homepage":null,"size":128454,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"41ee7c57abd9f52065fd7ffb71a8af229603371d","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-12-22T23:29:22Z","pushed_at":"2015-12-22T23:34:08Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":393733,"stargazers_count":6663,"watchers_count":6663,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6169,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":389,"forks":6169,"open_issues":389,"watchers":6663,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/10385"},"html":{"href":"https://github.com/apache/spark/pull/10385"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/10385"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/10385/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/10385/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/10385/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/9e241e791e5ce2cb0cc3dd7c609339ca8ea11129"}}}}