You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2015/03/24 14:04:35 UTC
svn commit: r1668872 - in /lucene/dev/branches/branch_5x: ./ solr/
solr/CHANGES.txt solr/core/
solr/core/src/java/org/apache/solr/cloud/ActionThrottle.java
solr/core/src/test/org/apache/solr/cloud/ActionThrottleTest.java
Author: markrmiller
Date: Tue Mar 24 13:04:35 2015
New Revision: 1668872
URL: http://svn.apache.org/r1668872
Log:
SOLR-7285: ActionThrottle will not pause if getNanoTime first returns 0.
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ActionThrottle.java
lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ActionThrottleTest.java
Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1668872&r1=1668871&r2=1668872&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Tue Mar 24 13:04:35 2015
@@ -218,6 +218,9 @@ Bug Fixes
* SOLR-7092: Stop the HDFS lease recovery retries in HdfsTransactionLog on close and try
to avoid lease recovery on closed files. (Mark Miller)
+* SOLR-7285: ActionThrottle will not pause if getNanoTime first returns 0.
+ (Mark Miller, Gregory Chanan)
+
Optimizations
----------------------
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ActionThrottle.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ActionThrottle.java?rev=1668872&r1=1668871&r2=1668872&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ActionThrottle.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ActionThrottle.java Tue Mar 24 13:04:35 2015
@@ -26,25 +26,45 @@ import org.slf4j.LoggerFactory;
public class ActionThrottle {
private static Logger log = LoggerFactory.getLogger(ActionThrottle.class);
- private volatile long lastActionStartedAt;
- private volatile long minMsBetweenActions;
+ private volatile Long lastActionStartedAt;
+ private volatile Long minMsBetweenActions;
private final String name;
+
+ private final NanoTimeSource nanoTimeSource;
+
+ public interface NanoTimeSource {
+ long getTime();
+ }
+
+ private static class DefaultNanoTimeSource implements NanoTimeSource {
+ @Override
+ public long getTime() {
+ return System.nanoTime();
+ }
+ }
public ActionThrottle(String name, long minMsBetweenActions) {
this.name = name;
this.minMsBetweenActions = minMsBetweenActions;
+ this.nanoTimeSource = new DefaultNanoTimeSource();
+ }
+
+ public ActionThrottle(String name, long minMsBetweenActions, NanoTimeSource nanoTimeSource) {
+ this.name = name;
+ this.minMsBetweenActions = minMsBetweenActions;
+ this.nanoTimeSource = nanoTimeSource;
}
public void markAttemptingAction() {
- lastActionStartedAt = System.nanoTime();
+ lastActionStartedAt = nanoTimeSource.getTime();
}
public void minimumWaitBetweenActions() {
- if (lastActionStartedAt == 0) {
+ if (lastActionStartedAt == null) {
return;
}
- long diff = System.nanoTime() - lastActionStartedAt;
+ long diff = nanoTimeSource.getTime() - lastActionStartedAt;
int diffMs = (int) TimeUnit.MILLISECONDS.convert(diff, TimeUnit.NANOSECONDS);
long minNsBetweenActions = TimeUnit.NANOSECONDS.convert(minMsBetweenActions, TimeUnit.MILLISECONDS);
log.info("The last {} attempt started {}ms ago.", name, diffMs);
@@ -53,7 +73,7 @@ public class ActionThrottle {
if (diffMs > 0 && diff < minNsBetweenActions) {
sleep = (int) TimeUnit.MILLISECONDS.convert(minNsBetweenActions - diff, TimeUnit.NANOSECONDS);
} else if (diffMs == 0) {
- sleep = (int) minMsBetweenActions;
+ sleep = minMsBetweenActions.intValue();
}
if (sleep > 0) {
Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ActionThrottleTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ActionThrottleTest.java?rev=1668872&r1=1668871&r2=1668872&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ActionThrottleTest.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ActionThrottleTest.java Tue Mar 24 13:04:35 2015
@@ -17,9 +17,12 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
+import java.util.Arrays;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.cloud.ActionThrottle.NanoTimeSource;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,6 +30,21 @@ import org.slf4j.LoggerFactory;
public class ActionThrottleTest extends SolrTestCaseJ4 {
protected static Logger log = LoggerFactory.getLogger(ActionThrottleTest.class);
+ static class TestNanoTimeSource implements NanoTimeSource {
+
+ private List<Long> returnValues;
+ private int index = 0;
+
+ public TestNanoTimeSource(List<Long> returnValues) {
+ this.returnValues = returnValues;
+ }
+
+ @Override
+ public long getTime() {
+ return returnValues.get(index++);
+ }
+
+ }
@Test
public void testBasics() throws Exception {
@@ -59,5 +77,21 @@ public class ActionThrottleTest extends
assertTrue(elaspsedTime + "ms", elaspsedTime >= 995);
}
+
+ @Test
+ public void testAZeroNanoTimeReturnInWait() throws Exception {
+
+ ActionThrottle at = new ActionThrottle("test", 1000, new TestNanoTimeSource(Arrays.asList(new Long[]{0L, 10L})));
+ long start = System.nanoTime();
+
+ at.markAttemptingAction();
+
+ at.minimumWaitBetweenActions();
+
+ long elaspsedTime = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
+
+ assertTrue(elaspsedTime + "ms", elaspsedTime >= 995);
+
+ }
}