Permalink
Browse files

Port tool to cassandra 0.8.

And automate schema creation
  • Loading branch information...
1 parent a59e105 commit 2cfc36f4881e8fb86118024e67a17932d9d65a5b @patricioe patricioe committed Sep 2, 2011
View
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target
View
@@ -4,7 +4,7 @@
<groupId>com.riptano.cassandra.stress</groupId>
<artifactId>cassandra-stress</artifactId>
- <version>0.7_28</version>
+ <version>0.8.3_1</version>
<packaging>jar</packaging>
<name>cassandra-stress</name>
@@ -108,9 +108,14 @@
<dependency>
<groupId>me.prettyprint</groupId>
<artifactId>hector-core</artifactId>
- <version>0.7.0-31-SNAPSHOT</version>
+ <version>0.8.0-3-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.apache.cassandra</groupId>
+ <artifactId>cassandra-all</artifactId>
+ <version>0.8.3</version>
+ </dependency>
+ <dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
@@ -1,6 +1,5 @@
package com.riptano.cassandra.stress;
-import java.util.concurrent.CountDownLatch;
public class CommandFactory {
@@ -1,7 +1,6 @@
package com.riptano.cassandra.stress;
import java.util.Date;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -31,7 +30,7 @@
private Operation previousOperation;
public CommandRunner(Set<CassandraHost> cassandraHosts) {
- latencies = new ConcurrentHashMap<CassandraHost, LatencyTracker>();
+ latencies = new ConcurrentHashMap<CassandraHost, LatencyTracker>();
for (CassandraHost host : cassandraHosts) {
latencies.put(host, new LatencyTracker());
}
@@ -1,11 +1,16 @@
package com.riptano.cassandra.stress;
+import java.util.Arrays;
+
import jline.ConsoleReader;
import me.prettyprint.cassandra.model.ConfigurableConsistencyLevel;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
+import me.prettyprint.cassandra.service.ThriftKsDef;
import me.prettyprint.hector.api.Cluster;
-import me.prettyprint.hector.api.ConsistencyLevelPolicy;
import me.prettyprint.hector.api.HConsistencyLevel;
+import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
+import me.prettyprint.hector.api.ddl.ComparatorType;
+import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.factory.HFactory;
import org.apache.commons.cli.CommandLine;
@@ -23,7 +28,7 @@
*/
public class Stress {
- private static Logger log = LoggerFactory.getLogger(Stress.class);
+ private static Logger log = LoggerFactory.getLogger(Stress.class);
private CommandArgs commandArgs;
private CommandRunner commandRunner;
@@ -177,11 +182,23 @@ private void initializeCommandRunner(CommandLine cmd) throws Exception {
}
Cluster cluster = HFactory.createCluster("StressCluster", cassandraHostConfigurator);
-
- commandArgs.keyspace = clc == null ? HFactory.createKeyspace("StressKeyspace", cluster) :
- HFactory.createKeyspace("StressKeyspace", cluster, clc);
+
+ // Populate schema if needed.
+ KeyspaceDefinition ksDef = cluster.describeKeyspace(commandArgs.workingKeyspace);
+ if (ksDef == null) {
+ ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(
+ commandArgs.workingKeyspace, commandArgs.workingColumnFamily, ComparatorType.BYTESTYPE);
+
+ KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(
+ commandArgs.workingKeyspace, ThriftKsDef.DEF_STRATEGY_CLASS, 1, Arrays.asList(cfDef));
+
+ cluster.addKeyspace(newKeyspace, true);
+ }
+
+ commandArgs.keyspace = clc == null ? HFactory.createKeyspace(commandArgs.workingKeyspace, cluster) :
+ HFactory.createKeyspace(commandArgs.workingKeyspace, cluster, clc);
commandRunner = new CommandRunner(cluster.getKnownPoolHosts(true));
- if ( commandArgs.validateCommand() && commandArgs.getOperation() != Operation.REPLAY) {
+ if ( commandArgs.validateCommand() && commandArgs.getOperation() != Operation.REPLAY) {
commandRunner.processCommand(commandArgs);
} else {
throw new IllegalArgumentException();
@@ -1,11 +1,6 @@
package com.riptano.cassandra.stress;
import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-
-import org.apache.cassandra.utils.LatencyTracker;
-
-import me.prettyprint.hector.api.Keyspace;
public abstract class StressCommand implements Callable<Void> {

0 comments on commit 2cfc36f

Please sign in to comment.