kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | bb1e664492002b9858d980f29f657bba0d8125c5f0cf118fa545174fba5518de |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-03-01 12:04 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-03-07 16:57 +01:00 |
| Parents | 1880c9980a0f |
6 files changed
modified changelog/README.md +1 −0
| @@ -32,6 +32,7 @@ | ||
| 32 | 32 | - [improvement] JAVA-923: Position idempotent flag on object mapper queries. |
| 33 | 33 | - [new feature] JAVA-1019: SchemaBuilder support for CREATE/ALTER/DROP KEYSPACE. |
| 34 | 34 | - [bug] JAVA-1070: The Mapper should not prepare queries synchronously. |
| 35 | +- [new feature] JAVA-982: Introduce new method ConsistencyLevel.isSerial(). | |
| 35 | 36 | |
| 36 | 37 | Merged from 2.0 branch: |
| 37 | 38 |
modified driver-core/src/main/java/com/datastax/driver/core/ConsistencyLevel.java +20 −1
| @@ -58,11 +58,30 @@ | ||
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | - * Whether or not the the consistency level applies to the local data-center only. | |
| 61 | + * Whether or not this consistency level applies to the local data-center only. | |
| 62 | 62 | * |
| 63 | 63 | * @return whether this consistency level is {@code LOCAL_ONE} or {@code LOCAL_QUORUM}. |
| 64 | 64 | */ |
| 65 | 65 | public boolean isDCLocal() { |
| 66 | 66 | return this == LOCAL_ONE || this == LOCAL_QUORUM; |
| 67 | 67 | } |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Whether or not this consistency level is serial, that is, | |
| 71 | + * applies only to the "paxos" phase of a | |
| 72 | + * <a href="https://docs.datastax.com/en/cassandra/2.1/cassandra/dml/dml_ltwt_transaction_c.html">Lightweight transaction</a>. | |
| 73 | + * <p/> | |
| 74 | + * Serial consistency levels are only meaningful when executing conditional updates ({@code INSERT}, {@code UPDATE} | |
| 75 | + * or {@code DELETE} statements with an {@code IF} condition). | |
| 76 | + * <p/> | |
| 77 | + * Two consistency levels belong to this category: {@link #SERIAL} and {@link #LOCAL_SERIAL}. | |
| 78 | + * | |
| 79 | + * @return whether this consistency level is {@link #SERIAL} or {@link #LOCAL_SERIAL}. | |
| 80 | + * @see Statement#setSerialConsistencyLevel(ConsistencyLevel) | |
| 81 | + * @see <a href="https://docs.datastax.com/en/cassandra/2.1/cassandra/dml/dml_ltwt_transaction_c.html">Lightweight transactions</a> | |
| 82 | + */ | |
| 83 | + public boolean isSerial() { | |
| 84 | + return this == SERIAL || this == LOCAL_SERIAL; | |
| 85 | + } | |
| 86 | + | |
| 68 | 87 | } |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultPreparedStatement.java +1 −1
| @@ -141,7 +141,7 @@ | ||
| 141 | 141 | |
| 142 | 142 | @Override |
| 143 | 143 | public PreparedStatement setSerialConsistencyLevel(ConsistencyLevel serialConsistency) { |
| 144 | - if (serialConsistency != ConsistencyLevel.SERIAL && serialConsistency != ConsistencyLevel.LOCAL_SERIAL) | |
| 144 | + if (!serialConsistency.isSerial()) | |
| 145 | 145 | throw new IllegalArgumentException(); |
| 146 | 146 | this.serialConsistency = serialConsistency; |
| 147 | 147 | return this; |
modified driver-core/src/main/java/com/datastax/driver/core/Statement.java +9 −8
| @@ -82,8 +82,9 @@ | ||
| 82 | 82 | /** |
| 83 | 83 | * Sets the serial consistency level for the query. |
| 84 | 84 | * <p/> |
| 85 | - * The serial consistency level is only used by conditional updates (so INSERT, UPDATE | |
| 86 | - * and DELETE with an IF condition). For those, the serial consistency level defines | |
| 85 | + * The serial consistency level is only used by conditional updates ({@code INSERT}, {@code UPDATE} | |
| 86 | + * or {@code DELETE} statements with an {@code IF} condition). | |
| 87 | + * For those, the serial consistency level defines | |
| 87 | 88 | * the consistency level of the serial phase (or "paxos" phase) while the |
| 88 | 89 | * normal consistency level defines the consistency for the "learn" phase, i.e. what |
| 89 | 90 | * type of reads will be guaranteed to see the update right away. For instance, if |
| @@ -106,8 +107,8 @@ | ||
| 106 | 107 | * {@code ConsistencyLevel.SERIAL} or {@code ConsistencyLevel.LOCAL_SERIAL}. |
| 107 | 108 | */ |
| 108 | 109 | public Statement setSerialConsistencyLevel(ConsistencyLevel serialConsistency) { |
| 109 | - if (serialConsistency != ConsistencyLevel.SERIAL && serialConsistency != ConsistencyLevel.LOCAL_SERIAL) | |
| 110 | - throw new IllegalArgumentException(); | |
| 110 | + if (!serialConsistency.isSerial()) | |
| 111 | + throw new IllegalArgumentException("Supplied consistency level is not serial: " + serialConsistency); | |
| 111 | 112 | this.serialConsistency = serialConsistency; |
| 112 | 113 | return this; |
| 113 | 114 | } |
| @@ -115,10 +116,10 @@ | ||
| 115 | 116 | /** |
| 116 | 117 | * The serial consistency level for this query. |
| 117 | 118 | * <p/> |
| 118 | - * See {@link #setSerialConsistencyLevel} for more detail on the serial consistency level. | |
| 119 | + * See {@link #setSerialConsistencyLevel(ConsistencyLevel)} for more detail on the serial consistency level. | |
| 119 | 120 | * |
| 120 | - * @return the consistency level for this query, or {@code null} if no serial | |
| 121 | - * consistency level has been specified (through {@code setSerialConsistencyLevel}). | |
| 121 | + * @return the serial consistency level for this query, or {@code null} if no serial | |
| 122 | + * consistency level has been specified (through {@link #setSerialConsistencyLevel(ConsistencyLevel)}). | |
| 122 | 123 | * In the latter case, the default serial consistency level will be used. |
| 123 | 124 | */ |
| 124 | 125 | public ConsistencyLevel getSerialConsistencyLevel() { |
| @@ -446,4 +447,4 @@ | ||
| 446 | 447 | else |
| 447 | 448 | return queryOptions.getDefaultIdempotence(); |
| 448 | 449 | } |
| 449 | -} | |
| No newline at the end of the file | ||
| 450 | +} |
modified driver-core/src/main/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicy.java +1 −1
| @@ -114,7 +114,7 @@ | ||
| 114 | 114 | // normal consistency levels on the committing phase. So the main use case for CAS reads is probably for |
| 115 | 115 | // when you've timed out on a CAS write and want to make sure what happened. Downgrading in that case |
| 116 | 116 | // would be always wrong so we just special case to rethrow. |
| 117 | - if (cl == ConsistencyLevel.SERIAL || cl == ConsistencyLevel.LOCAL_SERIAL) | |
| 117 | + if (cl.isSerial()) | |
| 118 | 118 | return RetryDecision.rethrow(); |
| 119 | 119 | |
| 120 | 120 | if (receivedResponses < requiredResponses) { |
modified driver-core/src/test/java/com/datastax/driver/core/DataProviders.java +1 −1
| @@ -33,7 +33,7 @@ | ||
| 33 | 33 | @Override |
| 34 | 34 | public boolean apply(ConsistencyLevel input) { |
| 35 | 35 | // filter out serial CLs. |
| 36 | - return !input.equals(ConsistencyLevel.SERIAL) && !input.equals(ConsistencyLevel.LOCAL_SERIAL); | |
| 36 | + return !input.isSerial(); | |
| 37 | 37 | } |
| 38 | 38 | }).iterator(); |
| 39 | 39 |