GitHub PullRequestReviewCommentEvent at 2014-07-14 06:49:33
Repository: spark-cassandra-connector
Actor: pkolaczk
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/comments/14866111","id":14866111,"diff_hunk":"@@ -63,57 +63,44 @@ class CassandraConnector(conf: CassandraConnectorConf)\n   /** Authentication configuration */\n   def authConf = _config.authConf\n \n-  /** Allows to use Cassandra `Cluster` in a safe way without\n-    * risk of forgetting to close it. Multiple, concurrent calls might share the same\n-    * `Cluster`. The `Cluster` will be closed when not in use for some time. */\n-  def withClusterDo[T](code: Cluster => T): T = {\n-    var cluster: Cluster = null\n+  /** Returns a shared session to Cassandra and increases the internal open\n+    * reference counter. It does not release the session automatically,\n+    * so please remember to close it after use. Closing a shared session\n+    * decreases the session reference counter. If the reference count drops to zero,\n+    * the session may be physically closed. */\n+  def openSession() = {\n+    val session = sessionCache.acquire(_config)\n     try {\n-      cluster = clusterCache.acquire(_config)\n-      val allNodes = cluster.getMetadata.getAllHosts.toSet\n+      val allNodes = session.getCluster.getMetadata.getAllHosts.toSet\n       val myNodes = nodesInTheSameDC(_config.hosts, allNodes).map(_.getAddress)\n       _config = _config.copy(hosts = myNodes)\n-      code(cluster)\n-    }\n-    finally {\n-      if (cluster != null)\n-        clusterCache.release(cluster)\n+      SessionProxy.wrapWithCloseAction(session)(sessionCache.release)\n+    } catch {\n+      case e: Throwable =>\n+        sessionCache.release(session)\n+        throw e\n     }\n   }\n \n   /** Allows to use Cassandra `Session` in a safe way without\n     * risk of forgetting to close it. */\n   def withSessionDo[T](code: Session => T): T = {\n-    withClusterDo { cluster =>\n-      IOUtils.closeAfterUse(cluster.connect) { session =>\n-        code(SessionProxy.wrap(session))\n-      }\n+    IOUtils.closeAfterUse(openSession()) { session =>\n+      code(SessionProxy.wrap(session))\n     }\n   }\n \n-  /** Opens a new session to Cassandra.\n-    * It does not close it automatically, so please remember to close it after use. */\n-  def openSession() = {\n-    var cluster: Cluster = null\n-    var session: Session = null\n-    try {\n-      cluster = clusterCache.acquire(_config)\n-      session = cluster.connect()\n-      SessionProxy.wrapWithCloseAction(session) { _ =>\n-        clusterCache.release(cluster)\n-      }\n-    }\n-    catch {\n-      case e: Throwable =>\n-        if (session != null)\n-          session.close()\n-        if (cluster != null)\n-          clusterCache.release(cluster)\n-        throw e\n+\n+  /** Allows to use Cassandra `Cluster` in a safe way without\n+    * risk of forgetting to close it. Multiple, concurrent calls might share the same\n+    * `Cluster`. The `Cluster` will be closed when not in use for some time. */\n+  def withClusterDo[T](code: Cluster => T): T = {\n+    withSessionDo { session =>\n+      code(session.getCluster)","path":"src/main/scala/com/datastax/spark/connector/cql/CassandraConnector.scala","position":81,"original_position":81,"commit_id":"20b70d8d2c05775017bb97c37cce39e7c7e28a29","original_commit_id":"20b70d8d2c05775017bb97c37cce39e7c7e28a29","user":{"login":"pkolaczk","id":1352795,"avatar_url":"https://avatars.githubusercontent.com/u/1352795?","gravatar_id":"1843063a52a68828c4eccedd9bba95b9","url":"https://api.github.com/users/pkolaczk","html_url":"https://github.com/pkolaczk","followers_url":"https://api.github.com/users/pkolaczk/followers","following_url":"https://api.github.com/users/pkolaczk/following{/other_user}","gists_url":"https://api.github.com/users/pkolaczk/gists{/gist_id}","starred_url":"https://api.github.com/users/pkolaczk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkolaczk/subscriptions","organizations_url":"https://api.github.com/users/pkolaczk/orgs","repos_url":"https://api.github.com/users/pkolaczk/repos","events_url":"https://api.github.com/users/pkolaczk/events{/privacy}","received_events_url":"https://api.github.com/users/pkolaczk/received_events","type":"User","site_admin":false},"body":"Indeed, that would make the abstraction less leaky.","created_at":"2014-07-14T06:49:33Z","updated_at":"2014-07-14T06:49:33Z","html_url":"https://github.com/datastax/spark-cassandra-connector/pull/54#discussion_r14866111","pull_request_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/54","_links":{"self":{"href":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/comments/14866111"},"html":{"href":"https://github.com/datastax/spark-cassandra-connector/pull/54#discussion_r14866111"},"pull_request":{"href":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/54"}}},"pull_request":{"url":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/54","id":18320867,"html_url":"https://github.com/datastax/spark-cassandra-connector/pull/54","diff_url":"https://github.com/datastax/spark-cassandra-connector/pull/54.diff","patch_url":"https://github.com/datastax/spark-cassandra-connector/pull/54.patch","issue_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues/54","number":54,"state":"open","title":"CassandraConnector shares core driver Session objects. Previously it sha...","user":{"login":"pkolaczk","id":1352795,"avatar_url":"https://avatars.githubusercontent.com/u/1352795?","gravatar_id":"1843063a52a68828c4eccedd9bba95b9","url":"https://api.github.com/users/pkolaczk","html_url":"https://github.com/pkolaczk","followers_url":"https://api.github.com/users/pkolaczk/followers","following_url":"https://api.github.com/users/pkolaczk/following{/other_user}","gists_url":"https://api.github.com/users/pkolaczk/gists{/gist_id}","starred_url":"https://api.github.com/users/pkolaczk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkolaczk/subscriptions","organizations_url":"https://api.github.com/users/pkolaczk/orgs","repos_url":"https://api.github.com/users/pkolaczk/repos","events_url":"https://api.github.com/users/pkolaczk/events{/privacy}","received_events_url":"https://api.github.com/users/pkolaczk/received_events","type":"User","site_admin":false},"body":"...red only Cluster objects and a separate Session was open per every Spark task. This had a significant performance overhead in terms of CPU, networking and memory use, because every Session object manages an internal pool of connections to all cluster nodes. Fixes #41 and #53.","created_at":"2014-07-13T06:09:18Z","updated_at":"2014-07-14T06:49:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"80b8c26975b2b66e127891c011f2cb2d2775f9f6","assignee":{"login":"jacek-lewandowski","id":6516951,"avatar_url":"https://avatars.githubusercontent.com/u/6516951?","gravatar_id":"5ea8165c9ae02629f0eb249032af5b07","url":"https://api.github.com/users/jacek-lewandowski","html_url":"https://github.com/jacek-lewandowski","followers_url":"https://api.github.com/users/jacek-lewandowski/followers","following_url":"https://api.github.com/users/jacek-lewandowski/following{/other_user}","gists_url":"https://api.github.com/users/jacek-lewandowski/gists{/gist_id}","starred_url":"https://api.github.com/users/jacek-lewandowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacek-lewandowski/subscriptions","organizations_url":"https://api.github.com/users/jacek-lewandowski/orgs","repos_url":"https://api.github.com/users/jacek-lewandowski/repos","events_url":"https://api.github.com/users/jacek-lewandowski/events{/privacy}","received_events_url":"https://api.github.com/users/jacek-lewandowski/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/datastax/spark-cassandra-connector/milestones/1","labels_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/milestones/1/labels","id":707961,"number":1,"title":"1.0","description":"First stable release. Support for Spark 0.9.x and 1.0 (without Spark 1.0 specific features) and Cassandra 2.0.","creator":{"login":"pkolaczk","id":1352795,"avatar_url":"https://avatars.githubusercontent.com/u/1352795?","gravatar_id":"1843063a52a68828c4eccedd9bba95b9","url":"https://api.github.com/users/pkolaczk","html_url":"https://github.com/pkolaczk","followers_url":"https://api.github.com/users/pkolaczk/followers","following_url":"https://api.github.com/users/pkolaczk/following{/other_user}","gists_url":"https://api.github.com/users/pkolaczk/gists{/gist_id}","starred_url":"https://api.github.com/users/pkolaczk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkolaczk/subscriptions","organizations_url":"https://api.github.com/users/pkolaczk/orgs","repos_url":"https://api.github.com/users/pkolaczk/repos","events_url":"https://api.github.com/users/pkolaczk/events{/privacy}","received_events_url":"https://api.github.com/users/pkolaczk/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":11,"state":"open","created_at":"2014-07-02T12:27:16Z","updated_at":"2014-07-14T04:20:19Z","due_on":"2014-07-18T07:00:00Z"},"commits_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/54/commits","review_comments_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/54/comments","review_comment_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/comments/{number}","comments_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues/54/comments","statuses_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/statuses/20b70d8d2c05775017bb97c37cce39e7c7e28a29","head":{"label":"datastax:issue-41","ref":"issue-41","sha":"20b70d8d2c05775017bb97c37cce39e7c7e28a29","user":{"login":"datastax","id":573369,"avatar_url":"https://avatars.githubusercontent.com/u/573369?","gravatar_id":"5cd14d804ff6455946254031d35efd3a","url":"https://api.github.com/users/datastax","html_url":"https://github.com/datastax","followers_url":"https://api.github.com/users/datastax/followers","following_url":"https://api.github.com/users/datastax/following{/other_user}","gists_url":"https://api.github.com/users/datastax/gists{/gist_id}","starred_url":"https://api.github.com/users/datastax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datastax/subscriptions","organizations_url":"https://api.github.com/users/datastax/orgs","repos_url":"https://api.github.com/users/datastax/repos","events_url":"https://api.github.com/users/datastax/events{/privacy}","received_events_url":"https://api.github.com/users/datastax/received_events","type":"Organization","site_admin":false},"repo":{"id":21280887,"name":"spark-cassandra-connector","full_name":"datastax/spark-cassandra-connector","owner":{"login":"datastax","id":573369,"avatar_url":"https://avatars.githubusercontent.com/u/573369?","gravatar_id":"5cd14d804ff6455946254031d35efd3a","url":"https://api.github.com/users/datastax","html_url":"https://github.com/datastax","followers_url":"https://api.github.com/users/datastax/followers","following_url":"https://api.github.com/users/datastax/following{/other_user}","gists_url":"https://api.github.com/users/datastax/gists{/gist_id}","starred_url":"https://api.github.com/users/datastax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datastax/subscriptions","organizations_url":"https://api.github.com/users/datastax/orgs","repos_url":"https://api.github.com/users/datastax/repos","events_url":"https://api.github.com/users/datastax/events{/privacy}","received_events_url":"https://api.github.com/users/datastax/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/datastax/spark-cassandra-connector","description":"If you write a Spark application that needs access to Cassandra, this library is for you","fork":false,"url":"https://api.github.com/repos/datastax/spark-cassandra-connector","forks_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/forks","keys_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/teams","hooks_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/hooks","issue_events_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues/events{/number}","events_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/events","assignees_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/assignees{/user}","branches_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/branches{/branch}","tags_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/tags","blobs_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/refs{/sha}","trees_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/statuses/{sha}","languages_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/languages","stargazers_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/stargazers","contributors_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/contributors","subscribers_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/subscribers","subscription_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/subscription","commits_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/commits{/sha}","git_commits_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/commits{/sha}","comments_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/comments{/number}","issue_comment_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues/comments/{number}","contents_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/contents/{+path}","compare_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/merges","archive_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/downloads","issues_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues{/number}","pulls_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls{/number}","milestones_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/milestones{/number}","notifications_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/labels{/name}","releases_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/releases{/id}","created_at":"2014-06-27T15:45:54Z","updated_at":"2014-07-12T23:49:00Z","pushed_at":"2014-07-14T04:28:01Z","git_url":"git://github.com/datastax/spark-cassandra-connector.git","ssh_url":"git@github.com:datastax/spark-cassandra-connector.git","clone_url":"https://github.com/datastax/spark-cassandra-connector.git","svn_url":"https://github.com/datastax/spark-cassandra-connector","homepage":"","size":1142,"stargazers_count":106,"watchers_count":106,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":19,"mirror_url":null,"open_issues_count":15,"forks":19,"open_issues":15,"watchers":106,"default_branch":"master"}},"base":{"label":"datastax:master","ref":"master","sha":"6d9e271da0631fe69f7d67dd68900b90b9a3ea30","user":{"login":"datastax","id":573369,"avatar_url":"https://avatars.githubusercontent.com/u/573369?","gravatar_id":"5cd14d804ff6455946254031d35efd3a","url":"https://api.github.com/users/datastax","html_url":"https://github.com/datastax","followers_url":"https://api.github.com/users/datastax/followers","following_url":"https://api.github.com/users/datastax/following{/other_user}","gists_url":"https://api.github.com/users/datastax/gists{/gist_id}","starred_url":"https://api.github.com/users/datastax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datastax/subscriptions","organizations_url":"https://api.github.com/users/datastax/orgs","repos_url":"https://api.github.com/users/datastax/repos","events_url":"https://api.github.com/users/datastax/events{/privacy}","received_events_url":"https://api.github.com/users/datastax/received_events","type":"Organization","site_admin":false},"repo":{"id":21280887,"name":"spark-cassandra-connector","full_name":"datastax/spark-cassandra-connector","owner":{"login":"datastax","id":573369,"avatar_url":"https://avatars.githubusercontent.com/u/573369?","gravatar_id":"5cd14d804ff6455946254031d35efd3a","url":"https://api.github.com/users/datastax","html_url":"https://github.com/datastax","followers_url":"https://api.github.com/users/datastax/followers","following_url":"https://api.github.com/users/datastax/following{/other_user}","gists_url":"https://api.github.com/users/datastax/gists{/gist_id}","starred_url":"https://api.github.com/users/datastax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datastax/subscriptions","organizations_url":"https://api.github.com/users/datastax/orgs","repos_url":"https://api.github.com/users/datastax/repos","events_url":"https://api.github.com/users/datastax/events{/privacy}","received_events_url":"https://api.github.com/users/datastax/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/datastax/spark-cassandra-connector","description":"If you write a Spark application that needs access to Cassandra, this library is for you","fork":false,"url":"https://api.github.com/repos/datastax/spark-cassandra-connector","forks_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/forks","keys_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/teams","hooks_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/hooks","issue_events_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues/events{/number}","events_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/events","assignees_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/assignees{/user}","branches_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/branches{/branch}","tags_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/tags","blobs_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/refs{/sha}","trees_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/statuses/{sha}","languages_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/languages","stargazers_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/stargazers","contributors_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/contributors","subscribers_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/subscribers","subscription_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/subscription","commits_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/commits{/sha}","git_commits_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/git/commits{/sha}","comments_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/comments{/number}","issue_comment_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues/comments/{number}","contents_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/contents/{+path}","compare_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/merges","archive_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/downloads","issues_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues{/number}","pulls_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls{/number}","milestones_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/milestones{/number}","notifications_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/labels{/name}","releases_url":"https://api.github.com/repos/datastax/spark-cassandra-connector/releases{/id}","created_at":"2014-06-27T15:45:54Z","updated_at":"2014-07-12T23:49:00Z","pushed_at":"2014-07-14T04:28:01Z","git_url":"git://github.com/datastax/spark-cassandra-connector.git","ssh_url":"git@github.com:datastax/spark-cassandra-connector.git","clone_url":"https://github.com/datastax/spark-cassandra-connector.git","svn_url":"https://github.com/datastax/spark-cassandra-connector","homepage":"","size":1142,"stargazers_count":106,"watchers_count":106,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":19,"mirror_url":null,"open_issues_count":15,"forks":19,"open_issues":15,"watchers":106,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/54"},"html":{"href":"https://github.com/datastax/spark-cassandra-connector/pull/54"},"issue":{"href":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues/54"},"comments":{"href":"https://api.github.com/repos/datastax/spark-cassandra-connector/issues/54/comments"},"review_comments":{"href":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/54/comments"},"review_comment":{"href":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/datastax/spark-cassandra-connector/pulls/54/commits"},"statuses":{"href":"https://api.github.com/repos/datastax/spark-cassandra-connector/statuses/20b70d8d2c05775017bb97c37cce39e7c7e28a29"}}}}