Java Code Examples for org.apache.solr.common.cloud.ZkStateReader#COLLECTIONS_ZKNODE

The following examples show how to use org.apache.solr.common.cloud.ZkStateReader#COLLECTIONS_ZKNODE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverseerCollectionMessageHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * This doesn't validate the config (path) itself and is just responsible for creating the confNode.
 * That check should be done before the config node is created.
 */
public static void createConfNode(DistribStateManager stateManager, String configName, String coll) throws IOException, AlreadyExistsException, BadVersionException, KeeperException, InterruptedException {

  if (configName != null) {
    String collDir = ZkStateReader.COLLECTIONS_ZKNODE + "/" + coll;
    log.debug("creating collections conf node {} ", collDir);
    byte[] data = Utils.toJSON(makeMap(ZkController.CONFIGNAME_PROP, configName));
    if (stateManager.hasData(collDir)) {
      stateManager.setData(collDir, data, -1);
    } else {
      stateManager.makePath(collDir, data, CreateMode.PERSISTENT, false);
    }
  } else {
    throw new SolrException(ErrorCode.BAD_REQUEST,"Unable to get config name");
  }
}
 
Example 2
Source File: SplitShardCmd.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static boolean lockForSplit(SolrCloudManager cloudManager, String collection, String shard) throws Exception {
  String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + "/" + shard + "-splitting";
  final DistribStateManager stateManager = cloudManager.getDistribStateManager();
  synchronized (stateManager) {
    if (stateManager.hasData(path)) {
      VersionedData vd = stateManager.getData(path);
      return false;
    }
    Map<String, Object> map = new HashMap<>();
    map.put(ZkStateReader.STATE_TIMESTAMP_PROP, String.valueOf(cloudManager.getTimeSource().getEpochTimeNs()));
    byte[] data = Utils.toJSON(map);
    try {
      cloudManager.getDistribStateManager().makePath(path, data, CreateMode.EPHEMERAL, true);
    } catch (Exception e) {
      throw new SolrException(SolrException.ErrorCode.INVALID_STATE, "Can't lock parent slice for splitting (another split operation running?): " +
          collection + "/" + shard, e);
    }
    return true;
  }
}
 
Example 3
Source File: BackupManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void uploadCollectionProperties(URI backupLoc, String backupId, String collectionName) throws IOException {
  URI sourceDir = repository.resolve(backupLoc, backupId, ZK_STATE_DIR);
  URI source = repository.resolve(sourceDir, ZkStateReader.COLLECTION_PROPS_ZKNODE);
  if (!repository.exists(source)) {
    // No collection properties to restore
    return;
  }
  String zkPath = ZkStateReader.COLLECTIONS_ZKNODE + '/' + collectionName + '/' + ZkStateReader.COLLECTION_PROPS_ZKNODE;

  try (IndexInput is = repository.openInput(sourceDir, ZkStateReader.COLLECTION_PROPS_ZKNODE, IOContext.DEFAULT)) {
    byte[] arr = new byte[(int) is.length()];
    is.readBytes(arr, 0, (int) is.length());
    zkStateReader.getZkClient().create(zkPath, arr, CreateMode.PERSISTENT, true);
  } catch (KeeperException | InterruptedException e) {
    throw new IOException("Error uploading file to zookeeper path " + source.toString() + " to " + zkPath,
        SolrZkClient.checkInterrupted(e));
  }
}
 
Example 4
Source File: BackupManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void downloadCollectionProperties(URI backupLoc, String backupId, String collectionName) throws IOException {
  URI dest = repository.resolve(backupLoc, backupId, ZK_STATE_DIR, ZkStateReader.COLLECTION_PROPS_ZKNODE);
  String zkPath = ZkStateReader.COLLECTIONS_ZKNODE + '/' + collectionName + '/' + ZkStateReader.COLLECTION_PROPS_ZKNODE;


  try {
    if (!zkStateReader.getZkClient().exists(zkPath, true)) {
      // Nothing to back up
      return;
    }

    try (OutputStream os = repository.createOutput(dest)) {
      byte[] data = zkStateReader.getZkClient().getData(zkPath, null, null, true);
      os.write(data);
    }
  } catch (KeeperException | InterruptedException e) {
    throw new IOException("Error downloading file from zookeeper path " + zkPath + " to " + dest.toString(),
        SolrZkClient.checkInterrupted(e));
  }
}
 
Example 5
Source File: ZkShardTerms.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public ZkShardTerms(String collection, String shard, SolrZkClient zkClient) {
  this.znodePath = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + "/terms/" + shard;
  this.collection = collection;
  this.shard = shard;
  this.zkClient = zkClient;
  ensureTermNodeExist();
  refreshTerms();
  retryRegisterWatcher();
  ObjectReleaseTracker.track(this);
}
 
