From b03ce9fd479d3da9c51d118c50480ea96df0d73e Mon Sep 17 00:00:00 2001 From: ZhaoYang Date: Wed, 16 Dec 2015 15:06:06 +0100 Subject: [PATCH] Add new types to Stress patch by ZhaoYang; reviewed by Benjamin Lerer for CASSANDRA-9556 --- CHANGES.txt | 1 + .../cassandra/stress/StressProfile.java | 8 ++++ .../stress/generate/values/LocalDates.java | 43 ++++++++++++++++++ .../stress/generate/values/SmallInts.java | 38 ++++++++++++++++ .../stress/generate/values/Times.java | 37 +++++++++++++++ .../stress/generate/values/TinyInts.java | 45 +++++++++++++++++++ .../userdefined/SchemaStatement.java | 16 +++++-- .../stress/util/JavaDriverClient.java | 2 +- 8 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 tools/stress/src/org/apache/cassandra/stress/generate/values/LocalDates.java create mode 100644 tools/stress/src/org/apache/cassandra/stress/generate/values/SmallInts.java create mode 100644 tools/stress/src/org/apache/cassandra/stress/generate/values/Times.java create mode 100644 tools/stress/src/org/apache/cassandra/stress/generate/values/TinyInts.java diff --git a/CHANGES.txt b/CHANGES.txt index c969a4d998..14809600fe 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.2.5 + * Add new types to Stress (CASSANDRA-9556) * Add property to allow listening on broadcast interface (CASSANDRA-9748) * Fix regression in split size on CqlInputFormat (CASSANDRA-10835) * Better handling of SSL connection errors inter-node (CASSANDRA-10816) diff --git a/tools/stress/src/org/apache/cassandra/stress/StressProfile.java b/tools/stress/src/org/apache/cassandra/stress/StressProfile.java index 9c9b9213a1..410f666d95 100644 --- a/tools/stress/src/org/apache/cassandra/stress/StressProfile.java +++ b/tools/stress/src/org/apache/cassandra/stress/StressProfile.java @@ -531,6 +531,14 @@ public class StressProfile implements Serializable return new UUIDs(name, config); case TIMEUUID: return new TimeUUIDs(name, config); + case TINYINT: + return new TinyInts(name, config); + case SMALLINT: + return new SmallInts(name, config); + case TIME: + return new Times(name, config); + case DATE: + return new LocalDates(name, config); case SET: return new Sets(name, getGenerator(name, type.getTypeArguments().get(0), config), config); case LIST: diff --git a/tools/stress/src/org/apache/cassandra/stress/generate/values/LocalDates.java b/tools/stress/src/org/apache/cassandra/stress/generate/values/LocalDates.java new file mode 100644 index 0000000000..f079d35e50 --- /dev/null +++ b/tools/stress/src/org/apache/cassandra/stress/generate/values/LocalDates.java @@ -0,0 +1,43 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.cassandra.stress.generate.values; + +import com.datastax.driver.core.LocalDate; +import org.apache.cassandra.db.marshal.SimpleDateType; +import org.joda.time.DateTimeZone; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +public class LocalDates extends Generator +{ + + public LocalDates(String name, GeneratorConfig config) + { + super(SimpleDateType.instance, config, name, Integer.class); + } + + public Integer generate() + { + return (int)identityDistribution.next(); + } + + +} diff --git a/tools/stress/src/org/apache/cassandra/stress/generate/values/SmallInts.java b/tools/stress/src/org/apache/cassandra/stress/generate/values/SmallInts.java new file mode 100644 index 0000000000..702b6dcff3 --- /dev/null +++ b/tools/stress/src/org/apache/cassandra/stress/generate/values/SmallInts.java @@ -0,0 +1,38 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.cassandra.stress.generate.values; + +import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.ShortType; + +public class SmallInts extends Generator +{ + public SmallInts(String name, GeneratorConfig config) + { + super(ShortType.instance, config, name, Short.class); + } + + public Short generate() + { + long seed = identityDistribution.next(); + return (short)seed; + } +} diff --git a/tools/stress/src/org/apache/cassandra/stress/generate/values/Times.java b/tools/stress/src/org/apache/cassandra/stress/generate/values/Times.java new file mode 100644 index 0000000000..35bac866e6 --- /dev/null +++ b/tools/stress/src/org/apache/cassandra/stress/generate/values/Times.java @@ -0,0 +1,37 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.cassandra.stress.generate.values; + +import org.apache.cassandra.db.marshal.AbstractType; +import org.apache.cassandra.db.marshal.TimeType; + +public class Times extends Generator +{ + public Times(String name, GeneratorConfig config) + { + super(TimeType.instance, config, name, Long.class); + } + + public Long generate() + { + return identityDistribution.next(); + } +} diff --git a/tools/stress/src/org/apache/cassandra/stress/generate/values/TinyInts.java b/tools/stress/src/org/apache/cassandra/stress/generate/values/TinyInts.java new file mode 100644 index 0000000000..0fe3f3502a --- /dev/null +++ b/tools/stress/src/org/apache/cassandra/stress/generate/values/TinyInts.java @@ -0,0 +1,45 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.cassandra.stress.generate.values; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.util.Arrays; + +import org.apache.cassandra.db.marshal.ByteType; +import org.apache.cassandra.db.marshal.DecimalType; +import org.apache.cassandra.db.marshal.IntegerType; +import org.apache.cassandra.db.marshal.ShortType; +import org.apache.cassandra.stress.generate.FasterRandom; + +public class TinyInts extends Generator +{ + public TinyInts(String name, GeneratorConfig config) + { + super(ByteType.instance, config, name, Byte.class); + } + + public Byte generate() + { + long seed = identityDistribution.next(); + return (byte)seed; + } +} diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/userdefined/SchemaStatement.java b/tools/stress/src/org/apache/cassandra/stress/operations/userdefined/SchemaStatement.java index e90de23620..49891ece3d 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/userdefined/SchemaStatement.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/userdefined/SchemaStatement.java @@ -28,15 +28,15 @@ import java.util.List; import com.datastax.driver.core.BoundStatement; import com.datastax.driver.core.ColumnDefinitions; +import com.datastax.driver.core.DataType; +import com.datastax.driver.core.LocalDate; import com.datastax.driver.core.PreparedStatement; -import com.datastax.driver.core.ResultSet; import org.apache.cassandra.db.ConsistencyLevel; import org.apache.cassandra.stress.Operation; import org.apache.cassandra.stress.generate.Row; import org.apache.cassandra.stress.settings.StressSettings; import org.apache.cassandra.stress.util.JavaDriverClient; import org.apache.cassandra.stress.util.Timer; -import org.apache.cassandra.thrift.CqlResult; import org.apache.cassandra.transport.SimpleClient; public abstract class SchemaStatement extends Operation @@ -47,6 +47,7 @@ public abstract class SchemaStatement extends Operation final ConsistencyLevel cl; final int[] argumentIndex; final Object[] bindBuffer; + final ColumnDefinitions definitions; public SchemaStatement(Timer timer, StressSettings settings, DataSpec spec, PreparedStatement statement, Integer thriftId, ConsistencyLevel cl) @@ -57,8 +58,9 @@ public abstract class SchemaStatement extends Operation this.cl = cl; argumentIndex = new int[statement.getVariables().size()]; bindBuffer = new Object[argumentIndex.length]; + definitions = statement.getVariables(); int i = 0; - for (ColumnDefinitions.Definition definition : statement.getVariables()) + for (ColumnDefinitions.Definition definition : definitions) argumentIndex[i++] = spec.partitionGenerator.indexOf(definition.getName()); statement.setConsistencyLevel(JavaDriverClient.from(cl)); @@ -68,7 +70,13 @@ public abstract class SchemaStatement extends Operation { for (int i = 0 ; i < argumentIndex.length ; i++) { - bindBuffer[i] = row.get(argumentIndex[i]); + Object value = row.get(argumentIndex[i]); + if (definitions.getType(i).getName().equals(DataType.date().getName())) + { + // the java driver only accepts com.datastax.driver.core.LocalDate for CQL type "DATE" + value= LocalDate.fromDaysSinceEpoch((Integer) value); + } + bindBuffer[i] = value; if (bindBuffer[i] == null && !spec.partitionGenerator.permitNulls(argumentIndex[i])) throw new IllegalStateException(); } diff --git a/tools/stress/src/org/apache/cassandra/stress/util/JavaDriverClient.java b/tools/stress/src/org/apache/cassandra/stress/util/JavaDriverClient.java index d82ebfd499..30d0d4a719 100644 --- a/tools/stress/src/org/apache/cassandra/stress/util/JavaDriverClient.java +++ b/tools/stress/src/org/apache/cassandra/stress/util/JavaDriverClient.java @@ -95,7 +95,7 @@ public class JavaDriverClient .addContactPoint(host) .withPort(port) .withPoolingOptions(poolingOpts) - .withProtocolVersion(ProtocolVersion.V2) + .withProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED) .withoutMetrics(); // The driver uses metrics 3 with conflict with our version if (whitelist != null) clusterBuilder.withLoadBalancingPolicy(whitelist);