{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/23051150","id":23051150,"diff_hunk":"@@ -0,0 +1,203 @@\n+/*\n+ * Copyright © 2014 Cask Data, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n+ * use this file except in compliance with the License. You may obtain a copy of\n+ * the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n+ * License for the specific language governing permissions and limitations under\n+ * the License.\n+ */\n+package co.cask.cdap.data.stream.service;\n+\n+import co.cask.cdap.api.data.stream.StreamSpecification;\n+import co.cask.cdap.common.conf.Constants;\n+import co.cask.cdap.common.conf.PropertyStore;\n+import co.cask.cdap.common.io.Codec;\n+import co.cask.cdap.common.zookeeper.coordination.BalancedAssignmentStrategy;\n+import co.cask.cdap.common.zookeeper.coordination.PartitionReplica;\n+import co.cask.cdap.common.zookeeper.coordination.ResourceCoordinator;\n+import co.cask.cdap.common.zookeeper.coordination.ResourceCoordinatorClient;\n+import co.cask.cdap.common.zookeeper.coordination.ResourceHandler;\n+import co.cask.cdap.common.zookeeper.coordination.ResourceModifier;\n+import co.cask.cdap.common.zookeeper.coordination.ResourceRequirement;\n+import co.cask.cdap.common.zookeeper.store.ZKPropertyStore;\n+import co.cask.cdap.data2.transaction.stream.StreamAdmin;\n+import com.google.common.base.Functions;\n+import com.google.common.base.Preconditions;\n+import com.google.common.base.Throwables;\n+import com.google.common.util.concurrent.Futures;\n+import com.google.common.util.concurrent.ListenableFuture;\n+import com.google.inject.Inject;\n+import com.google.inject.Singleton;\n+import org.apache.twill.api.ElectionHandler;\n+import org.apache.twill.common.Cancellable;\n+import org.apache.twill.discovery.Discoverable;\n+import org.apache.twill.discovery.DiscoveryServiceClient;\n+import org.apache.twill.internal.zookeeper.LeaderElection;\n+import org.apache.twill.zookeeper.ZKClient;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.util.Collection;\n+import java.util.Set;\n+import javax.annotation.Nullable;\n+\n+/**\n+ * A {@link StreamCoordinator} uses ZooKeeper to implementation coordination needed for stream. It also uses a\n+ * {@link ResourceCoordinator} to elect each handler as the leader of a set of streams.\n+ */\n+@Singleton\n+public final class DistributedStreamCoordinator extends AbstractStreamCoordinator {\n+  private static final Logger LOG = LoggerFactory.getLogger(DistributedStreamCoordinator.class);\n+\n+  public static final String STREAMS_COORDINATOR = \"streams.coordinator\";","path":"cdap-data-fabric/src/main/java/co/cask/cdap/data/stream/service/DistributedStreamCoordinator.java","position":59,"original_position":59,"commit_id":"5897c932ed898f53c7bcec669a15f32c565f9b9a","original_commit_id":"5897c932ed898f53c7bcec669a15f32c565f9b9a","user":{"login":"jguery","id":3600810,"avatar_url":"https://avatars.githubusercontent.com/u/3600810?v=3","gravatar_id":"","url":"https://api.github.com/users/jguery","html_url":"https://github.com/jguery","followers_url":"https://api.github.com/users/jguery/followers","following_url":"https://api.github.com/users/jguery/following{/other_user}","gists_url":"https://api.github.com/users/jguery/gists{/gist_id}","starred_url":"https://api.github.com/users/jguery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jguery/subscriptions","organizations_url":"https://api.github.com/users/jguery/orgs","repos_url":"https://api.github.com/users/jguery/repos","events_url":"https://api.github.com/users/jguery/events{/privacy}","received_events_url":"https://api.github.com/users/jguery/received_events","type":"User","site_admin":false},"body":"True.","created_at":"2015-01-15T22:54:26Z","updated_at":"2015-01-15T22:54:26Z","html_url":"https://github.com/caskdata/cdap/pull/912#discussion_r23051150","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/912","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/23051150"},"html":{"href":"https://github.com/caskdata/cdap/pull/912#discussion_r23051150"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/912"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/912","id":26935779,"html_url":"https://github.com/caskdata/cdap/pull/912","diff_url":"https://github.com/caskdata/cdap/pull/912.diff","patch_url":"https://github.com/caskdata/cdap/pull/912.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/912","number":912,"state":"open","locked":false,"title":"Add logic to have one stream handler leader per stream","user":{"login":"jguery","id":3600810,"avatar_url":"https://avatars.githubusercontent.com/u/3600810?v=3","gravatar_id":"","url":"https://api.github.com/users/jguery","html_url":"https://github.com/jguery","followers_url":"https://api.github.com/users/jguery/followers","following_url":"https://api.github.com/users/jguery/following{/other_user}","gists_url":"https://api.github.com/users/jguery/gists{/gist_id}","starred_url":"https://api.github.com/users/jguery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jguery/subscriptions","organizations_url":"https://api.github.com/users/jguery/orgs","repos_url":"https://api.github.com/users/jguery/repos","events_url":"https://api.github.com/users/jguery/events{/privacy}","received_events_url":"https://api.github.com/users/jguery/received_events","type":"User","site_admin":false},"body":"Build: https://builds.cask.co/browse/CDAP-DUT417-1","created_at":"2015-01-07T03:33:03Z","updated_at":"2015-01-15T22:54:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"199b5844ac2d242192c013fd04e34f2d50ed3f92","assignee":null,"milestone":{"url":"https://api.github.com/repos/caskdata/cdap/milestones/2","labels_url":"https://api.github.com/repos/caskdata/cdap/milestones/2/labels","id":880401,"number":2,"title":"2.7.0","description":null,"creator":{"login":"jwang47","id":1084704,"avatar_url":"https://avatars.githubusercontent.com/u/1084704?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang47","html_url":"https://github.com/jwang47","followers_url":"https://api.github.com/users/jwang47/followers","following_url":"https://api.github.com/users/jwang47/following{/other_user}","gists_url":"https://api.github.com/users/jwang47/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang47/subscriptions","organizations_url":"https://api.github.com/users/jwang47/orgs","repos_url":"https://api.github.com/users/jwang47/repos","events_url":"https://api.github.com/users/jwang47/events{/privacy}","received_events_url":"https://api.github.com/users/jwang47/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":56,"state":"open","created_at":"2014-11-25T19:54:18Z","updated_at":"2015-01-15T22:41:46Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/912/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/912/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/{number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/912/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/5897c932ed898f53c7bcec669a15f32c565f9b9a","head":{"label":"caskdata:feature/stream-handlers-leader-election","ref":"feature/stream-handlers-leader-election","sha":"5897c932ed898f53c7bcec669a15f32c565f9b9a","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments/{number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-01-15T22:41:47Z","pushed_at":"2015-01-15T22:47:28Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":694931,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":19,"forks":7,"open_issues":19,"watchers":23,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"e0785d62099cb4ff5292213f3da03686e3a04ac9","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments/{number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-01-15T22:41:47Z","pushed_at":"2015-01-15T22:47:28Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"http://cdap.io","size":694931,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":19,"forks":7,"open_issues":19,"watchers":23,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/912"},"html":{"href":"https://github.com/caskdata/cdap/pull/912"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/912"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/912/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/912/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/912/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/5897c932ed898f53c7bcec669a15f32c565f9b9a"}}}}