You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jj...@apache.org on 2017/10/31 17:35:55 UTC
cassandra git commit: Speculative retry allows more friendly params
Repository: cassandra
Updated Branches:
refs/heads/trunk bc5ad7bfa -> 3fe31ffdd
Speculative retry allows more friendly params
Patch by Michał Szczygieł; Reviewed by Jeff Jirsa for CASSANDRA-13876
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/3fe31ffd
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/3fe31ffd
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/3fe31ffd
Branch: refs/heads/trunk
Commit: 3fe31ffddb6a57e0ff89a813f724cd74133052db
Parents: bc5ad7b
Author: mszczygiel <my...@gmail.com>
Authored: Tue Oct 24 22:46:27 2017 +0200
Committer: Jeff Jirsa <jj...@apple.com>
Committed: Tue Oct 31 10:34:54 2017 -0700
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cassandra/schema/SpeculativeRetryParam.java | 13 ++-
.../schema/SpeculativeRetryParamParseTest.java | 104 +++++++++++++++++++
3 files changed, 113 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3fe31ffd/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5c0bc04..6c3eb53 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
4.0
+ * Speculative retry should allow more friendly params (CASSANDRA-13876)
* Throw exception if we send/receive repair messages to incompatible nodes (CASSANDRA-13944)
* Replace usages of MessageDigest with Guava's Hasher (CASSANDRA-13291)
* Add nodetool cmd to print hinted handoff window (CASSANDRA-13728)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3fe31ffd/src/java/org/apache/cassandra/schema/SpeculativeRetryParam.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/SpeculativeRetryParam.java b/src/java/org/apache/cassandra/schema/SpeculativeRetryParam.java
index 43447f0..d99af74 100644
--- a/src/java/org/apache/cassandra/schema/SpeculativeRetryParam.java
+++ b/src/java/org/apache/cassandra/schema/SpeculativeRetryParam.java
@@ -89,7 +89,8 @@ public final class SpeculativeRetryParam
public static SpeculativeRetryParam fromString(String value)
{
- if (value.toLowerCase(Locale.ENGLISH).endsWith("ms"))
+ String upperCaseValue = value.toUpperCase(Locale.ENGLISH);
+ if (upperCaseValue.endsWith("MS"))
{
try
{
@@ -101,12 +102,14 @@ public final class SpeculativeRetryParam
}
}
- if (value.toUpperCase(Locale.ENGLISH).endsWith(Kind.PERCENTILE.toString()))
+ if (upperCaseValue.endsWith(Kind.PERCENTILE.toString()) ||
+ upperCaseValue.endsWith("P"))
{
+ int suffixLength = upperCaseValue.endsWith("P") ? 1 : Kind.PERCENTILE.toString().length();
double threshold;
try
{
- threshold = Double.parseDouble(value.substring(0, value.length() - Kind.PERCENTILE.toString().length()));
+ threshold = Double.parseDouble(value.substring(0, value.length() - suffixLength));
}
catch (IllegalArgumentException e)
{
@@ -121,10 +124,10 @@ public final class SpeculativeRetryParam
TableParams.Option.SPECULATIVE_RETRY));
}
- if (value.equals(Kind.NONE.toString()))
+ if (upperCaseValue.equals(Kind.NONE.toString()))
return NONE;
- if (value.equals(Kind.ALWAYS.toString()))
+ if (upperCaseValue.equals(Kind.ALWAYS.toString()))
return ALWAYS;
throw new ConfigurationException(format("Invalid value %s for option '%s'", value, TableParams.Option.SPECULATIVE_RETRY));
http://git-wip-us.apache.org/repos/asf/cassandra/blob/3fe31ffd/test/unit/org/apache/cassandra/schema/SpeculativeRetryParamParseTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/schema/SpeculativeRetryParamParseTest.java b/test/unit/org/apache/cassandra/schema/SpeculativeRetryParamParseTest.java
new file mode 100644
index 0000000..284290a
--- /dev/null
+++ b/test/unit/org/apache/cassandra/schema/SpeculativeRetryParamParseTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.schema;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import org.apache.cassandra.exceptions.ConfigurationException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Enclosed.class)
+public class SpeculativeRetryParamParseTest
+{
+
+ @RunWith(Parameterized.class)
+ public static class SuccessfulParseTest
+ {
+ private final String string;
+ private final SpeculativeRetryParam expectedValue;
+
+ public SuccessfulParseTest(String string, SpeculativeRetryParam expectedValue)
+ {
+ this.string = string;
+ this.expectedValue = expectedValue;
+ }
+
+ @Parameters
+ public static Collection<Object[]> generateData()
+ {
+ return Arrays.asList(new Object[][]{
+ { "NONE", SpeculativeRetryParam.none() },
+ { "ALWAYS", SpeculativeRetryParam.always() },
+ { "10PERCENTILE", SpeculativeRetryParam.percentile(10.0) },
+ { "121.1ms", SpeculativeRetryParam.custom(121.1) },
+ { "21.7MS", SpeculativeRetryParam.custom(21.7) },
+ { "None", SpeculativeRetryParam.none() },
+ { "Always", SpeculativeRetryParam.always() },
+ { "21.1percentile", SpeculativeRetryParam.percentile(21.1) },
+ { "78.11p", SpeculativeRetryParam.percentile(78.11) }
+ }
+ );
+ }
+
+ @Test
+ public void testParameterParse()
+ {
+ assertEquals(expectedValue, SpeculativeRetryParam.fromString(string));
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class FailedParseTest
+ {
+ private final String string;
+
+ public FailedParseTest(String string)
+ {
+ this.string = string;
+ }
+
+ @Parameters
+ public static Collection<Object[]> generateData()
+ {
+ return Arrays.asList(new Object[][]{
+ { "" },
+ { "-0.1PERCENTILE" },
+ { "100.1PERCENTILE" },
+ { "xPERCENTILE" },
+ { "xyzms" },
+ { "X" }
+ }
+ );
+ }
+
+ @Test(expected = ConfigurationException.class)
+ public void testParameterParse()
+ {
+ SpeculativeRetryParam.fromString(string);
+ }
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org