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

The following examples show how to use org.apache.solr.common.cloud.ZkStateReader#COLLECTION_PROP . 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 5 votes vote down vote up
void deleteCoreNode(String collectionName, String replicaName, Replica replica, String core) throws Exception {
  ZkNodeProps m = new ZkNodeProps(
      Overseer.QUEUE_OPERATION, OverseerAction.DELETECORE.toLower(),
      ZkStateReader.CORE_NAME_PROP, core,
      ZkStateReader.NODE_NAME_PROP, replica.getStr(ZkStateReader.NODE_NAME_PROP),
      ZkStateReader.COLLECTION_PROP, collectionName,
      ZkStateReader.CORE_NODE_NAME_PROP, replicaName,
      ZkStateReader.BASE_URL_PROP, replica.getStr(ZkStateReader.BASE_URL_PROP));
  overseer.offerStateUpdate(Utils.toJSON(m));
}
 
Example 2
Source File: ExclusiveSliceProperty.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
ExclusiveSliceProperty(ClusterState clusterState, ZkNodeProps message) {
  this.clusterState = clusterState;
  String tmp = message.getStr(ZkStateReader.PROPERTY_PROP);
  if (StringUtils.startsWith(tmp, OverseerCollectionMessageHandler.COLL_PROP_PREFIX) == false) {
    tmp = OverseerCollectionMessageHandler.COLL_PROP_PREFIX + tmp;
  }
  this.property = tmp.toLowerCase(Locale.ROOT);
  collectionName = message.getStr(ZkStateReader.COLLECTION_PROP);

  if (StringUtils.isBlank(collectionName) || StringUtils.isBlank(property)) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "Overseer '" + message.getStr(Overseer.QUEUE_OPERATION) + "'  requires both the '" + ZkStateReader.COLLECTION_PROP + "' and '" +
            ZkStateReader.PROPERTY_PROP + "' parameters. No action taken ");
  }

  Boolean shardUnique = Boolean.parseBoolean(message.getStr(SHARD_UNIQUE));
  if (shardUnique == false &&
      SliceMutator.SLICE_UNIQUE_BOOLEAN_PROPERTIES.contains(this.property) == false) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Balancing properties amongst replicas in a slice requires that"
        + " the property be a pre-defined property (e.g. 'preferredLeader') or that 'shardUnique' be set to 'true' " +
        " Property: " + this.property + " shardUnique: " + Boolean.toString(shardUnique));
  }

  collection = clusterState.getCollection(collectionName);
  if (collection == null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "Could not find collection ' " + collectionName + "' for overseer operation '" +
            message.getStr(Overseer.QUEUE_OPERATION) + "'. No action taken.");
  }
  onlyActiveNodes = Boolean.parseBoolean(message.getStr(ONLY_ACTIVE_NODES, "true"));
}
 
Example 3
Source File: ReplicaMutator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public ZkWriteCommand deleteReplicaProperty(ClusterState clusterState, ZkNodeProps message) {
  if (checkKeyExistence(message, ZkStateReader.COLLECTION_PROP) == false ||
      checkKeyExistence(message, ZkStateReader.SHARD_ID_PROP) == false ||
      checkKeyExistence(message, ZkStateReader.REPLICA_PROP) == false ||
      checkKeyExistence(message, ZkStateReader.PROPERTY_PROP) == false) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "Overseer DELETEREPLICAPROP requires " +
            ZkStateReader.COLLECTION_PROP + " and " + ZkStateReader.SHARD_ID_PROP + " and " +
            ZkStateReader.REPLICA_PROP + " and " + ZkStateReader.PROPERTY_PROP + " no action taken.");
  }
  String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP);
  String sliceName = message.getStr(ZkStateReader.SHARD_ID_PROP);
  String replicaName = message.getStr(ZkStateReader.REPLICA_PROP);
  String property = message.getStr(ZkStateReader.PROPERTY_PROP).toLowerCase(Locale.ROOT);
  if (StringUtils.startsWith(property, OverseerCollectionMessageHandler.COLL_PROP_PREFIX) == false) {
    property = OverseerCollectionMessageHandler.COLL_PROP_PREFIX + property;
  }

  DocCollection collection = clusterState.getCollection(collectionName);
  Replica replica = collection.getReplica(replicaName);

  if (replica == null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection/slice/replica " +
        collectionName + "/" + sliceName + "/" + replicaName + " no action taken.");
  }

  log.info("Deleting property {} for collection: {} slice: {} replica: {}", property, collectionName, sliceName, replicaName);
  log.debug("Full message: {}", message);
  String curProp = replica.getStr(property);
  if (curProp == null) return ZkStateWriter.NO_OP; // not there anyway, nothing to do.

  Slice slice = collection.getSlice(sliceName);
  DocCollection newCollection = SliceMutator.updateReplica(collection,
      slice, replicaName, unsetProperty(replica, property));
  return new ZkWriteCommand(collectionName, newCollection);
}
 
