Repository: cassandra Updated Branches: refs/heads/trunk 2629c30a9 -> 6cecbf914
Warn when timestamps are provided on CAS batch patch by slebresne; reviewed by iamaleksey for CASSANDRA-7067 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/32e1b16b Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/32e1b16b Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/32e1b16b Branch: refs/heads/trunk Commit: 32e1b16b81af5afb244860af9dad368575d69988 Parents: b4a3b52 Author: Sylvain Lebresne <[email protected]> Authored: Wed May 7 10:27:04 2014 +0200 Committer: Sylvain Lebresne <[email protected]> Committed: Wed May 7 10:27:04 2014 +0200 ---------------------------------------------------------------------- CHANGES.txt | 4 ++++ .../cql3/statements/BatchStatement.java | 24 +++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/32e1b16b/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 517f0ab..1e60fc3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,7 @@ +2.0.9 + * Warn when 'USING TIMESTAMP' is used on a CAS BATCH (CASSANDRA-7067) + + 2.0.8 * Correctly delete scheduled range xfers (CASSANDRA-7143) * Make batchlog replica selection rack-aware (CASSANDRA-6551) http://git-wip-us.apache.org/repos/asf/cassandra/blob/32e1b16b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java index 8e61ae5..c03548b 100644 --- a/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java @@ -41,6 +41,9 @@ import org.apache.cassandra.transport.messages.ResultMessage; */ public class BatchStatement implements CQLStatement, MeasurableForPreparedCache { + private static boolean loggedCASTimestamp = false; + private static boolean loggedCounterTimestamp = false; + public static enum Type { LOGGED, UNLOGGED, COUNTER @@ -102,9 +105,28 @@ public class BatchStatement implements CQLStatement, MeasurableForPreparedCache if (attrs.isTimeToLiveSet()) throw new InvalidRequestException("Global TTL on the BATCH statement is not supported."); + boolean timestampSet = attrs.isTimestampSet(); + if (timestampSet) + { + if (hasConditions && !loggedCASTimestamp) + { + logger.warn("Detected use of 'USING TIMESTAMP' on a BATCH with conditions. This is invalid, " + + "custom timestamps are not allowed when conditions are used and the timestamp has been ignored. " + + "Such queries will be rejected in Cassandra 2.1+ - please fix your queries before then."); + loggedCASTimestamp = true; + } + if (type == Type.COUNTER && !loggedCounterTimestamp) + { + logger.warn("Detected use of 'USING TIMESTAMP' in a counter BATCH. This is invalid " + + "because counters do not use timestamps, and the timestamp has been ignored. " + + "Such queries will be rejected in Cassandra 2.1+ - please fix your queries before then."); + loggedCounterTimestamp = true; + } + } + for (ModificationStatement statement : statements) { - if (attrs.isTimestampSet() && statement.isTimestampSet()) + if (timestampSet && statement.isTimestampSet()) throw new InvalidRequestException("Timestamp must be set either on BATCH or individual statements"); } }
