mirror of https://github.com/apache/cassandra
Fix stress with CQL3
This commit is contained in:
parent
aef01d1627
commit
4cd813632d
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
|
|
|
|||
Loading…
Reference in New Issue