use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.
the class ManagedIndexSchema method getActiveReplicaCoreUrls.
protected static List<String> getActiveReplicaCoreUrls(ZkController zkController, String collection, String localCoreNodeName) {
List<String> activeReplicaCoreUrls = new ArrayList<>();
ZkStateReader zkStateReader = zkController.getZkStateReader();
ClusterState clusterState = zkStateReader.getClusterState();
Set<String> liveNodes = clusterState.getLiveNodes();
Collection<Slice> activeSlices = clusterState.getActiveSlices(collection);
if (activeSlices != null && activeSlices.size() > 0) {
for (Slice next : activeSlices) {
Map<String, Replica> replicasMap = next.getReplicasMap();
if (replicasMap != null) {
for (Map.Entry<String, Replica> entry : replicasMap.entrySet()) {
Replica replica = entry.getValue();
if (!localCoreNodeName.equals(replica.getName()) && replica.getState() == Replica.State.ACTIVE && liveNodes.contains(replica.getNodeName())) {
ZkCoreNodeProps replicaCoreProps = new ZkCoreNodeProps(replica);
activeReplicaCoreUrls.add(replicaCoreProps.getCoreUrl());
}
}
}
}
}
return activeReplicaCoreUrls;
}
use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.
the class HttpSolrCall method extractRemotePath.
protected void extractRemotePath(String corename, String origCorename, int idx) throws UnsupportedEncodingException, KeeperException, InterruptedException {
if (core == null && idx > 0) {
coreUrl = getRemotCoreUrl(corename, origCorename);
// don't proxy for internal update requests
invalidStates = checkStateIsValid(queryParams.get(CloudSolrClient.STATE_VERSION));
if (coreUrl != null && queryParams.get(DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM) == null) {
path = path.substring(idx);
if (invalidStates != null) {
//it does not make sense to send the request to a remote node
throw new SolrException(SolrException.ErrorCode.INVALID_STATE, new String(Utils.toJSON(invalidStates), org.apache.lucene.util.IOUtils.UTF_8));
}
action = REMOTEQUERY;
} else {
if (!retry) {
// we couldn't find a core to work with, try reloading aliases
// TODO: it would be nice if admin ui elements skipped this...
ZkStateReader reader = cores.getZkController().getZkStateReader();
reader.updateAliases();
action = RETRY;
}
}
}
}
use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.
the class HttpSolrCall method getCoreByCollection.
protected SolrCore getCoreByCollection(String collectionName, boolean isPreferLeader) {
ZkStateReader zkStateReader = cores.getZkController().getZkStateReader();
ClusterState clusterState = zkStateReader.getClusterState();
DocCollection collection = clusterState.getCollectionOrNull(collectionName);
if (collection == null) {
return null;
}
Set<String> liveNodes = clusterState.getLiveNodes();
if (isPreferLeader) {
List<Replica> leaderReplicas = collection.getLeaderReplicas(cores.getZkController().getNodeName());
SolrCore core = randomlyGetSolrCore(liveNodes, leaderReplicas);
if (core != null)
return core;
}
List<Replica> replicas = collection.getReplicas(cores.getZkController().getNodeName());
return randomlyGetSolrCore(liveNodes, replicas);
}
use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.
the class TestSubQueryTransformerDistrib method setupCluster.
@BeforeClass
public static void setupCluster() throws Exception {
differentUniqueId = random().nextBoolean();
final Path configDir = Paths.get(TEST_HOME(), "collection1", "conf");
String configName = "solrCloudCollectionConfig";
int nodeCount = 5;
configureCluster(nodeCount).addConfig(configName, configDir).configure();
Map<String, String> collectionProperties = new HashMap<>();
collectionProperties.put("config", "solrconfig-doctransformers.xml");
collectionProperties.put("schema", "schema-docValuesJoin.xml");
int shards = 2;
int replicas = 2;
CollectionAdminRequest.createCollection(people, configName, shards, replicas).withProperty("config", "solrconfig-doctransformers.xml").withProperty("schema", "schema-docValuesJoin.xml").process(cluster.getSolrClient());
CollectionAdminRequest.createCollection(depts, configName, shards, replicas).withProperty("config", "solrconfig-doctransformers.xml").withProperty("schema", differentUniqueId ? "schema-minimal-with-another-uniqkey.xml" : "schema-docValuesJoin.xml").process(cluster.getSolrClient());
CloudSolrClient client = cluster.getSolrClient();
client.setDefaultCollection(people);
ZkStateReader zkStateReader = client.getZkStateReader();
AbstractDistribZkTestBase.waitForRecoveriesToFinish(people, zkStateReader, true, true, 30);
AbstractDistribZkTestBase.waitForRecoveriesToFinish(depts, zkStateReader, false, true, 30);
}
use of org.apache.solr.common.cloud.ZkStateReader in project lucene-solr by apache.
the class ZkClientClusterStateProvider method connect.
@Override
public void connect() {
if (zkStateReader == null) {
synchronized (this) {
if (zkStateReader == null) {
ZkStateReader zk = null;
try {
zk = new ZkStateReader(zkHost, zkClientTimeout, zkConnectTimeout);
zk.createClusterStateWatchersAndUpdate();
zkStateReader = zk;
log.info("Cluster at {} ready", zkHost);
} catch (InterruptedException e) {
zk.close();
Thread.currentThread().interrupt();
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
} catch (KeeperException e) {
zk.close();
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
} catch (Exception e) {
if (zk != null)
zk.close();
// do not wrap because clients may be relying on the underlying exception being thrown
throw e;
}
}
}
}
}
Aggregations