Example 6
Source File: ReindexCollectionCmd.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> setReindexingState(String collection, State state, Map<String, Object> props) throws Exception {
  String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + REINDEXING_STATE_PATH;
  DistribStateManager stateManager = ocmh.cloudManager.getDistribStateManager();
  if (props == null) { // retrieve existing props, if any
    props = Utils.getJson(stateManager, path);
  }
  Map<String, Object> copyProps = new HashMap<>(props);
  copyProps.put("state", state.toLower());
  if (stateManager.hasData(path)) {
    stateManager.setData(path, Utils.toJSON(copyProps), -1);
  } else {
    stateManager.makePath(path, Utils.toJSON(copyProps), CreateMode.PERSISTENT, false);
  }
  return copyProps;
}
 
Example 7
Source File: ReindexCollectionCmd.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void removeReindexingState(String collection) throws Exception {
  String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + REINDEXING_STATE_PATH;
  DistribStateManager stateManager = ocmh.cloudManager.getDistribStateManager();
  if (stateManager.hasData(path)) {
    stateManager.removeData(path, -1);
  }
}
 
Example 8
Source File: ZooKeeperInspector.java    From examples with Apache License 2.0 5 votes vote down vote up
/**
 * Returns config value given collection name Borrowed heavily from Solr's ZKController.
 */
public String readConfigName(SolrZkClient zkClient, String collection) throws KeeperException,
    InterruptedException {
  if (collection == null) {
    throw new IllegalArgumentException("collection must not be null");
  }
  String configName = null;

  // first check for alias
  collection = checkForAlias(zkClient, collection);

  String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection;
  if (LOG.isInfoEnabled()) {
    LOG.info("Load collection config from:" + path);
  }
  byte[] data = zkClient.getData(path, null, null, true);

  if (data != null) {
    ZkNodeProps props = ZkNodeProps.load(data);
    configName = props.getStr(ZkController.CONFIGNAME_PROP);
  }

  if (configName != null
      && !zkClient.exists(ZkController.CONFIGS_ZKNODE + "/" + configName, true)) {
    LOG.error("Specified config does not exist in ZooKeeper:" + configName);
    throw new IllegalArgumentException("Specified config does not exist in ZooKeeper:"
        + configName);
  }

  return configName;
}
 
Example 9
Source File: ZooKeeperDownloader.java    From kite with Apache License 2.0 5 votes vote down vote up
/**
 * Returns config value given collection name
 * Borrowed heavily from Solr's ZKController.
 */
public String readConfigName(SolrZkClient zkClient, String collection)
throws KeeperException, InterruptedException {
  if (collection == null) {
    throw new IllegalArgumentException("collection must not be null");
  }
  String configName = null;

  // first check for alias
  byte[] aliasData = zkClient.getData(ZkStateReader.ALIASES, null, null, true);
  Aliases aliases = ClusterState.load(aliasData);
  String alias = aliases.getCollectionAlias(collection);
  if (alias != null) {
    List<String> aliasList = StrUtils.splitSmart(alias, ",", true);
    if (aliasList.size() > 1) {
      throw new IllegalArgumentException("collection cannot be an alias that maps to multiple collections");
    }
    collection = aliasList.get(0);
  }
  
  String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection;
  if (LOG.isInfoEnabled()) {
    LOG.info("Load collection config from:" + path);
  }
  byte[] data = zkClient.getData(path, null, null, true);
  
  if(data != null) {
    ZkNodeProps props = ZkNodeProps.load(data);
    configName = props.getStr(ZkController.CONFIGNAME_PROP);
  }
  
  if (configName != null && !zkClient.exists(ZkConfigManager.CONFIGS_ZKNODE + "/" + configName, true)) {
    LOG.error("Specified config does not exist in ZooKeeper:" + configName);
    throw new IllegalArgumentException("Specified config does not exist in ZooKeeper:"
      + configName);
  }

  return configName;
}
 
Example 10
Source File: Assign.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public static String getCounterNodePath(String collection) {
  return ZkStateReader.COLLECTIONS_ZKNODE + "/"+collection+"/counter";
}
 
Example 11
Source File: ReindexCollectionCmd.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public static Map<String, Object> getReindexingState(DistribStateManager stateManager, String collection) throws Exception {
  String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + REINDEXING_STATE_PATH;
  // make it modifiable
  return new TreeMap<>(Utils.getJson(stateManager, path));
}