gpt4 book ai didi

org.apache.solr.common.cloud.ZkStateReader.getClusterState()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 11:52:40 26 4
gpt4 key购买 nike

本文整理了Java中org.apache.solr.common.cloud.ZkStateReader.getClusterState()方法的一些代码示例,展示了ZkStateReader.getClusterState()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkStateReader.getClusterState()方法的具体详情如下:
包路径:org.apache.solr.common.cloud.ZkStateReader
类名称:ZkStateReader
方法名:getClusterState

ZkStateReader.getClusterState介绍

暂无

代码示例

代码示例来源:origin: thinkaurelius/titan

/**
 * Checks if the collection has already been created in Solr.
 */
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
  ZkStateReader zkStateReader = server.getZkStateReader();
  zkStateReader.updateClusterState(true);
  ClusterState clusterState = zkStateReader.getClusterState();
  return clusterState.getCollectionOrNull(collection) != null;
}

代码示例来源:origin: thinkaurelius/titan

boolean sawLiveRecovering = false;
zkStateReader.updateClusterState(true);
ClusterState clusterState = zkStateReader.getClusterState();
Map<String, Slice> slices = clusterState.getSlicesMap(collection);
Preconditions.checkNotNull("Could not find collection:" + collection, slices);

代码示例来源:origin: thinkaurelius/titan

@Override
public void clearStorage() throws BackendException {
  try {
    if (mode!=Mode.CLOUD) throw new UnsupportedOperationException("Operation only supported for SolrCloud");
    logger.debug("Clearing storage from Solr: {}", solrClient);
    ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader();
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    for (String collection : clusterState.getCollections()) {
      logger.debug("Clearing collection [{}] in Solr",collection);
      UpdateRequest deleteAll = newUpdateRequest();
      deleteAll.deleteByQuery("*:*");
      solrClient.request(deleteAll, collection);
    }
  } catch (SolrServerException e) {
    logger.error("Unable to clear storage from index due to server error on Solr.", e);
    throw new PermanentBackendException(e);
  } catch (IOException e) {
    logger.error("Unable to clear storage from index due to low-level I/O error.", e);
    throw new PermanentBackendException(e);
  } catch (Exception e) {
    logger.error("Unable to clear storage from index due to general error.", e);
    throw new PermanentBackendException(e);
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected void createCollectionIfNotExist(CloudSolrClient client, String collectionName) {
  Set<String> collectionNames = client.getZkStateReader().getClusterState().getCollections();
  if (!collectionNames.contains(collectionName)) {
    try {
      new CollectionAdminRequest.Create().setCollectionName(collectionName).setNumShards(getSolrCloudNumShards())
          .setMaxShardsPerNode(getSolrCloudNumShards()).setConfigName(getSolrCloudConfigName()).process(client);
    } catch (SolrServerException e) {
      throw ExceptionHelper.refineException(e);
    } catch (IOException e) {
      throw ExceptionHelper.refineException(e);
    }
  }
}

代码示例来源:origin: org.apache.solr/solr-solrj

@Override
public ClusterState getClusterState() throws IOException {
 return zkStateReader.getClusterState();
}

代码示例来源:origin: org.apache.solr/solr-solrj

@Override
public Set<String> getLiveNodes() {
 ClusterState clusterState = zkStateReader.getClusterState();
 if (clusterState != null) {
  return clusterState.getLiveNodes();
 } else {
  return Collections.emptySet();
 }
}

代码示例来源:origin: org.apache.solr/solr-solrj

@Override
public ClusterState.CollectionRef getState(String collection) {
 ClusterState clusterState = zkStateReader.getClusterState();
 if (clusterState != null) {
  return clusterState.getCollectionRef(collection);
 } else {
  return null;
 }
}
public ZkStateReader getZkStateReader(){

代码示例来源:origin: org.apache.solr/solr-test-framework

private String getRandomSlice() {
 Map<String,Slice> slices = zkStateReader.getClusterState().getCollection(collection).getSlicesMap();
 
 List<String> sliceKeyList = new ArrayList<>(slices.size());
 sliceKeyList.addAll(slices.keySet());
 String sliceName = sliceKeyList.get(chaosRandom.nextInt(sliceKeyList.size()));
 return sliceName;
}

代码示例来源:origin: stackoverflow.com

final ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader();
 final Collection<Slice> activeSlices = zkStateReader.getClusterState().getCollection(this.solrCollection).getActiveSlices();
 solrBackupResult.setTotalShards(activeSlices.size());
 String bckupName = "";
 for (final Slice slice : activeSlices) {
     // here you can get leader of each shard 
     final Replica leader = slice.getLeader();
     final Map<String, Object> prop = leader.getProperties();
     final String url = (String) prop.get("base_url");
     final String coreName = (String) prop.get("core");
     }

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-solr

static ClusterState getClusterState(AuthorizedSolrClient<CloudSolrClient> authorizedSolrClient) {
 authorizedSolrClient.solrClient.connect();
 return authorizedSolrClient.solrClient.getZkStateReader().getClusterState();
}

代码示例来源:origin: com.hynnet/solr-solrj

public static boolean isAutoAddReplicas(ZkStateReader reader, String collection) {
 ClusterState clusterState = reader.getClusterState();
 if (clusterState != null) {
  DocCollection docCollection = clusterState.getCollectionOrNull(collection);
  if (docCollection != null) {
   return docCollection.getAutoAddReplicas();
  }
 }
 return false;
}

代码示例来源:origin: org.apache.solr/solr-test-framework

protected int getTotalReplicas(String collection) {
 ZkStateReader zkStateReader = cloudClient.getZkStateReader();
 DocCollection coll = zkStateReader.getClusterState().getCollectionOrNull(collection);
 if (coll == null) return 0;  // support for when collection hasn't been created yet
 int cnt = 0;
 for (Slice slices : coll.getSlices()) {
  cnt += slices.getReplicas().size();
 }
 return cnt;
}

代码示例来源:origin: com.hynnet/solr-solrj

public Replica getLeader(String collection, String shard) throws InterruptedException {
 if (clusterState != null) {
  Replica replica = clusterState.getLeader(collection, shard);
  if (replica != null && getClusterState().liveNodesContain(replica.getNodeName())) {
   return replica;
  }
 }
 return null;
}

代码示例来源:origin: treygrainger/solr-in-action

private final Map<String,String> getShardLeaders(CloudSolrServer solr, String collection) throws Exception {
    Map<String,String> leaders = new TreeMap<String,String>();
    ZkStateReader zkStateReader = solr.getZkStateReader();
    for (Slice slice : zkStateReader.getClusterState().getSlices(collection)) {
      leaders.put(slice.getName(), zkStateReader.getLeaderUrl(collection, slice.getName(), ZK_CLIENT_TIMEOUT));
    }
    return leaders;
  }
}

代码示例来源:origin: org.apache.solr/solr-test-framework

/**
 * Get the collection state for a particular collection
 */
protected static DocCollection getCollectionState(String collectionName) {
 return cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(collectionName);
}

代码示例来源:origin: org.apache.solr/solr-test-framework

private Type getTypeForJetty(String sliceName, CloudJettyRunner cjetty) {
 DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection);
 
 Slice slice = docCollection.getSlice(sliceName);
 
 ZkNodeProps props = slice.getReplicasMap().get(cjetty.coreNodeName);
 if (props == null) {
  throw new RuntimeException("shard name " + cjetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet());
 }
 return Replica.Type.valueOf(props.getStr(ZkStateReader.REPLICA_TYPE));
}

代码示例来源:origin: org.apache.atlas/atlas-titan

/**
 * Checks if the collection has already been created in Solr.
 */
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
  ZkStateReader zkStateReader = server.getZkStateReader();
  zkStateReader.updateClusterState();
  ClusterState clusterState = zkStateReader.getClusterState();
  return clusterState.getCollectionOrNull(collection) != null;
}

