Fix stress with CQL3
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4cd81363 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4cd81363 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4cd81363 Branch: refs/heads/trunk Commit: 4cd813632d7e03adae1f8b519be65e0d65b7eaad Parents: aef01d1 Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Tue Feb 19 00:01:41 2013 +0100 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Tue Feb 19 00:01:41 2013 +0100 ---------------------------------------------------------------------- .../stress/operations/CqlCounterAdder.java | 6 ++-- .../stress/operations/CqlCounterGetter.java | 6 ++-- .../stress/operations/CqlIndexedRangeSlicer.java | 4 +- .../cassandra/stress/operations/CqlInserter.java | 4 +- .../stress/operations/CqlRangeSlicer.java | 6 ++-- .../cassandra/stress/operations/CqlReader.java | 4 +- .../apache/cassandra/stress/util/Operation.java | 16 +++++++++----- 7 files changed, 25 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4cd81363/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java index e1e4e9a..b0633ea 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java @@ -88,14 +88,14 @@ public class CqlCounterAdder extends Operation { Integer stmntId = getPreparedStatement(client, cqlQuery); if (session.cqlVersion.startsWith("3")) - client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key))), session.getConsistencyLevel()); + client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes())), session.getConsistencyLevel()); else - client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key)))); + client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes()))); } else { if (formattedQuery == null) - formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key))); + formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3")))); if (session.cqlVersion.startsWith("3")) client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel()); else http://git-wip-us.apache.org/repos/asf/cassandra/blob/4cd81363/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java index db99d0d..7feee5b 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java @@ -89,14 +89,14 @@ public class CqlCounterGetter extends Operation { Integer stmntId = getPreparedStatement(client, cqlQuery); if (session.cqlVersion.startsWith("3")) - result = client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key))), session.getConsistencyLevel()); + result = client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key)), session.getConsistencyLevel()); else - result = client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key)))); + result = client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key))); } else { if (formattedQuery == null) - formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key))); + formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3")))); if (session.cqlVersion.startsWith("3")) result = client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel()); http://git-wip-us.apache.org/repos/asf/cassandra/blob/4cd81363/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java index 5a18b30..b1fa85e 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java @@ -62,7 +62,7 @@ public class CqlIndexedRangeSlicer extends Operation if (session.cqlVersion.startsWith("2")) query.append(" USING CONSISTENCY ").append(session.getConsistencyLevel()); - query.append(" WHERE C1=").append(getUnQuotedCqlBlob(values.get(1).array())) + query.append(" WHERE C1=").append(getUnQuotedCqlBlob(values.get(1).array(), session.cqlVersion.startsWith("3"))) .append(" AND KEY > ? LIMIT ").append(session.getKeysPerCall()); cqlQuery = query.toString(); @@ -81,7 +81,7 @@ public class CqlIndexedRangeSlicer extends Operation String exceptionMessage = null; CqlResult results = null; String formattedQuery = null; - List<String> queryParms = Collections.singletonList(getUnQuotedCqlBlob(startOffset)); + List<String> queryParms = Collections.singletonList(getUnQuotedCqlBlob(startOffset, session.cqlVersion.startsWith("3"))); for (int t = 0; t < session.getRetryTimes(); t++) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/4cd81363/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java index 7a3eab9..ed03f1f 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java @@ -89,11 +89,11 @@ public class CqlInserter extends Operation for (int i = 0; i < session.getColumnsPerKey(); i++) { // Column value - queryParms.add(getUnQuotedCqlBlob(values.get(i % values.size()).array())); + queryParms.add(getUnQuotedCqlBlob(values.get(i % values.size()).array(), session.cqlVersion.startsWith("3"))); } String key = String.format("%0" + session.getTotalKeysLength() + "d", index); - queryParms.add(getUnQuotedCqlBlob(key)); + queryParms.add(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))); String formattedQuery = null; http://git-wip-us.apache.org/repos/asf/cassandra/blob/4cd81363/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java index 0e27f67..acf0602 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java @@ -82,14 +82,14 @@ public class CqlRangeSlicer extends Operation { Integer stmntId = getPreparedStatement(client, cqlQuery); if (session.cqlVersion.startsWith("3")) - result = client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key))), session.getConsistencyLevel()); + result = client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes())), session.getConsistencyLevel()); else - result = client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key)))); + result = client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes()))); } else { if (formattedQuery == null) - formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key))); + formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3")))); if (session.cqlVersion.startsWith("3")) result = client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel()); else http://git-wip-us.apache.org/repos/asf/cassandra/blob/4cd81363/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java index a7f9a09..58d77dd 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java @@ -80,10 +80,10 @@ public class CqlReader extends Operation List<String> queryParams = new ArrayList<String>(); if (session.columnNames != null) for (int i = 0; i < session.columnNames.size(); i++) - queryParams.add(getUnQuotedCqlBlob(session.columnNames.get(i).array())); + queryParams.add(getUnQuotedCqlBlob(session.columnNames.get(i).array(), session.cqlVersion.startsWith("3"))); byte[] key = generateKey(); - queryParams.add(getUnQuotedCqlBlob(key)); + queryParams.add(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))); String formattedQuery = null; http://git-wip-us.apache.org/repos/asf/cassandra/blob/4cd81363/tools/stress/src/org/apache/cassandra/stress/util/Operation.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/util/Operation.java b/tools/stress/src/org/apache/cassandra/stress/util/Operation.java index d5910f9..d1cfc22 100644 --- a/tools/stress/src/org/apache/cassandra/stress/util/Operation.java +++ b/tools/stress/src/org/apache/cassandra/stress/util/Operation.java @@ -230,14 +230,16 @@ public abstract class Operation System.err.println(message); } - protected String getUnQuotedCqlBlob(String term) + protected String getUnQuotedCqlBlob(String term, boolean isCQL3) { - return getUnQuotedCqlBlob(term.getBytes()); + return getUnQuotedCqlBlob(term.getBytes(), isCQL3); } - protected String getUnQuotedCqlBlob(byte[] term) + protected String getUnQuotedCqlBlob(byte[] term, boolean isCQL3) { - return Hex.bytesToHex(term); + return isCQL3 + ? "0x" + Hex.bytesToHex(term) + : Hex.bytesToHex(term); } protected List<ByteBuffer> queryParamsAsByteBuffer(List<String> queryParams) @@ -246,7 +248,9 @@ public abstract class Operation { public ByteBuffer apply(String param) { - return ByteBufferUtil.bytes(param); + if (param.startsWith("0x")) + param = param.substring(2); + return ByteBufferUtil.hexToBytes(param); } }); } @@ -270,7 +274,7 @@ public abstract class Operation for (String parm : parms) { result.append(query.substring(position, marker)); - result.append('\'').append(parm).append('\''); + result.append(parm); position = marker + 1; if (-1 == (marker = query.indexOf('?', position + 1)))