Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 487871187C for ; Fri, 20 Jun 2014 22:49:15 +0000 (UTC) Received: (qmail 64301 invoked by uid 500); 20 Jun 2014 22:49:15 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 64264 invoked by uid 500); 20 Jun 2014 22:49:14 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 64241 invoked by uid 99); 20 Jun 2014 22:49:14 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jun 2014 22:49:14 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A48F19894B0; Fri, 20 Jun 2014 22:49:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aleksey@apache.org To: commits@cassandra.apache.org Date: Fri, 20 Jun 2014 22:49:14 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: (ninja) Deduplicate BatchStatement hasConditions inference logic Repository: cassandra Updated Branches: refs/heads/trunk e88c83006 -> c1ce969c6 (ninja) Deduplicate BatchStatement hasConditions inference logic Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/bf9b49ca Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/bf9b49ca Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/bf9b49ca Branch: refs/heads/trunk Commit: bf9b49ca8443b020cee6f0e1550763fed5a36363 Parents: ee401cf Author: Aleksey Yeschenko Authored: Fri Jun 20 15:46:16 2014 -0700 Committer: Aleksey Yeschenko Committed: Fri Jun 20 15:46:16 2014 -0700 ---------------------------------------------------------------------- .../cql3/statements/BatchStatement.java | 20 ++++++++------------ .../transport/messages/BatchMessage.java | 15 +++++---------- 2 files changed, 13 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/bf9b49ca/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 b7d69cc..0521485 100644 --- a/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java @@ -64,8 +64,12 @@ public class BatchStatement implements CQLStatement, MeasurableForPreparedCache * @param statements a list of UpdateStatements * @param attrs additional attributes for statement (CL, timestamp, timeToLive) */ - public BatchStatement(int boundTerms, Type type, List statements, Attributes attrs, boolean hasConditions) + public BatchStatement(int boundTerms, Type type, List statements, Attributes attrs) { + boolean hasConditions = false; + for (ModificationStatement statement : statements) + hasConditions |= statement.hasConditions(); + this.boundTerms = boundTerms; this.type = type; this.statements = statements; @@ -304,7 +308,7 @@ public class BatchStatement implements CQLStatement, MeasurableForPreparedCache String cfName = null; ColumnFamily updates = null; CQL3CasConditions conditions = null; - Set columnsWithConditions = new LinkedHashSet(); + Set columnsWithConditions = new LinkedHashSet<>(); for (int i = 0; i < statements.size(); i++) { @@ -397,21 +401,13 @@ public class BatchStatement implements CQLStatement, MeasurableForPreparedCache VariableSpecifications boundNames = getBoundVariables(); List statements = new ArrayList<>(parsedStatements.size()); - boolean hasConditions = false; - for (ModificationStatement.Parsed parsed : parsedStatements) - { - ModificationStatement stmt = parsed.prepare(boundNames); - if (stmt.hasConditions()) - hasConditions = true; - - statements.add(stmt); - } + statements.add(parsed.prepare(boundNames)); Attributes prepAttrs = attrs.prepare("[batch]", "[batch]"); prepAttrs.collectMarkerSpecification(boundNames); - BatchStatement batchStatement = new BatchStatement(boundNames.size(), type, statements, prepAttrs, hasConditions); + BatchStatement batchStatement = new BatchStatement(boundNames.size(), type, statements, prepAttrs); batchStatement.validate(); return new ParsedStatement.Prepared(batchStatement, boundNames); http://git-wip-us.apache.org/repos/asf/cassandra/blob/bf9b49ca/src/java/org/apache/cassandra/transport/messages/BatchMessage.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/transport/messages/BatchMessage.java b/src/java/org/apache/cassandra/transport/messages/BatchMessage.java index c199a62..19fa6aa 100644 --- a/src/java/org/apache/cassandra/transport/messages/BatchMessage.java +++ b/src/java/org/apache/cassandra/transport/messages/BatchMessage.java @@ -29,9 +29,9 @@ import org.apache.cassandra.cql3.*; import org.apache.cassandra.cql3.statements.BatchStatement; import org.apache.cassandra.cql3.statements.ModificationStatement; import org.apache.cassandra.cql3.statements.ParsedStatement; -import org.apache.cassandra.db.ConsistencyLevel; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.exceptions.PreparedQueryNotFoundException; +import org.apache.cassandra.service.ClientState; import org.apache.cassandra.service.QueryState; import org.apache.cassandra.tracing.Tracing; import org.apache.cassandra.transport.*; @@ -169,9 +169,8 @@ public class BatchMessage extends Message.Request Tracing.instance.begin("Execute batch of CQL3 queries", Collections.emptyMap()); } - QueryHandler handler = state.getClientState().getCQLQueryHandler(); + QueryHandler handler = ClientState.getCQLQueryHandler(); List prepared = new ArrayList<>(queryOrIdList.size()); - boolean hasConditions = false; for (int i = 0; i < queryOrIdList.size(); i++) { Object query = queryOrIdList.get(i); @@ -202,20 +201,16 @@ public class BatchMessage extends Message.Request { ParsedStatement.Prepared p = prepared.get(i); batchOptions.forStatement(i).prepare(p.boundNames); - CQLStatement statement = p.statement; - if (!(statement instanceof ModificationStatement)) + if (!(p.statement instanceof ModificationStatement)) throw new InvalidRequestException("Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed."); - ModificationStatement mst = (ModificationStatement)statement; - hasConditions |= mst.hasConditions(); - - statements.add(mst); + statements.add((ModificationStatement)p.statement); } // Note: It's ok at this point to pass a bogus value for the number of bound terms in the BatchState ctor // (and no value would be really correct, so we prefer passing a clearly wrong one). - BatchStatement batch = new BatchStatement(-1, type, statements, Attributes.none(), hasConditions); + BatchStatement batch = new BatchStatement(-1, type, statements, Attributes.none()); Message.Response response = handler.processBatch(batch, state, batchOptions); if (tracingId != null)