diff --git a/solr/core/src/java/org/apache/solr/core/JarRepository.java b/solr/core/src/java/org/apache/solr/core/JarRepository.java index cfb4893a5b9..8d0ccba9a05 100644 --- a/solr/core/src/java/org/apache/solr/core/JarRepository.java +++ b/solr/core/src/java/org/apache/solr/core/JarRepository.java @@ -24,8 +24,10 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; @@ -41,6 +43,8 @@ import org.apache.solr.common.cloud.ClusterState; import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; +import org.apache.solr.common.cloud.ZkCoreNodeProps; +import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.handler.admin.CollectionsHandler; import org.apache.solr.util.SimplePostTool; import org.slf4j.Logger; @@ -81,16 +85,28 @@ public class JarRepository { JarContent jar = jars.get(key); if (jar == null) { if (this.coreContainer.isZooKeeperAware()) { - ClusterState cs = this.coreContainer.getZkController().getZkStateReader().getClusterState(); + ZkStateReader zkStateReader = this.coreContainer.getZkController().getZkStateReader(); + ClusterState cs = zkStateReader.getClusterState(); DocCollection coll = cs.getCollectionOrNull(CollectionsHandler.SYSTEM_COLL); if (coll == null) throw new SolrException(SERVICE_UNAVAILABLE, ".system collection not available"); ArrayList slices = new ArrayList<>(coll.getActiveSlices()); - if (slices.isEmpty()) throw new SolrException(SERVICE_UNAVAILABLE, ".no active slices for .system collection"); + if (slices.isEmpty()) throw new SolrException(SERVICE_UNAVAILABLE, "No active slices for .system collection"); Collections.shuffle(slices, RANDOM); //do load balancing - Slice slice = slices.get(0); - Replica replica = slice.getReplicas().iterator().next(); - if (replica == null) + + Replica replica = null; + for (Slice slice : slices) { + List replicas = new ArrayList<>(slice.getReplicasMap().values()); + Collections.shuffle(replicas, RANDOM); + for (Replica r : replicas) { + if (ZkStateReader.ACTIVE.equals(r.getStr(ZkStateReader.STATE_PROP))) { + replica = r; + break; + } + } + } + if (replica == null) { throw new SolrException(SERVICE_UNAVAILABLE, ".no active replica available for .system collection"); + } String url = replica.getStr(BASE_URL_PROP) + "/.system/blob/" + key + "?wt=filestream"; HttpClient httpClient = coreContainer.getUpdateShardHandler().getHttpClient(); @@ -108,10 +124,8 @@ public class JarRepository { } jars.put(key, jar = new JarContent(key, b)); } else { - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Jar loading is not supported in non-cloud mode"); // todo - } } diff --git a/solr/core/src/java/org/apache/solr/handler/BlobHandler.java b/solr/core/src/java/org/apache/solr/handler/BlobHandler.java index ccd0b3a015b..5b28a309161 100644 --- a/solr/core/src/java/org/apache/solr/handler/BlobHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/BlobHandler.java @@ -233,10 +233,11 @@ public class BlobHandler extends RequestHandlerBase implements PluginInfoInitia UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp); AddUpdateCommand cmd = new AddUpdateCommand(req); cmd.solrDoc = solrDoc; - log.info("Adding doc "+doc); + log.info("Adding doc: "+doc); processor.processAdd(cmd); - log.info("committing doc"+doc); + log.info("committing doc: "+doc); processor.processCommit(new CommitUpdateCommand(req, false)); + processor.finish(); } @Override diff --git a/solr/core/src/test/org/apache/solr/core/TestDynamicLoading.java b/solr/core/src/test/org/apache/solr/core/TestDynamicLoading.java index d46d474601c..c3bea635fdd 100644 --- a/solr/core/src/test/org/apache/solr/core/TestDynamicLoading.java +++ b/solr/core/src/test/org/apache/solr/core/TestDynamicLoading.java @@ -30,7 +30,6 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.FileOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -88,7 +87,9 @@ public class TestDynamicLoading extends AbstractFullDistribZkTestBase { HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size())); String baseURL = randomClient.getBaseURL(); baseURL = baseURL.substring(0, baseURL.lastIndexOf('/')); - TestBlobHandler.createSysColl(new HttpSolrClient(baseURL,randomClient.getHttpClient())); + TestBlobHandler.createSystemCollection(new HttpSolrClient(baseURL, randomClient.getHttpClient())); + waitForRecoveriesToFinish(".system", true); + map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client); assertNotNull(map = (Map) map.get("error")); diff --git a/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java b/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java index f273333fcb2..466e51692cc 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java +++ b/solr/core/src/test/org/apache/solr/handler/TestBlobHandler.java @@ -102,7 +102,7 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase { } } - public static void createSysColl(SolrClient client) throws SolrServerException, IOException { + public static void createSystemCollection(SolrClient client) throws SolrServerException, IOException { CollectionAdminResponse response1; CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create(); createCollectionRequest.setCollectionName(".system"); @@ -131,7 +131,7 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase { List l; long start = System.currentTimeMillis(); int i=0; - for(;i<150;i++) {//10secs + for(;i<150;i++) {//15 secs url = baseUrl + "/.system/blob/test"; map = TestSolrConfigHandlerConcurrent.getAsMap(url, cloudClient); String numFound = String.valueOf(ConfigOverlay.getObjectByPath(map, false, Arrays.asList("response", "numFound")));