SOLR-6917: TestDynamicLoading should wait for .system collection to recover and JarRepository should always choose an active replica

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1659893 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2015-02-15 08:21:13 +00:00
parent 59769898df
commit 8c1c170468
4 changed files with 29 additions and 13 deletions

View File

@ -24,8 +24,10 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; 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.DocCollection;
import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice; 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.handler.admin.CollectionsHandler;
import org.apache.solr.util.SimplePostTool; import org.apache.solr.util.SimplePostTool;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -81,16 +85,28 @@ public class JarRepository {
JarContent jar = jars.get(key); JarContent jar = jars.get(key);
if (jar == null) { if (jar == null) {
if (this.coreContainer.isZooKeeperAware()) { 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); DocCollection coll = cs.getCollectionOrNull(CollectionsHandler.SYSTEM_COLL);
if (coll == null) throw new SolrException(SERVICE_UNAVAILABLE, ".system collection not available"); if (coll == null) throw new SolrException(SERVICE_UNAVAILABLE, ".system collection not available");
ArrayList<Slice> slices = new ArrayList<>(coll.getActiveSlices()); ArrayList<Slice> 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 Collections.shuffle(slices, RANDOM); //do load balancing
Slice slice = slices.get(0);
Replica replica = slice.getReplicas().iterator().next(); Replica replica = null;
if (replica == null) for (Slice slice : slices) {
List<Replica> 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"); throw new SolrException(SERVICE_UNAVAILABLE, ".no active replica available for .system collection");
}
String url = replica.getStr(BASE_URL_PROP) + "/.system/blob/" + key + "?wt=filestream"; String url = replica.getStr(BASE_URL_PROP) + "/.system/blob/" + key + "?wt=filestream";
HttpClient httpClient = coreContainer.getUpdateShardHandler().getHttpClient(); HttpClient httpClient = coreContainer.getUpdateShardHandler().getHttpClient();
@ -108,10 +124,8 @@ public class JarRepository {
} }
jars.put(key, jar = new JarContent(key, b)); jars.put(key, jar = new JarContent(key, b));
} else { } else {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Jar loading is not supported in non-cloud mode"); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Jar loading is not supported in non-cloud mode");
// todo // todo
} }
} }

View File

@ -233,10 +233,11 @@ public class BlobHandler extends RequestHandlerBase implements PluginInfoInitia
UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp); UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp);
AddUpdateCommand cmd = new AddUpdateCommand(req); AddUpdateCommand cmd = new AddUpdateCommand(req);
cmd.solrDoc = solrDoc; cmd.solrDoc = solrDoc;
log.info("Adding doc "+doc); log.info("Adding doc: "+doc);
processor.processAdd(cmd); processor.processAdd(cmd);
log.info("committing doc"+doc); log.info("committing doc: "+doc);
processor.processCommit(new CommitUpdateCommand(req, false)); processor.processCommit(new CommitUpdateCommand(req, false));
processor.finish();
} }
@Override @Override

View File

@ -30,7 +30,6 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -88,7 +87,9 @@ public class TestDynamicLoading extends AbstractFullDistribZkTestBase {
HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size())); HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size()));
String baseURL = randomClient.getBaseURL(); String baseURL = randomClient.getBaseURL();
baseURL = baseURL.substring(0, baseURL.lastIndexOf('/')); 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); map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client);
assertNotNull(map = (Map) map.get("error")); assertNotNull(map = (Map) map.get("error"));

View File

@ -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; CollectionAdminResponse response1;
CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create(); CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create();
createCollectionRequest.setCollectionName(".system"); createCollectionRequest.setCollectionName(".system");
@ -131,7 +131,7 @@ public class TestBlobHandler extends AbstractFullDistribZkTestBase {
List l; List l;
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
int i=0; int i=0;
for(;i<150;i++) {//10secs for(;i<150;i++) {//15 secs
url = baseUrl + "/.system/blob/test"; url = baseUrl + "/.system/blob/test";
map = TestSolrConfigHandlerConcurrent.getAsMap(url, cloudClient); map = TestSolrConfigHandlerConcurrent.getAsMap(url, cloudClient);
String numFound = String.valueOf(ConfigOverlay.getObjectByPath(map, false, Arrays.asList("response", "numFound"))); String numFound = String.valueOf(ConfigOverlay.getObjectByPath(map, false, Arrays.asList("response", "numFound")));