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/08/11 22:56:24 UTC

[lucene-solr] 01/03: @511 Some opti's.

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

commit de03e0eba66e738e80916fabf511e7b1972e1f26
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Tue Aug 11 17:40:10 2020 -0500

    @511 Some opti's.
---
 .../src/java/org/apache/solr/api/AnnotatedApi.java | 13 ++++++-----
 .../src/java/org/apache/solr/common/ParWork.java   | 26 +++++++++++++---------
 .../apache/solr/common/cloud/ZkStateReader.java    | 15 +++++--------
 3 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/api/AnnotatedApi.java b/solr/core/src/java/org/apache/solr/api/AnnotatedApi.java
index 32a434e..069b89f 100644
--- a/solr/core/src/java/org/apache/solr/api/AnnotatedApi.java
+++ b/solr/core/src/java/org/apache/solr/api/AnnotatedApi.java
@@ -64,7 +64,7 @@ public class AnnotatedApi extends Api implements PermissionNameProvider {
 
   public static final String ERR = "Error executing commands :";
   private EndPoint endPoint;
-  private final Map<String, Cmd> commands ;
+  private final Map<String, Cmd> commands;
   private final Cmd singletonCommand;
   private final Api fallback;
 
@@ -93,8 +93,9 @@ public class AnnotatedApi extends Api implements PermissionNameProvider {
       SpecProvider specProvider = readSpec(endPoint, methods);
       return Collections.singletonList(new AnnotatedApi(specProvider, endPoint, commands, null));
     } else {
-      List<Api> apis = new ArrayList<>();
-      for (Method m : klas.getDeclaredMethods()) {
+      Method[] methods = klas.getDeclaredMethods();
+      List<Api> apis = new ArrayList<>(methods.length);
+      for (Method m : methods) {
         EndPoint endPoint = m.getAnnotation(EndPoint.class);
         if (endPoint == null) continue;
         if (!Modifier.isPublic(m.getModifiers())) {
@@ -127,14 +128,14 @@ public class AnnotatedApi extends Api implements PermissionNameProvider {
 
   private static SpecProvider readSpec(EndPoint endPoint, List<Method> m) {
     return () -> {
-      Map map = new LinkedHashMap();
-      List<String> methods = new ArrayList<>();
+      Map map = new LinkedHashMap(3);
+      List<String> methods = new ArrayList<>(endPoint.method().length);
       for (SolrRequest.METHOD method : endPoint.method()) {
         methods.add(method.name());
       }
       map.put("methods", methods);
       map.put("url", new ValidatingJsonMap(Collections.singletonMap("paths", Arrays.asList(endPoint.path()))));
-      Map<String, Object> cmds = new HashMap<>();
+      Map<String, Object> cmds = new HashMap<>(m.size());
 
       for (Method method : m) {
         Command command = method.getAnnotation(Command.class);
diff --git a/solr/solrj/src/java/org/apache/solr/common/ParWork.java b/solr/solrj/src/java/org/apache/solr/common/ParWork.java
index e24efa7..31420f9 100644
--- a/solr/solrj/src/java/org/apache/solr/common/ParWork.java
+++ b/solr/solrj/src/java/org/apache/solr/common/ParWork.java
@@ -545,7 +545,7 @@ public class ParWork implements Closeable {
 
             }
             if (closeCalls.size() > 0) {
-              try {
+
                 List<Future<Object>> results = new ArrayList<>(closeCalls.size());
                 for (Callable<Object> call : closeCalls) {
                     Future<Object> future = executor.doSubmit(call, requireAnotherThread);
@@ -555,18 +555,24 @@ public class ParWork implements Closeable {
 //                List<Future<Object>> results = executor.invokeAll(closeCalls, 8, TimeUnit.SECONDS);
 
                 for (Future<Object> future : results) {
-                  future.get(Integer.getInteger("solr.parwork.task_timeout", 60000), TimeUnit.MILLISECONDS); // nocommit
-                  if (!future.isDone() || future.isCancelled()) {
-                    log.warn("A task did not finish isDone={} isCanceled={}", future.isDone(), future.isCancelled());
-                  //  throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "A task did nor finish" +future.isDone()  + " " + future.isCancelled());
+                  try {
+                    future.get(
+                        Integer.getInteger("solr.parwork.task_timeout", 60000),
+                        TimeUnit.MILLISECONDS); // nocommit
+                    if (!future.isDone() || future.isCancelled()) {
+                      log.warn("A task did not finish isDone={} isCanceled={}",
+                          future.isDone(), future.isCancelled());
+                      //  throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "A task did nor finish" +future.isDone()  + " " + future.isCancelled());
+                    }
+                  } catch (InterruptedException e1) {
+                    log.warn(WORK_WAS_INTERRUPTED);
+                    // TODO: save interrupted status and reset it at end?
                   }
+
                 }
 
-              } catch (InterruptedException e1) {
-                log.warn(WORK_WAS_INTERRUPTED);
-                Thread.currentThread().interrupt();
-                return;
-              }
+
+
             }
           }
         } finally {
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index 946c97e..fb3e744 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -200,15 +200,15 @@ public class ZkStateReader implements SolrCloseable {
   private ConcurrentHashMap<String, CollectionWatch<DocCollectionWatcher>> collectionWatches = new ConcurrentHashMap<>(16, 0.75f, 5);
 
   // named this observers so there's less confusion between CollectionPropsWatcher map and the PropsWatcher map.
-  private ConcurrentHashMap<String, CollectionPropsWatcher> collectionPropsObservers = new ConcurrentHashMap<>(16, 0.75f, 5);
+  private final ConcurrentHashMap<String, CollectionPropsWatcher> collectionPropsObservers = new ConcurrentHashMap<>(16, 0.75f, 5);
 
   private Set<CloudCollectionsListener> cloudCollectionsListeners = ConcurrentHashMap.newKeySet();
 
   private final ExecutorService notifications = ParWork.getExecutor();
 
-  private Set<LiveNodesListener> liveNodesListeners = ConcurrentHashMap.newKeySet();
+  private final Set<LiveNodesListener> liveNodesListeners = ConcurrentHashMap.newKeySet();
 
-  private Set<ClusterPropertiesListener> clusterPropertiesListeners = ConcurrentHashMap.newKeySet();
+  private final Set<ClusterPropertiesListener> clusterPropertiesListeners = ConcurrentHashMap.newKeySet();
 
   private static final long LAZY_CACHE_TIME = TimeUnit.NANOSECONDS.convert(STATE_UPDATE_DELAY, TimeUnit.MILLISECONDS);
 
@@ -312,7 +312,7 @@ public class ZkStateReader implements SolrCloseable {
 
   private volatile boolean closed = false;
 
-  private Set<CountDownLatch> waitLatches = ConcurrentHashMap.newKeySet(64);
+  private final Set<CountDownLatch> waitLatches = ConcurrentHashMap.newKeySet(64);
 
   public ZkStateReader(SolrZkClient zkClient) {
     this(zkClient, null);
@@ -842,14 +842,11 @@ public class ZkStateReader implements SolrCloseable {
   }
 
   public void close() {
+    log.info("Closing ZkStateReader");
     closeTracker.close();
     this.closed = true;
     try {
-      try (ParWork closer = new ParWork(this, true)) {
-//        closer.add("waitLatchesReader", () -> {
-//          waitLatches.forEach((w) -> w.countDown());
-//          return null;
-//        });
+      try (ParWork closer = new ParWork(this, false)) {
 
         closer
             .add("notifications", notifications, () -> {