kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 874608aec5e51fba039314ef65415bcacb1e28330b97a5df494cf97a448a5efa |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-04-29 19:36 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-05-04 12:53 +02:00 |
| Parents | fa8f9610d6ed |
1 file changed
modified features/metadata/README.md +70 −4
| @@ -1,13 +1,19 @@ | ||
| 1 | 1 | ## Metadata |
| 2 | 2 | |
| 3 | 3 | The driver maintains global information about the Cassandra cluster it |
| 4 | -is connected to. It is available via `Cluster#getMetadata()`. | |
| 4 | +is connected to. It is available via | |
| 5 | +[Cluster#getMetadata()][getMetadata]. | |
| 6 | + | |
| 7 | +[getMetadata]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Cluster.html#getMetadata() | |
| 5 | 8 | |
| 6 | 9 | ### Schema metadata |
| 7 | 10 | |
| 8 | -Use `getKeyspace(String)` or `getKeyspaces()` to get keyspace-level | |
| 9 | -metadata. From there you can access the keyspace's objects (tables, and | |
| 10 | -UDTs and UDFs if relevant). | |
| 11 | +Use [getKeyspace(String)][getKeyspace] or [getKeyspaces()][getKeyspaces] | |
| 12 | +to get keyspace-level metadata. From there you can access the keyspace's | |
| 13 | +objects (tables, and UDTs and UDFs if relevant). | |
| 14 | + | |
| 15 | +[getKeyspace]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Metadata.html#getKeyspace(java.lang.String) | |
| 16 | +[getKeyspaces]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Metadata.html#getKeyspaces() | |
| 11 | 17 | |
| 12 | 18 | #### Refreshes |
| 13 | 19 | |
| @@ -103,3 +109,63 @@ | ||
| 103 | 109 | (so `maxSchemaAgreementWaitSeconds` does not apply). If you need |
| 104 | 110 | retries, you'll have to schedule them yourself (for example with a |
| 105 | 111 | custom executor). |
| 112 | + | |
| 113 | +Check out the API docs for the features in this section: | |
| 114 | + | |
| 115 | +* [withMaxSchemaAgreementWaitSeconds(int)](http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Cluster.Builder.html#withMaxSchemaAgreementWaitSeconds(int)) | |
| 116 | +* [isSchemaInAgreement()](http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/ExecutionInfo.html#isSchemaInAgreement()) | |
| 117 | +* [checkSchemaAgreement()](http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Metadata.html#checkSchemaAgreement()) | |
| 118 | + | |
| 119 | + | |
| 120 | +### Token metadata | |
| 121 | + | |
| 122 | +This feature is probably of less interest to regular driver users, but | |
| 123 | +it will be useful if you're writing an analytics client on top of the | |
| 124 | +driver. | |
| 125 | + | |
| 126 | +[Metadata][metadata] exposes a number of methods to manipulate tokens | |
| 127 | +and ranges: [getTokenRanges()][getTokenRanges], [getTokenRanges(String | |
| 128 | +keyspace, Host host)][getTokenRanges2], [getReplicas(String keyspace, | |
| 129 | +TokenRange range)][getReplicas], [newToken(String)][newToken] and | |
| 130 | +[newTokenRange(Token start, Token end)][newTokenRange]. | |
| 131 | + | |
| 132 | +[TokenRange][TokenRange] provides various operations on ranges | |
| 133 | +(splitting, merging, etc.). | |
| 134 | + | |
| 135 | +Each host exposes its primary tokens as [getTokens()][getTokens]. | |
| 136 | + | |
| 137 | +Finally, you can inject tokens in CQL queries with | |
| 138 | +[BoundStatement#setToken][setToken], and retrieve them from results with | |
| 139 | +[Row#getToken][getToken] and [Row#getPartitionKeyToken][getPKToken]. | |
| 140 | + | |
| 141 | +As an example, here is how you could compute the splits to partition a | |
| 142 | +job (pseudocode): | |
| 143 | + | |
| 144 | +``` | |
| 145 | +metadata = cluster.getMetadata() | |
| 146 | +for range : metadata.getTokenRanges() { | |
| 147 | + hosts = metadata.getReplicas(keyspace, range) | |
| 148 | + int n = estimateNumberOfSplits() // more on that below | |
| 149 | + for split : range.splitEvenly(n) | |
| 150 | + // pick a host to process split | |
| 151 | +} | |
| 152 | +``` | |
| 153 | + | |
| 154 | +For `estimateNumberOfSplits`, you need a way to estimate the total | |
| 155 | +number of partition keys (this is what analytics clients would | |
| 156 | +traditionally do with the Thrift operation `describe_splits_ex`). | |
| 157 | +Starting with Cassandra 2.1.5, this information is available in a system | |
| 158 | +table (see | |
| 159 | +[CASSANDRA-7688](https://issues.apache.org/jira/browse/CASSANDRA-7688)). | |
| 160 | + | |
| 161 | +[metadata]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Metadata.html | |
| 162 | +[getTokenRanges]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Metadata.html#getTokenRanges() | |
| 163 | +[getTokenRanges2]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Metadata.html#getTokenRanges(java.lang.String,%20com.datastax.driver.core.Host) | |
| 164 | +[getReplicas]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Metadata.html#getReplicas(java.lang.String,%20com.datastax.driver.core.TokenRange) | |
| 165 | +[newToken]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Metadata.html#newToken(java.lang.String) | |
| 166 | +[newTokenRange]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Metadata.html#newTokenRange(com.datastax.driver.core.Token,%20com.datastax.driver.core.Token) | |
| 167 | +[TokenRange]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/TokenRange.html | |
| 168 | +[getTokens]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Host.html#getTokens() | |
| 169 | +[setToken]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/BoundStatement.html#setToken(int,%20com.datastax.driver.core.Token) | |
| 170 | +[getToken]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Row.html#getToken(int) | |
| 171 | +[getPKToken]: http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Row.html#getPartitionKeyToken() |