{"action":"created","issue":{"url":"https://api.github.com/repos/gocql/gocql/issues/338","labels_url":"https://api.github.com/repos/gocql/gocql/issues/338/labels{/name}","comments_url":"https://api.github.com/repos/gocql/gocql/issues/338/comments","events_url":"https://api.github.com/repos/gocql/gocql/issues/338/events","html_url":"https://github.com/gocql/gocql/pull/338","id":64852019,"number":338,"title":"Added routing key computation to Query","user":{"login":"justinretailnext","id":10342005,"avatar_url":"https://avatars.githubusercontent.com/u/10342005?v=3","gravatar_id":"","url":"https://api.github.com/users/justinretailnext","html_url":"https://github.com/justinretailnext","followers_url":"https://api.github.com/users/justinretailnext/followers","following_url":"https://api.github.com/users/justinretailnext/following{/other_user}","gists_url":"https://api.github.com/users/justinretailnext/gists{/gist_id}","starred_url":"https://api.github.com/users/justinretailnext/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinretailnext/subscriptions","organizations_url":"https://api.github.com/users/justinretailnext/orgs","repos_url":"https://api.github.com/users/justinretailnext/repos","events_url":"https://api.github.com/users/justinretailnext/events{/privacy}","received_events_url":"https://api.github.com/users/justinretailnext/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-27T21:10:21Z","updated_at":"2015-03-27T22:09:29Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/gocql/gocql/pulls/338","html_url":"https://github.com/gocql/gocql/pull/338","diff_url":"https://github.com/gocql/gocql/pull/338.diff","patch_url":"https://github.com/gocql/gocql/pull/338.patch"},"body":"This PR adds some incremental functionality which would be needed for token awareness in a connection pool. It depends on the metadata functionality from my previous PR. Since gocql doesn't differentiate between prepared and unprepared statements, this functionality is a departure in some respects from the Datastax driver methodology, which it is loosely based on.\r\n\r\nThe top-level functionality added in this PR is the addition of the `GetRoutingKey() []byte` function to `Query`. This function returns the computed routing key for a given statement and its bound values. The function `RoutingKey([]byte)` is supplied in `Query` as a way to override the routing key, or as a simple short circuit to avoid the computation of the routing key (e.g. cqlc could probably generate code that creates appropriate routing keys without relying on the runtime computation of the partition key metadata). Computation of the routing key during runtime requires determining which bound parameters of a statement are part of the partition key. This is done in the `routingKeyInfo() *routingKeyInfo` function of `Session` which utilizes both the cached `QueryInfo` for a statement combined with the `TableMetadata`. The function `routingKeyInfo` is cached so that the routing key indexes and type information is only collected once for each unique statement.\r\n\r\nSome things to note in this PR are the slight modification to queries in metadata.go which set the routing key to an empty byte slice:\r\n```\r\nquery.RoutingKey([]byte{})\r\n```\r\nThis disables computation of the routing key since the routing key computation calls the metadata queries thus avoiding an infinite loop. In the Datastax drivers the metadata queries are performed on a uniquely configured \"control\" connection which does not use the routing key, thus avoiding this workaround.\r\n\r\nAnother item to notice is that the routing key info cache is owned by the session since this information isn't bound to a specific connection unlike the prepared statement cache.\n\n<!-- Reviewable:start -->\n[<img src=\"https://reviewable.io/review_button.png\" height=40 alt=\"Review on Reviewable\"/>](https://reviewable.io/reviews/gocql/gocql/338)\n<!-- Reviewable:end -->\n"},"comment":{"url":"https://api.github.com/repos/gocql/gocql/issues/comments/87105128","html_url":"https://github.com/gocql/gocql/pull/338#issuecomment-87105128","issue_url":"https://api.github.com/repos/gocql/gocql/issues/338","id":87105128,"user":{"login":"Zariel","id":2213,"avatar_url":"https://avatars.githubusercontent.com/u/2213?v=3","gravatar_id":"","url":"https://api.github.com/users/Zariel","html_url":"https://github.com/Zariel","followers_url":"https://api.github.com/users/Zariel/followers","following_url":"https://api.github.com/users/Zariel/following{/other_user}","gists_url":"https://api.github.com/users/Zariel/gists{/gist_id}","starred_url":"https://api.github.com/users/Zariel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zariel/subscriptions","organizations_url":"https://api.github.com/users/Zariel/orgs","repos_url":"https://api.github.com/users/Zariel/repos","events_url":"https://api.github.com/users/Zariel/events{/privacy}","received_events_url":"https://api.github.com/users/Zariel/received_events","type":"User","site_admin":false},"created_at":"2015-03-27T22:09:29Z","updated_at":"2015-03-27T22:09:29Z","body":"As a note once my refactor of the framing code lands I plan on working on adding a control connection, which should help with this and various other features for the connection pool.\r\n\r\nThanks for the PR, I will take a look :)"}}