diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 4e42b531a79..9440ab6a468 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -214,6 +214,12 @@ Bug Fixes * SOLR-6545: Query field list with wild card on dynamic field fails. (Burke Webster, Xu Zhang, shalin) +Optimizations +---------------------- + +* SOLR-6603: LBHttpSolrServer - lazily allocate skipped-zombie-servers list. + (Christine Poerschke via shalin) + Other Changes ---------------------- diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java index 52316dc946d..b6d51b36005 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java @@ -286,7 +286,7 @@ public class LBHttpSolrServer extends SolrServer { Rsp rsp = new Rsp(); Exception ex = null; boolean isUpdate = req.request instanceof IsUpdateRequest; - List skipped = new ArrayList<>(req.getNumDeadServersToTry()); + List skipped = null; for (String serverStr : req.getServers()) { serverStr = normalize(serverStr); @@ -294,8 +294,16 @@ public class LBHttpSolrServer extends SolrServer { ServerWrapper wrapper = zombieServers.get(serverStr); if (wrapper != null) { // System.out.println("ZOMBIE SERVER QUERIED: " + serverStr); - if (skipped.size() < req.getNumDeadServersToTry()) - skipped.add(wrapper); + final int numDeadServersToTry = req.getNumDeadServersToTry(); + if (numDeadServersToTry > 0) { + if (skipped == null) { + skipped = new ArrayList<>(numDeadServersToTry); + skipped.add(wrapper); + } + else if (skipped.size() < numDeadServersToTry) { + skipped.add(wrapper); + } + } continue; } rsp.server = serverStr; @@ -308,10 +316,12 @@ public class LBHttpSolrServer extends SolrServer { } // try the servers we previously skipped - for (ServerWrapper wrapper : skipped) { - ex = doRequest(wrapper.solrServer, req, rsp, isUpdate, true, wrapper.getKey()); - if (ex == null) { - return rsp; // SUCCESS + if (skipped != null) { + for (ServerWrapper wrapper : skipped) { + ex = doRequest(wrapper.solrServer, req, rsp, isUpdate, true, wrapper.getKey()); + if (ex == null) { + return rsp; // SUCCESS + } } }