Modified: 
cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/Session.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/Session.java?rev=1210747&r1=1210746&r2=1210747&view=diff
==============================================================================
--- cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/Session.java 
(original)
+++ cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/Session.java 
Tue Dec  6 02:09:58 2011
@@ -27,9 +27,7 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.config.ConfigurationException;
-import org.apache.cassandra.db.compaction.AbstractCompactionStrategy;
-import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.db.marshal.TypeParser;
+import org.apache.cassandra.db.marshal.*;
 import org.apache.commons.cli.*;
 
 import org.apache.cassandra.db.ColumnFamilyType;
@@ -50,6 +48,8 @@ public class Session implements Serializ
     public static final String DEFAULT_COMPARATOR = "AsciiType";
     public static final String DEFAULT_VALIDATOR  = "BytesType";
 
+    private static InetAddress localInetAddress;
+
     public final AtomicInteger operations;
     public final AtomicInteger keys;
     public final AtomicLong    latency;
@@ -89,6 +89,7 @@ public class Session implements Serializ
         availableOptions.addOption("I",  "compression",          true,   
"Specify the compression to use for sstable, default:no compression");
         availableOptions.addOption("Q",  "query-names",          true,   
"Comma-separated list of column names to retrieve from each row.");
         availableOptions.addOption("Z",  "compaction-strategy",  true,   
"CompactionStrategy to use.");
+        availableOptions.addOption("U",  "comparator",           true,   
"Column Comparator to use. Currently supported types are: TimeUUIDType, 
AsciiType, UTF8Type.");
     }
 
     private int numKeys          = 1000 * 1000;
@@ -131,6 +132,8 @@ public class Session implements Serializ
     protected float sigma;
 
     public final InetAddress sendToDaemon;
+    public final String comparator;
+    public final boolean timeUUIDComparator;
 
     public Session(String[] arguments) throws IllegalArgumentException
     {
@@ -313,7 +316,7 @@ public class Session implements Serializ
                 try
                 {
                     // validate compaction strategy class
-                    CFMetaData.createCompactionSrategy(compactionStrategy);
+                    CFMetaData.createCompactionStrategy(compactionStrategy);
                 }
                 catch (ConfigurationException e)
                 {
@@ -321,6 +324,35 @@ public class Session implements Serializ
                     System.exit(1);
                 }
             }
+
+            if (cmd.hasOption("U"))
+            {
+                AbstractType parsed = null;
+
+                try
+                {
+                    parsed = TypeParser.parse(cmd.getOptionValue("U"));
+                }
+                catch (ConfigurationException e)
+                {
+                    System.err.println(e.getMessage());
+                    System.exit(1);
+                }
+
+                comparator = cmd.getOptionValue("U");
+                timeUUIDComparator = parsed instanceof TimeUUIDType;
+
+                if (!(parsed instanceof TimeUUIDType || parsed instanceof 
AsciiType || parsed instanceof UTF8Type))
+                {
+                    System.err.println("Currently supported types are: 
TimeUUIDType, AsciiType, UTF8Type.");
+                    System.exit(1);
+                }
+            }
+            else
+            {
+                comparator = null;
+                timeUUIDComparator = false;
+            }
         }
         catch (ParseException e)
         {
@@ -464,6 +496,7 @@ public class Session implements Serializ
     public void createKeySpaces()
     {
         KsDef keyspace = new KsDef();
+        String defaultComparator = comparator == null ? DEFAULT_COMPARATOR : 
comparator;
 
         // column family for standard columns
         CfDef standardCfDef = new CfDef("Keyspace1", "Standard1");
@@ -471,7 +504,7 @@ public class Session implements Serializ
         if (compression != null)
             compressionOptions.put("sstable_compression", compression);
 
-        standardCfDef.setComparator_type(DEFAULT_COMPARATOR)
+        standardCfDef.setComparator_type(defaultComparator)
                      .setDefault_validation_class(DEFAULT_VALIDATOR)
                      .setCompression_options(compressionOptions);
 
@@ -485,7 +518,7 @@ public class Session implements Serializ
         // column family with super columns
         CfDef superCfDef = new CfDef("Keyspace1", 
"Super1").setColumn_type("Super");
         superCfDef.setComparator_type(DEFAULT_COMPARATOR)
-                  .setSubcomparator_type(DEFAULT_COMPARATOR)
+                  .setSubcomparator_type(defaultComparator)
                   .setDefault_validation_class(DEFAULT_VALIDATOR)
                   .setCompression_options(compressionOptions);
 
@@ -574,4 +607,20 @@ public class Session implements Serializ
         return client;
     }
 
+    public static InetAddress getLocalAddress()
+    {
+        if (localInetAddress == null)
+        {
+            try
+            {
+                localInetAddress = InetAddress.getLocalHost();
+            }
+            catch (UnknownHostException e)
+            {
+                throw new RuntimeException(e);
+            }
+        }
+
+        return localInetAddress;
+    }
 }

Modified: 
cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java?rev=1210747&r1=1210746&r2=1210747&view=diff
==============================================================================
--- 
cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
 (original)
+++ 
cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
 Tue Dec  6 02:09:58 2011
@@ -52,9 +52,9 @@ public class Inserter extends Operation
 
         for (int i = 0; i < session.getColumnsPerKey(); i++)
         {
-            String columnName = ("C" + Integer.toString(i));
-            ByteBuffer columnValue = values.get(i % values.size());
-            columns.add(new 
Column(ByteBufferUtil.bytes(columnName)).setValue(columnValue).setTimestamp(System.currentTimeMillis()));
+            columns.add(new Column(columnName(i, session.timeUUIDComparator))
+                                .setValue(values.get(i % values.size()))
+                                .setTimestamp(System.currentTimeMillis()));
         }
 
         if (session.getColumnFamilyType() == ColumnFamilyType.Super)

Modified: 
cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/util/Operation.java?rev=1210747&r1=1210746&r2=1210747&view=diff
==============================================================================
--- 
cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
 (original)
+++ 
cassandra/trunk/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
 Tue Dec  6 02:09:58 2011
@@ -27,11 +27,14 @@ import java.util.Random;
 
 import static com.google.common.base.Charsets.UTF_8;
 
+import org.apache.cassandra.db.marshal.TimeUUIDType;
 import org.apache.cassandra.stress.Session;
 import org.apache.cassandra.stress.Stress;
 import org.apache.cassandra.thrift.Cassandra;
 import org.apache.cassandra.thrift.InvalidRequestException;
+import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.UUIDGen;
 
 public abstract class Operation
 {
@@ -200,6 +203,13 @@ public abstract class Operation
         return result.toString();
     }
 
+    protected ByteBuffer columnName(int index, boolean timeUUIDComparator)
+    {
+        return timeUUIDComparator
+                ? 
TimeUUIDType.instance.decompose(UUIDGen.makeType1UUIDFromHost(Session.getLocalAddress()))
+                : ByteBufferUtil.bytes(String.format("C%d", index));
+    }
+
     protected String getExceptionMessage(Exception e)
     {
         String className = e.getClass().getSimpleName();


Reply via email to