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 2020/07/27 15:56:31 UTC

[lucene-solr] branch reference_impl updated: @385 Harden.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/reference_impl by this push:
     new f2e832d  @385 Harden.
f2e832d is described below

commit f2e832d85588ae56016d3f6f7793f4d2077c4483
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Mon Jul 27 10:56:08 2020 -0500

    @385 Harden.
---
 .../org/apache/solr/cloud/TestRandomFlRTGCloud.java  |  2 +-
 .../org/apache/solr/util/OrderedExecutorTest.java    | 20 ++++++++++++++------
 .../org/apache/solr/common/util/OrderedExecutor.java |  9 ++++-----
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/solr/core/src/test/org/apache/solr/cloud/TestRandomFlRTGCloud.java b/solr/core/src/test/org/apache/solr/cloud/TestRandomFlRTGCloud.java
index 8e51068..902960b 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestRandomFlRTGCloud.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestRandomFlRTGCloud.java
@@ -209,7 +209,7 @@ public class TestRandomFlRTGCloud extends SolrCloudTestCase {
 
     final int maxNumDocs = atLeast( TEST_NIGHTLY ? 100 : 35);
     final int numSeedDocs = random().nextInt(maxNumDocs / 10); // at most ~10% of the max possible docs
-    final int numIters = atLeast(maxNumDocs * (TEST_NIGHTLY ? 10 : 2));
+    final int numIters = atLeast(maxNumDocs * (TEST_NIGHTLY ? 10 : 3));
     final SolrInputDocument[] knownDocs = new SolrInputDocument[maxNumDocs];
 
     log.info("Starting {} iters by seeding {} of {} max docs",
diff --git a/solr/core/src/test/org/apache/solr/util/OrderedExecutorTest.java b/solr/core/src/test/org/apache/solr/util/OrderedExecutorTest.java
index d78aa68..91cd6ca 100644
--- a/solr/core/src/test/org/apache/solr/util/OrderedExecutorTest.java
+++ b/solr/core/src/test/org/apache/solr/util/OrderedExecutorTest.java
@@ -30,9 +30,11 @@ import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.solr.SolrTestCase;
 import org.apache.solr.common.ParWork;
+import org.apache.solr.common.ParWorkExecutor;
 import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.common.util.OrderedExecutor;
 import org.junit.Test;
@@ -45,13 +47,19 @@ public class OrderedExecutorTest extends SolrTestCase {
 
   @Test
   public void testExecutionInOrder() {
-    OrderedExecutor orderedExecutor = new OrderedExecutor(TEST_NIGHTLY ? 10 : 3, ExecutorUtil.newMDCAwareCachedThreadPool("executeInOrderTest"));
     IntBox intBox = new IntBox();
-    for (int i = 0; i < 100; i++) {
-      orderedExecutor.execute(1, () -> intBox.value++);
+    OrderedExecutor orderedExecutor = new OrderedExecutor(TEST_NIGHTLY ? 10 : 3, new ParWorkExecutor("executeInOrderTest", TEST_NIGHTLY ? 10 : 3));
+    try {
+      for (int i = 0; i < 100; i++) {
+        orderedExecutor.execute(1, () -> intBox.value.incrementAndGet());
+      }
+      orderedExecutor.shutdown();
+      orderedExecutor.awaitTermination();
+      assertEquals(100, intBox.value.get());
+    } finally {
+      ParWork.close(orderedExecutor);
     }
-    ParWork.close(orderedExecutor);
-    assertEquals(intBox.value, 100);
+
   }
 
   @Test
@@ -221,6 +229,6 @@ public class OrderedExecutorTest extends SolrTestCase {
   }
 
   private static class IntBox {
-    int value;
+    final AtomicInteger value = new AtomicInteger();
   }
 }
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/OrderedExecutor.java b/solr/solrj/src/java/org/apache/solr/common/util/OrderedExecutor.java
index 7a863e5..729ca37 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/OrderedExecutor.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/OrderedExecutor.java
@@ -24,6 +24,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.Semaphore;
 
+import org.apache.solr.common.AlreadyClosedException;
 import org.apache.solr.common.ParWork;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.util.ExecutorUtil;
@@ -60,12 +61,10 @@ public class OrderedExecutor implements Executor {
       sparseStripedLock.add(lockId);
     } catch (InterruptedException e) {
       ParWork.propegateInterrupt(e);
-      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
+      throw new AlreadyClosedException(e);
     }
 
     try {
-      if (delegate.isShutdown()) throw new RejectedExecutionException();
-
       delegate.execute(() -> {
         try {
           command.run();
@@ -73,7 +72,7 @@ public class OrderedExecutor implements Executor {
           sparseStripedLock.remove(lockId);
         }
       });
-    } catch (RejectedExecutionException e) {
+    } catch (Exception e) {
       sparseStripedLock.remove(lockId);
       throw e;
     }
@@ -112,7 +111,7 @@ public class OrderedExecutor implements Executor {
         // myLock was successfully inserted
       }
       // won the lock
-      sizeSemaphore.acquire();
+      sizeSemaphore.acquireUninterruptibly();
     }
 
     public void remove(T t) {