Example 4
Source File: ZkController.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void createCollection(String collection) throws Exception {
  ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION,
      CollectionParams.CollectionAction.CREATE.toLower(), ZkStateReader.NODE_NAME_PROP, getNodeName(),
      ZkStateReader.COLLECTION_PROP, collection);
  overseerJobQueue.offer(Utils.toJSON(m));
}
 
Example 5
Source File: ReplicaMutator.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public ZkWriteCommand addReplicaProperty(ClusterState clusterState, ZkNodeProps message) {
  if (!checkKeyExistence(message, ZkStateReader.COLLECTION_PROP) ||
      !checkKeyExistence(message, ZkStateReader.SHARD_ID_PROP) ||
      !checkKeyExistence(message, ZkStateReader.REPLICA_PROP) ||
      !checkKeyExistence(message, ZkStateReader.PROPERTY_PROP) ||
      !checkKeyExistence(message, ZkStateReader.PROPERTY_VALUE_PROP)) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "Overseer ADDREPLICAPROP requires " +
            ZkStateReader.COLLECTION_PROP + " and " + ZkStateReader.SHARD_ID_PROP + " and " +
            ZkStateReader.REPLICA_PROP + " and " + ZkStateReader.PROPERTY_PROP + " and " +
            ZkStateReader.PROPERTY_VALUE_PROP + " no action taken.");
  }

  String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP);
  String sliceName = message.getStr(ZkStateReader.SHARD_ID_PROP);
  String replicaName = message.getStr(ZkStateReader.REPLICA_PROP);
  String property = message.getStr(ZkStateReader.PROPERTY_PROP).toLowerCase(Locale.ROOT);
  if (StringUtils.startsWith(property, OverseerCollectionMessageHandler.COLL_PROP_PREFIX) == false) {
    property = OverseerCollectionMessageHandler.COLL_PROP_PREFIX + property;
  }
  property = property.toLowerCase(Locale.ROOT);
  String propVal = message.getStr(ZkStateReader.PROPERTY_VALUE_PROP);
  String shardUnique = message.getStr(OverseerCollectionMessageHandler.SHARD_UNIQUE);

  boolean isUnique = false;

  if (SliceMutator.SLICE_UNIQUE_BOOLEAN_PROPERTIES.contains(property)) {
    if (StringUtils.isNotBlank(shardUnique) && Boolean.parseBoolean(shardUnique) == false) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Overseer ADDREPLICAPROP for " +
          property + " cannot have " + OverseerCollectionMessageHandler.SHARD_UNIQUE + " set to anything other than" +
          "'true'. No action taken");
    }
    isUnique = true;
  } else {
    isUnique = Boolean.parseBoolean(shardUnique);
  }

  DocCollection collection = clusterState.getCollection(collectionName);
  Replica replica = collection.getReplica(replicaName);

  if (replica == null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection/slice/replica " +
        collectionName + "/" + sliceName + "/" + replicaName + " no action taken.");
  }
  log.info("Setting property {} with value {} for collection {}", property, propVal, collectionName);
  log.debug("Full message: {}", message);
  if (StringUtils.equalsIgnoreCase(replica.getStr(property), propVal))
    return ZkStateWriter.NO_OP; // already the value we're going to set

  // OK, there's no way we won't change the cluster state now
  Map<String, Replica> replicas = collection.getSlice(sliceName).getReplicasCopy();
  if (isUnique == false) {
    replicas.get(replicaName).getProperties().put(property, propVal);
  } else { // Set prop for this replica, but remove it for all others.
    for (Replica rep : replicas.values()) {
      if (rep.getName().equalsIgnoreCase(replicaName)) {
        rep.getProperties().put(property, propVal);
      } else {
        rep.getProperties().remove(property);
      }
    }
  }
  Slice newSlice = new Slice(sliceName, replicas, collection.getSlice(sliceName).shallowCopy(),collectionName);
  DocCollection newCollection = CollectionMutator.updateSlice(collectionName, collection,
      newSlice);
  return new ZkWriteCommand(collectionName, newCollection);
}
 
