cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xe...@apache.org
Subject svn commit: r1208748 - in /cassandra/branches/cassandra-1.0: ./ tools/stress/src/org/apache/cassandra/stress/ tools/stress/src/org/apache/cassandra/stress/operations/ tools/stress/src/org/apache/cassandra/stress/util/
Date Wed, 30 Nov 2011 20:12:09 GMT
Author: xedin
Date: Wed Nov 30 20:12:08 2011
New Revision: 1208748

URL: http://svn.apache.org/viewvc?rev=1208748&view=rev
Log:
Support TimeUUIDType column names in Stress.java tool
patch by Pavel Yaskevich; reviewed by Brandon Williams for CASSANDRA-3541

Modified:
    cassandra/branches/cassandra-1.0/CHANGES.txt
    cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/Session.java
    cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
    cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/util/Operation.java

Modified: cassandra/branches/cassandra-1.0/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/CHANGES.txt?rev=1208748&r1=1208747&r2=1208748&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/CHANGES.txt (original)
+++ cassandra/branches/cassandra-1.0/CHANGES.txt Wed Nov 30 20:12:08 2011
@@ -2,6 +2,8 @@
  * add command to stop compactions (CASSANDRA-1740)
  * filter out unavailable cipher suites when using encryption (CASSANDRA-3178)
  * (HADOOP) add old-style api support for CFIF and CFRR (CASSANDRA-2799)
+ * Support TimeUUIDType column names in Stress.java tool (CASSANDRA-3541)
+
 
 1.0.5
  * revert CASSANDRA-3407 (see CASSANDRA-3540)

Modified: cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/Session.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/Session.java?rev=1208748&r1=1208747&r2=1208748&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/Session.java
(original)
+++ cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/Session.java
Wed Nov 30 20:12:08 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
     {
@@ -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/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java?rev=1208748&r1=1208747&r2=1208748&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
(original)
+++ cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/operations/Inserter.java
Wed Nov 30 20:12:08 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/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/util/Operation.java?rev=1208748&r1=1208747&r2=1208748&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
(original)
+++ cassandra/branches/cassandra-1.0/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
Wed Nov 30 20:12:08 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();



Mime
View raw message