代码示例来源:origin: org.apache.solr/solr-solrj

public Replica getLeader(String collection, String shard) {
 if (clusterState != null) {
  DocCollection docCollection = clusterState.getCollectionOrNull(collection);
  Replica replica = docCollection != null ? docCollection.getLeader(shard) : null;
  if (replica != null && getClusterState().liveNodesContain(replica.getNodeName())) {
   return replica;
  }
 }
 return null;
}

代码示例来源:origin: org.apache.solr/solr-test-framework

protected ZkCoreNodeProps getLeaderUrlFromZk(String collection, String slice) {
 ClusterState clusterState = getCommonCloudSolrClient().getZkStateReader().getClusterState();
 final DocCollection docCollection = clusterState.getCollectionOrNull(collection);
 if (docCollection != null && docCollection.getLeader(slice) != null) {
  return new ZkCoreNodeProps(docCollection.getLeader(slice));
 }
 throw new RuntimeException("Could not find leader:" + collection + " " + slice);
}

代码示例来源:origin: org.apache.solr/solr-test-framework

/** Delete all collections (and aliases) */
public void deleteAllCollections() throws Exception {
 try (ZkStateReader reader = new ZkStateReader(solrClient.getZkStateReader().getZkClient())) {
  reader.createClusterStateWatchersAndUpdate(); // up to date aliases & collections
  reader.aliasesManager.applyModificationAndExportToZk(aliases -> Aliases.EMPTY);
  for (String collection : reader.getClusterState().getCollectionStates().keySet()) {
   CollectionAdminRequest.deleteCollection(collection).process(solrClient);
  }
 }
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com