Example 6
Source File: DeleteReplicaTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void deleteReplicaFromClusterState() throws Exception {
  final String collectionName = "deleteFromClusterStateCollection";
  CollectionAdminRequest.createCollection(collectionName, "conf", 1, 3)
      .process(cluster.getSolrClient());
  
  cluster.waitForActiveCollection(collectionName, 1, 3);
  
  cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1"));
  cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "2"));
  cluster.getSolrClient().commit(collectionName);

  cluster.waitForActiveCollection(collectionName, 1, 3);

  Slice shard = getCollectionState(collectionName).getSlice("shard1");

  // don't choose the leader to shutdown, it just complicates things unnecessarily
  Replica replica = getRandomReplica(shard, (r) ->
                                     ( r.getState() == Replica.State.ACTIVE &&
                                       ! r.equals(shard.getLeader())));
  
  JettySolrRunner replicaJetty = cluster.getReplicaJetty(replica);
  ZkStateReaderAccessor accessor = new ZkStateReaderAccessor(replicaJetty.getCoreContainer().getZkController().getZkStateReader());

  final long preDeleteWatcherCount = countUnloadCoreOnDeletedWatchers
    (accessor.getStateWatchers(collectionName));

  ZkNodeProps m = new ZkNodeProps(
      Overseer.QUEUE_OPERATION, OverseerAction.DELETECORE.toLower(),
      ZkStateReader.CORE_NAME_PROP, replica.getCoreName(),
      ZkStateReader.NODE_NAME_PROP, replica.getNodeName(),
      ZkStateReader.COLLECTION_PROP, collectionName,
      ZkStateReader.CORE_NODE_NAME_PROP, replica.getName(),
      ZkStateReader.BASE_URL_PROP, replica.getBaseUrl());

  cluster.getOpenOverseer().getStateUpdateQueue().offer(Utils.toJSON(m));

  waitForState("Timeout waiting for replica get deleted", collectionName,
      (liveNodes, collectionState) -> collectionState.getSlice("shard1").getReplicas().size() == 2);

  TimeOut timeOut = new TimeOut(60, TimeUnit.SECONDS, TimeSource.NANO_TIME);
  timeOut.waitFor("Waiting for replica get unloaded", () ->
      replicaJetty.getCoreContainer().getCoreDescriptor(replica.getCoreName()) == null
  );
  
  // the core should no longer have a watch collection state since it was removed
  timeOut = new TimeOut(60, TimeUnit.SECONDS, TimeSource.NANO_TIME);
  timeOut.waitFor("Waiting for core's watcher to be removed", () -> {
      final long postDeleteWatcherCount = countUnloadCoreOnDeletedWatchers
        (accessor.getStateWatchers(collectionName));
      log.info("preDeleteWatcherCount={} vs postDeleteWatcherCount={}",
               preDeleteWatcherCount, postDeleteWatcherCount);
      return (preDeleteWatcherCount - 1L == postDeleteWatcherCount);
    });
  
  CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
}