cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bened...@apache.org
Subject [1/2] git commit: Fix serialization of command ratios in cassandra-stress/stressd
Date Fri, 01 Aug 2014 20:51:14 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 3faf88cd0 -> 4f778d2e7


Fix serialization of command ratios in cassandra-stress/stressd

patch by rspitzer; reviewed by benedict for CASSANDRA-7559


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/24f6f038
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/24f6f038
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/24f6f038

Branch: refs/heads/cassandra-2.1
Commit: 24f6f038ef88d8f8b3ef608148ae5a848b302ac5
Parents: a182ea0
Author: Benedict Elliott Smith <benedict@apache.org>
Authored: Fri Aug 1 21:48:19 2014 +0100
Committer: Benedict Elliott Smith <benedict@apache.org>
Committed: Fri Aug 1 21:48:19 2014 +0100

----------------------------------------------------------------------
 .../stress/settings/OptionAnyProbabilities.java        |  9 +++------
 .../stress/settings/OptionEnumProbabilities.java       |  9 +++++----
 .../settings/SettingsCommandPreDefinedMixed.java       |  9 +++++++--
 .../cassandra/stress/settings/SettingsCommandUser.java | 13 +++++++++----
 4 files changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/24f6f038/tools/stress/src/org/apache/cassandra/stress/settings/OptionAnyProbabilities.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/OptionAnyProbabilities.java
b/tools/stress/src/org/apache/cassandra/stress/settings/OptionAnyProbabilities.java
index 4e2ad64..b685294 100644
--- a/tools/stress/src/org/apache/cassandra/stress/settings/OptionAnyProbabilities.java
+++ b/tools/stress/src/org/apache/cassandra/stress/settings/OptionAnyProbabilities.java
@@ -27,8 +27,8 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.HashMap;
 
-import org.apache.commons.math3.util.Pair;
 
 public final class OptionAnyProbabilities extends OptionMulti
 {
@@ -88,12 +88,9 @@ public final class OptionAnyProbabilities extends OptionMulti
         return Arrays.asList(ratios);
     }
 
-    List<Pair<String, Double>> ratios()
+    Map<String, Double> ratios()
     {
-        List<Pair<String, Double>> ratiosOut = new ArrayList<>();
-        for (Map.Entry<String, Double> e : ratios.options.entrySet())
-            ratiosOut.add(new Pair<String, Double>(e.getKey(), e.getValue()));
-        return ratiosOut;
+        return ratios.options;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/24f6f038/tools/stress/src/org/apache/cassandra/stress/settings/OptionEnumProbabilities.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/OptionEnumProbabilities.java
b/tools/stress/src/org/apache/cassandra/stress/settings/OptionEnumProbabilities.java
index b1c5c49..71d7a8d 100644
--- a/tools/stress/src/org/apache/cassandra/stress/settings/OptionEnumProbabilities.java
+++ b/tools/stress/src/org/apache/cassandra/stress/settings/OptionEnumProbabilities.java
@@ -23,8 +23,9 @@ package org.apache.cassandra.stress.settings;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
 
-import org.apache.commons.math3.util.Pair;
 
 public final class OptionEnumProbabilities<T> extends OptionMulti
 {
@@ -67,15 +68,15 @@ public final class OptionEnumProbabilities<T> extends OptionMulti
         return options;
     }
 
-    List<Pair<T, Double>> ratios()
+    Map<T, Double> ratios()
     {
         List<? extends Option> ratiosIn = setByUser() ? optionsSetByUser() : defaultOptions();
-        List<Pair<T, Double>> ratiosOut = new ArrayList<>();
+        Map<T, Double> ratiosOut = new HashMap<>();
         for (Option opt : ratiosIn)
         {
             OptMatcher<T> optMatcher = (OptMatcher<T>) opt;
             double d = Double.parseDouble(optMatcher.value());
-            ratiosOut.add(new Pair<>(optMatcher.opt, d));
+            ratiosOut.put(optMatcher.opt, d);
         }
         return ratiosOut;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/24f6f038/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandPreDefinedMixed.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandPreDefinedMixed.java
b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandPreDefinedMixed.java
index e5d4f80..49d3c56 100644
--- a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandPreDefinedMixed.java
+++ b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandPreDefinedMixed.java
@@ -23,6 +23,7 @@ package org.apache.cassandra.stress.settings;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.cassandra.stress.Operation;
 import org.apache.cassandra.stress.generate.DistributionFactory;
@@ -39,7 +40,7 @@ public class SettingsCommandPreDefinedMixed extends SettingsCommandPreDefined
 {
 
     // Ratios for selecting commands - index for each Command, NaN indicates the command
is not requested
-    private final List<Pair<Command, Double>> ratios;
+    private final Map<Command, Double> ratios;
     private final DistributionFactory clustering;
 
     public SettingsCommandPreDefinedMixed(Options options)
@@ -54,7 +55,11 @@ public class SettingsCommandPreDefinedMixed extends SettingsCommandPreDefined
 
     public OpDistributionFactory getFactory(final StressSettings settings)
     {
-        return new SampledOpDistributionFactory<Command>(ratios, clustering)
+        final List<Pair<Command,Double>> mathPairs = new ArrayList<>();
+        for (Map.Entry entry: ratios.entrySet())
+            mathPairs.add(new Pair(entry.getKey(),entry.getValue()));
+
+        return new SampledOpDistributionFactory<Command>(mathPairs, clustering)
         {
             protected Operation get(Timer timer, PartitionGenerator generator, Command key)
             {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/24f6f038/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java
b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java
index f36296e..08d538e 100644
--- a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java
+++ b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsCommandUser.java
@@ -24,8 +24,7 @@ package org.apache.cassandra.stress.settings;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
-
-import org.apache.commons.math3.util.Pair;
+import java.util.Map;
 
 import org.apache.cassandra.stress.Operation;
 import org.apache.cassandra.stress.StressProfile;
@@ -35,12 +34,14 @@ import org.apache.cassandra.stress.operations.OpDistributionFactory;
 import org.apache.cassandra.stress.operations.SampledOpDistributionFactory;
 import org.apache.cassandra.stress.util.Timer;
 
+import org.apache.commons.math3.util.Pair;
+
 // Settings unique to the mixed command type
 public class SettingsCommandUser extends SettingsCommand
 {
 
     // Ratios for selecting commands - index for each Command, NaN indicates the command
is not requested
-    private final List<Pair<String, Double>> ratios;
+    private final Map<String, Double> ratios;
     private final DistributionFactory clustering;
     public final StressProfile profile;
 
@@ -58,7 +59,11 @@ public class SettingsCommandUser extends SettingsCommand
 
     public OpDistributionFactory getFactory(final StressSettings settings)
     {
-        return new SampledOpDistributionFactory<String>(ratios, clustering)
+        final List<Pair<String,Double>> mathPairs = new ArrayList<>();
+        for (Map.Entry entry: ratios.entrySet())
+            mathPairs.add(new Pair(entry.getKey(), entry.getValue()));
+
+        return new SampledOpDistributionFactory<String>(mathPairs, clustering)
         {
             protected Operation get(Timer timer, PartitionGenerator generator, String key)
             {


Mime
View raw message