mirror of https://github.com/apache/lucene.git
SOLR-5476 tests passing
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1559677 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f698963775
commit
a136d320b9
|
@ -19,6 +19,7 @@ package org.apache.solr.cloud;
|
|||
|
||||
import org.apache.solr.client.solrj.SolrResponse;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.apache.solr.client.solrj.impl.CloudSolrServer;
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrServer;
|
||||
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
|
||||
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
||||
|
@ -67,6 +68,7 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -222,56 +224,66 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
|
|||
List overseerDesignates = (List) m.get("overseer");
|
||||
if(overseerDesignates==null || overseerDesignates.isEmpty()) return;
|
||||
|
||||
log.debug("overseer designates {}", overseerDesignates);
|
||||
log.info("overseer designates {}", overseerDesignates);
|
||||
|
||||
List<String> children = zk.getChildren(OverseerElectionContext.PATH + LeaderElector.ELECTION_NODE, null, true);
|
||||
List<String> nodeNames = getSortedNodeNames(zk);
|
||||
if(nodeNames.size()<2) return;
|
||||
|
||||
|
||||
if(children.size()<2) return;
|
||||
|
||||
LeaderElector.sortSeqs(children);
|
||||
ArrayList<String> nodeNames = new ArrayList<>(children.size());
|
||||
for (String c : children) nodeNames.add(LeaderElector.getNodeName(c));
|
||||
boolean overseerDesignateAvailable = false;
|
||||
//
|
||||
Set<String> nodesTobePushedBack = new HashSet<String>();
|
||||
//ensure that the node right behind the leader , i.r at position 1 is a Overseer
|
||||
String newOverseerDesignate = null;
|
||||
log.debug("sorted nodes {}", nodeNames);
|
||||
for (int i = 1; i < nodeNames.size(); i++) {
|
||||
Set<String> availableDesignates = new HashSet<String>();
|
||||
|
||||
log.debug("sorted nodes {}", nodeNames);//TODO to be removed
|
||||
for (int i = 0; i < nodeNames.size(); i++) {
|
||||
String s = nodeNames.get(i);
|
||||
|
||||
if (overseerDesignates.contains(s)) {
|
||||
log.info(" found an overseer designate to be promoted to the front : {}, pushing others back", s);
|
||||
overseerDesignateAvailable = true;
|
||||
newOverseerDesignate = s;
|
||||
for (int j = 1; j < i; j++) {
|
||||
String nodeName = nodeNames.get(j);
|
||||
log.debug("pushing back {} ", nodeName);
|
||||
invokeRejoinOverseer(nodeName);
|
||||
availableDesignates.add(s);
|
||||
|
||||
for(int j=0;j<i;j++){
|
||||
if(!overseerDesignates.contains(nodeNames.get(j))) {
|
||||
nodesTobePushedBack.add(nodeNames.get(j));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
if(overseerDesignateAvailable) break;
|
||||
if(availableDesignates.size()>1) break;
|
||||
}
|
||||
|
||||
if(overseerDesignateAvailable){
|
||||
if(!availableDesignates.isEmpty()){
|
||||
for (String s : nodesTobePushedBack) {
|
||||
log.info("pushing back {} ", s);
|
||||
invokeRejoinOverseer(s);
|
||||
}
|
||||
|
||||
//wait for a while to ensure the designate has indeed come in front
|
||||
boolean prioritizationComplete = false;
|
||||
long timeout = System.currentTimeMillis() + 5000;
|
||||
long timeout = System.currentTimeMillis() + 2500;
|
||||
|
||||
for(;System.currentTimeMillis()< timeout ;){
|
||||
children = zk.getChildren(OverseerElectionContext.PATH + LeaderElector.ELECTION_NODE, null, true);
|
||||
LeaderElector.sortSeqs(children);
|
||||
List<String> currentNodeNames = getSortedNodeNames(zk);
|
||||
|
||||
String frontRunner = LeaderElector.getNodeName(children.get(1));
|
||||
log.debug("Frontrunner : {}", frontRunner);
|
||||
if(newOverseerDesignate.equals(frontRunner)){
|
||||
int totalLeaders = 0;
|
||||
|
||||
for(int i=0;i<availableDesignates.size();i++) {
|
||||
if(overseerDesignates.contains(currentNodeNames.get(i))) totalLeaders++;
|
||||
}
|
||||
if(totalLeaders == availableDesignates.size()){
|
||||
prioritizationComplete = true;
|
||||
break;
|
||||
}
|
||||
Thread.sleep(50);
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("Thread interrupted",e);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(!prioritizationComplete) {
|
||||
log.warn("Could not make the Overseer designate '{}' the frontrunner", newOverseerDesignate);
|
||||
log.warn("available designates and current state {} {} ", availableDesignates, getSortedNodeNames(zk));
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -279,14 +291,28 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!overseerDesignates.contains( nodeNames.get(0)) && overseerDesignateAvailable){
|
||||
if(!overseerDesignates.contains( getLeaderNode(zkStateReader.getZkClient())) && !availableDesignates.isEmpty()){
|
||||
//this means there are designated Overseer nodes and I am not one of them , kill myself
|
||||
invokeRejoinOverseer(nodeNames.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static List<String> getSortedNodeNames(SolrZkClient zk) throws KeeperException, InterruptedException {
|
||||
List<String> children = zk.getChildren(OverseerElectionContext.PATH + LeaderElector.ELECTION_NODE, null, true);
|
||||
LeaderElector.sortSeqs(children);
|
||||
ArrayList<String> nodeNames = new ArrayList<>(children.size());
|
||||
for (String c : children) nodeNames.add(LeaderElector.getNodeName(c));
|
||||
return nodeNames;
|
||||
}
|
||||
|
||||
public static String getLeaderNode(SolrZkClient zkClient) throws KeeperException, InterruptedException {
|
||||
Map m = (Map) ZkStateReader.fromJSON(zkClient.getData("/overseer_elect/leader", null, new Stat(), true));
|
||||
String s = (String) m.get("id");
|
||||
// log.info("leader-id {}",s);
|
||||
String nodeName = LeaderElector.getNodeName(s);
|
||||
// log.info("Leader {}", nodeName);
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
private void invokeRejoinOverseer(String nodeName) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.solr.client.solrj.SolrRequest;
|
|||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.apache.solr.client.solrj.impl.CloudSolrServer;
|
||||
import org.apache.solr.client.solrj.request.QueryRequest;
|
||||
import org.apache.solr.common.cloud.SolrZkClient;
|
||||
import org.apache.solr.common.cloud.ZkStateReader;
|
||||
import org.apache.solr.common.params.MapSolrParams;
|
||||
import org.apache.solr.common.params.SolrParams;
|
||||
|
@ -46,7 +47,6 @@ import static org.apache.solr.cloud.OverseerCollectionProcessor.REPLICATION_FACT
|
|||
import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
|
||||
import static org.apache.solr.common.params.CollectionParams.CollectionAction;
|
||||
|
||||
@Ignore("tests need fix failing too often")
|
||||
public class OverseerRolesTest extends AbstractFullDistribZkTestBase{
|
||||
private CloudSolrServer client;
|
||||
|
||||
|
@ -137,20 +137,18 @@ public class OverseerRolesTest extends AbstractFullDistribZkTestBase{
|
|||
timeout = System.currentTimeMillis()+10000;
|
||||
leaderchanged = false;
|
||||
for(;System.currentTimeMillis() < timeout;){
|
||||
log.info(" count {}", System.currentTimeMillis());
|
||||
List<String> seqs = client.getZkStateReader().getZkClient().getChildren("/overseer_elect/election", null, true);
|
||||
LeaderElector.sortSeqs(seqs);
|
||||
// log.info(" count {}", System.currentTimeMillis());
|
||||
|
||||
log.info("seqs : {} ",seqs);
|
||||
//
|
||||
if(LeaderElector.getNodeName(seqs.get(1)).equals(anotherOverseer)){
|
||||
List<String> sortedNodeNames = OverseerCollectionProcessor.getSortedNodeNames(client.getZkStateReader().getZkClient());
|
||||
if(sortedNodeNames.get(1) .equals(anotherOverseer) || sortedNodeNames.get(0).equals(anotherOverseer)){
|
||||
leaderchanged =true;
|
||||
break;
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
assertTrue("New overseer not the frontrunner", leaderchanged);
|
||||
assertTrue("New overseer not the frontrunner : "+ OverseerCollectionProcessor.getSortedNodeNames(client.getZkStateReader().getZkClient()) + " expected : "+ anotherOverseer, leaderchanged);
|
||||
|
||||
|
||||
client.shutdown();
|
||||
|
@ -158,7 +156,7 @@ public class OverseerRolesTest extends AbstractFullDistribZkTestBase{
|
|||
|
||||
}
|
||||
|
||||
private void setOverseerRole(CollectionAction action, String overseerDesignate) throws SolrServerException, IOException {
|
||||
private void setOverseerRole(CollectionAction action, String overseerDesignate) throws Exception, IOException {
|
||||
log.info("Adding overseer designate {} ", overseerDesignate);
|
||||
Map m = makeMap(
|
||||
"action", action.toString().toLowerCase(Locale.ROOT),
|
||||
|
|
Loading…
Reference in New Issue