Java Code Examples for org.apache.solr.common.cloud.ZkNodeProps#getStr()
The following examples show how to use
org.apache.solr.common.cloud.ZkNodeProps#getStr() .
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: SliceMutator.java From lucene-solr with Apache License 2.0 | 6 votes |
public ZkWriteCommand addReplica(ClusterState clusterState, ZkNodeProps message) { log.info("createReplica() {} ", message); String coll = message.getStr(ZkStateReader.COLLECTION_PROP); if (!checkCollectionKeyExistence(message)) return ZkStateWriter.NO_OP; String slice = message.getStr(ZkStateReader.SHARD_ID_PROP); DocCollection collection = clusterState.getCollection(coll); Slice sl = collection.getSlice(slice); if (sl == null) { log.error("Invalid Collection/Slice {}/{} ", coll, slice); return ZkStateWriter.NO_OP; } String coreNodeName; if (message.getStr(ZkStateReader.CORE_NODE_NAME_PROP) != null) { coreNodeName = message.getStr(ZkStateReader.CORE_NODE_NAME_PROP); } else { coreNodeName = Assign.assignCoreNodeName(stateManager, collection); } Replica replica = new Replica(coreNodeName, makeMap( ZkStateReader.CORE_NAME_PROP, message.getStr(ZkStateReader.CORE_NAME_PROP), ZkStateReader.BASE_URL_PROP, message.getStr(ZkStateReader.BASE_URL_PROP), ZkStateReader.STATE_PROP, message.getStr(ZkStateReader.STATE_PROP), ZkStateReader.NODE_NAME_PROP, message.getStr(ZkStateReader.NODE_NAME_PROP), ZkStateReader.REPLICA_TYPE, message.get(ZkStateReader.REPLICA_TYPE)), coll, slice); return new ZkWriteCommand(coll, updateReplica(collection, sl, replica.getName(), replica)); }
Example 2
Source File: ChaosMonkey.java From lucene-solr with Apache License 2.0 | 6 votes |
private int checkIfKillIsLegal(String sliceName, int numActive) throws KeeperException, InterruptedException { for (CloudJettyRunner cloudJetty : shardToJetty.get(sliceName)) { // get latest cloud state zkStateReader.forceUpdateCollection(collection); DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection); Slice slice = docCollection.getSlice(sliceName); ZkNodeProps props = slice.getReplicasMap().get(cloudJetty.coreNodeName); if (props == null) { throw new RuntimeException("shard name " + cloudJetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet()); } final Replica.State state = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)); final String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP); if (cloudJetty.jetty.isRunning() && state == Replica.State.ACTIVE && zkStateReader.getClusterState().liveNodesContain(nodeName)) { numActive++; } } return numActive; }
Example 3
Source File: AbstractFullDistribZkTestBase.java From lucene-solr with Apache License 2.0 | 5 votes |
public void showCounts() { Set<String> theShards = shardToJetty.keySet(); for (String shard : theShards) { List<CloudJettyRunner> solrJetties = shardToJetty.get(shard); for (CloudJettyRunner cjetty : solrJetties) { ZkNodeProps props = cjetty.info; System.err.println("PROPS:" + props); try { SolrParams query = params("q", "*:*", "rows", "0", "distrib", "false", "tests", "checkShardConsistency"); // "tests" is just a // tag that won't do // anything except be // echoed in logs long num = cjetty.client.solrClient.query(query).getResults() .getNumFound(); System.err.println("DOCS:" + num); } catch (SolrServerException | SolrException | IOException e) { System.err.println("error contacting client: " + e.getMessage() + "\n"); continue; } boolean live = false; String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP); ZkStateReader zkStateReader = cloudClient.getZkStateReader(); if (zkStateReader.getClusterState().liveNodesContain(nodeName)) { live = true; } System.err.println(" live:" + live); } } }
Example 4
Source File: OverseerCollectionConfigSetProcessorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void handleCreateCollMessage(byte[] bytes) { log.info("track created replicas / collections"); try { ZkNodeProps props = ZkNodeProps.load(bytes); if (CollectionParams.CollectionAction.CREATE.isEqual(props.getStr("operation"))) { String collName = props.getStr("name"); if (collName != null) collectionsSet.put(collName, new ClusterState.CollectionRef( new DocCollection(collName, new HashMap<>(), props.getProperties(), DocRouter.DEFAULT))); } if (CollectionParams.CollectionAction.ADDREPLICA.isEqual(props.getStr("operation"))) { replicas.add(props); } } catch (Exception e) {} }
Example 5
Source File: CreateCollectionCmd.java From lucene-solr with Apache License 2.0 | 5 votes |
String getConfigName(String coll, ZkNodeProps message) throws KeeperException, InterruptedException { String configName = message.getStr(COLL_CONF); if (configName == null) { // if there is only one conf, use that List<String> configNames = null; try { configNames = ocmh.zkStateReader.getZkClient().getChildren(ZkConfigManager.CONFIGS_ZKNODE, null, true); if (configNames.contains(ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME)) { if (CollectionAdminParams.SYSTEM_COLL.equals(coll)) { return coll; } else { String intendedConfigSetName = ConfigSetsHandlerApi.getSuffixedNameForAutoGeneratedConfigSet(coll); copyDefaultConfigSetTo(configNames, intendedConfigSetName); return intendedConfigSetName; } } else if (configNames != null && configNames.size() == 1) { configName = configNames.get(0); // no config set named, but there is only 1 - use it log.info("Only one config set found in zk - using it: {}", configName); } } catch (KeeperException.NoNodeException e) { } } return "".equals(configName)? null: configName; }
Example 6
Source File: OverseerConfigSetMessageHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
private String getBaseConfigSetIfCreate(ZkNodeProps message) { String operation = message.getStr(Overseer.QUEUE_OPERATION); if (operation != null) { operation = operation.substring(CONFIGSETS_ACTION_PREFIX.length()); ConfigSetParams.ConfigSetAction action = ConfigSetParams.ConfigSetAction.get(operation); if (action == CREATE) { String baseConfigSetName = message.getStr(BASE_CONFIGSET); if (baseConfigSetName == null || baseConfigSetName.length() == 0) { baseConfigSetName = DEFAULT_CONFIGSET_NAME; } return baseConfigSetName; } } return null; }
Example 7
Source File: CreateAliasCmd.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void call(ClusterState state, ZkNodeProps message, @SuppressWarnings({"rawtypes"})NamedList results) throws Exception { final String aliasName = message.getStr(CommonParams.NAME); ZkStateReader zkStateReader = ocmh.zkStateReader; // make sure we have the latest version of existing aliases if (zkStateReader.aliasesManager != null) { // not a mock ZkStateReader zkStateReader.aliasesManager.update(); } if (!anyRoutingParams(message)) { callCreatePlainAlias(message, aliasName, zkStateReader); } else { callCreateRoutedAlias(message, aliasName, zkStateReader, state); } // Sleep a bit to allow ZooKeeper state propagation. // // THIS IS A KLUDGE. // // Solr's view of the cluster is eventually consistent. *Eventually* all nodes and CloudSolrClients will be aware of // alias changes, but not immediately. If a newly created alias is queried, things should work right away since Solr // will attempt to see if it needs to get the latest aliases when it can't otherwise resolve the name. However // modifications to an alias will take some time. // // We could levy this requirement on the client but they would probably always add an obligatory sleep, which is // just kicking the can down the road. Perhaps ideally at this juncture here we could somehow wait until all // Solr nodes in the cluster have the latest aliases? Thread.sleep(100); }
Example 8
Source File: SliceMutator.java From lucene-solr with Apache License 2.0 | 5 votes |
public ZkWriteCommand updateShardState(ClusterState clusterState, ZkNodeProps message) { String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP); if (!checkCollectionKeyExistence(message)) return ZkStateWriter.NO_OP; log.info("Update shard state invoked for collection: {} with message: {}", collectionName, message); DocCollection collection = clusterState.getCollection(collectionName); Map<String, Slice> slicesCopy = new LinkedHashMap<>(collection.getSlicesMap()); for (String key : message.keySet()) { if (ZkStateReader.COLLECTION_PROP.equals(key)) continue; if (Overseer.QUEUE_OPERATION.equals(key)) continue; Slice slice = collection.getSlice(key); if (slice == null) { throw new RuntimeException("Overseer.updateShardState unknown collection: " + collectionName + " slice: " + key); } if (log.isInfoEnabled()) { log.info("Update shard state {} to {}", key, message.getStr(key)); } Map<String, Object> props = slice.shallowCopy(); if (Slice.State.getState(message.getStr(key)) == Slice.State.ACTIVE) { props.remove(Slice.PARENT); props.remove("shard_parent_node"); props.remove("shard_parent_zk_session"); } props.put(ZkStateReader.STATE_PROP, message.getStr(key)); // we need to use epoch time so that it's comparable across Overseer restarts props.put(ZkStateReader.STATE_TIMESTAMP_PROP, String.valueOf(cloudManager.getTimeSource().getEpochTimeNs())); Slice newSlice = new Slice(slice.getName(), slice.getReplicasCopy(), props,collectionName); slicesCopy.put(slice.getName(), newSlice); } return new ZkWriteCommand(collectionName, collection.copyWithSlices(slicesCopy)); }
Example 9
Source File: RenameCmd.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void call(ClusterState state, ZkNodeProps message, @SuppressWarnings({"rawtypes"})NamedList results) throws Exception { String extCollectionName = message.getStr(CoreAdminParams.NAME); String target = message.getStr(CollectionAdminParams.TARGET); if (ocmh.zkStateReader.aliasesManager != null) { // not a mock ZkStateReader ocmh.zkStateReader.aliasesManager.update(); } if (extCollectionName == null || target == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "both collection 'name' and 'target' name must be specified"); } Aliases aliases = ocmh.zkStateReader.getAliases(); boolean followAliases = message.getBool(FOLLOW_ALIASES, false); String collectionName; if (followAliases) { collectionName = aliases.resolveSimpleAlias(extCollectionName); } else { collectionName = extCollectionName; } if (!state.hasCollection(collectionName)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "source collection '" + collectionName + "' not found."); } if (ocmh.zkStateReader.getAliases().hasAlias(target)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "target alias '" + target + "' exists: " + ocmh.zkStateReader.getAliases().getCollectionAliasListMap().get(target)); } ocmh.zkStateReader.aliasesManager.applyModificationAndExportToZk(a -> a.cloneWithRename(extCollectionName, target)); }
Example 10
Source File: ReplicaMutator.java From lucene-solr with Apache License 2.0 | 5 votes |
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 11
Source File: ClusterStateMutator.java From lucene-solr with Apache License 2.0 | 5 votes |
public ZkWriteCommand deleteCollection(ClusterState clusterState, ZkNodeProps message) { final String collection = message.getStr(NAME); if (!CollectionMutator.checkKeyExistence(message, NAME)) return ZkStateWriter.NO_OP; DocCollection coll = clusterState.getCollectionOrNull(collection); if (coll == null) return ZkStateWriter.NO_OP; return new ZkWriteCommand(coll.getName(), null); }
Example 12
Source File: OverseerCollectionMessageHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public OverseerSolrResponse processMessage(ZkNodeProps message, String operation) { MDCLoggingContext.setCollection(message.getStr(COLLECTION)); MDCLoggingContext.setShard(message.getStr(SHARD_ID_PROP)); MDCLoggingContext.setReplica(message.getStr(REPLICA_PROP)); log.debug("OverseerCollectionMessageHandler.processMessage : {} , {}", operation, message); @SuppressWarnings({"rawtypes"}) NamedList results = new NamedList(); try { CollectionAction action = getCollectionAction(operation); Cmd command = commandMap.get(action); if (command != null) { command.call(cloudManager.getClusterStateProvider().getClusterState(), message, results); } else { throw new SolrException(ErrorCode.BAD_REQUEST, "Unknown operation:" + operation); } } catch (Exception e) { String collName = message.getStr("collection"); if (collName == null) collName = message.getStr(NAME); if (collName == null) { SolrException.log(log, "Operation " + operation + " failed", e); } else { SolrException.log(log, "Collection: " + collName + " operation: " + operation + " failed", e); } results.add("Operation " + operation + " caused exception:", e); SimpleOrderedMap<Object> nl = new SimpleOrderedMap<>(); nl.add("msg", e.getMessage()); nl.add("rspCode", e instanceof SolrException ? ((SolrException)e).code() : -1); results.add("exception", nl); } return new OverseerSolrResponse(results); }
Example 13
Source File: ReplicaMutator.java From lucene-solr with Apache License 2.0 | 4 votes |
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 14
Source File: SimClusterStateProvider.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Add a new replica. Note that if any details of a replica (node, coreNodeName, SolrCore name, etc) * are missing they will be filled in using the policy framework. * @param message replica details * @param results result of the operation */ @SuppressWarnings({"unchecked", "rawtypes"}) public void simAddReplica(ZkNodeProps message, NamedList results) throws Exception { if (message.getStr(CommonAdminParams.ASYNC) != null) { results.add(CoreAdminParams.REQUESTID, message.getStr(CommonAdminParams.ASYNC)); } ClusterState clusterState = getClusterState(); DocCollection coll = clusterState.getCollection(message.getStr(ZkStateReader.COLLECTION_PROP)); AtomicReference<PolicyHelper.SessionWrapper> sessionWrapper = new AtomicReference<>(); Replica.Type replicaType = Replica.Type.valueOf(message.getStr(ZkStateReader.REPLICA_TYPE, Replica.Type.NRT.name()).toUpperCase(Locale.ROOT)); EnumMap<Replica.Type, Integer> replicaTypesVsCount = new EnumMap<>(Replica.Type.class); replicaTypesVsCount.put(Replica.Type.NRT, message.getInt(NRT_REPLICAS, replicaType == Replica.Type.NRT ? 1 : 0)); replicaTypesVsCount.put(Replica.Type.TLOG, message.getInt(TLOG_REPLICAS, replicaType == Replica.Type.TLOG ? 1 : 0)); replicaTypesVsCount.put(Replica.Type.PULL, message.getInt(PULL_REPLICAS, replicaType == Replica.Type.PULL ? 1 : 0)); int totalReplicas = 0; for (Map.Entry<Replica.Type, Integer> entry : replicaTypesVsCount.entrySet()) { totalReplicas += entry.getValue(); } if (totalReplicas > 1) { if (message.getStr(CoreAdminParams.NAME) != null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot create " + totalReplicas + " replicas if 'name' parameter is specified"); } if (message.getStr(CoreAdminParams.CORE_NODE_NAME) != null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot create " + totalReplicas + " replicas if 'coreNodeName' parameter is specified"); } } List<ReplicaPosition> replicaPositions = AddReplicaCmd.buildReplicaPositions(cloudManager, clusterState, coll.getName(), message, replicaTypesVsCount, sessionWrapper); for (ReplicaPosition replicaPosition : replicaPositions) { AddReplicaCmd.CreateReplica createReplica = AddReplicaCmd.assignReplicaDetails(cloudManager, clusterState, message, replicaPosition); if (message.getStr(CoreAdminParams.CORE_NODE_NAME) == null) { createReplica.coreNodeName = Assign.assignCoreNodeName(stateManager, coll); } ReplicaInfo ri = new ReplicaInfo( createReplica.coreNodeName, createReplica.coreName, createReplica.collectionName, createReplica.sliceName, createReplica.replicaType, createReplica.node, message.getProperties() ); simAddReplica(ri.getNode(), ri, true); } if (sessionWrapper.get() != null) { sessionWrapper.get().release(); } results.add("success", ""); }
Example 15
Source File: BasicDistributedZk2Test.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test @ShardsFixed(num = 4) public void test() throws Exception { boolean testFinished = false; try { handle.clear(); handle.put("timestamp", SKIPVAL); testNodeWithoutCollectionForwarding(); indexr(id, 1, i1, 100, tlong, 100, t1, "now is the time for all good men", "foo_f", 1.414f, "foo_b", "true", "foo_d", 1.414d); commit(); // make sure we are in a steady state... waitForRecoveriesToFinish(false); assertDocCounts(false); indexAbunchOfDocs(); // check again waitForRecoveriesToFinish(false); commit(); assertDocCounts(VERBOSE); checkQueries(); assertDocCounts(VERBOSE); query("q", "*:*", "sort", "n_tl1 desc"); brindDownShardIndexSomeDocsAndRecover(); query("q", "*:*", "sort", "n_tl1 desc"); // test adding another replica to a shard - it should do a // recovery/replication to pick up the index from the leader addNewReplica(); long docId = testUpdateAndDelete(); // index a bad doc... expectThrows(SolrException.class, () -> indexr(t1, "a doc with no id")); // TODO: bring this to its own method? // try indexing to a leader that has no replicas up ZkStateReader zkStateReader = cloudClient.getZkStateReader(); ZkNodeProps leaderProps = zkStateReader.getLeaderRetry( DEFAULT_COLLECTION, SHARD2); String nodeName = leaderProps.getStr(ZkStateReader.NODE_NAME_PROP); chaosMonkey.stopShardExcept(SHARD2, nodeName); SolrClient client = getClient(nodeName); index_specific(client, "id", docId + 1, t1, "what happens here?"); // expire a session... CloudJettyRunner cloudJetty = shardToJetty.get(SHARD1).get(0); chaosMonkey.expireSession(cloudJetty.jetty); indexr("id", docId + 1, t1, "slip this doc in"); waitForRecoveriesToFinish(false); checkShardConsistency(SHARD1); checkShardConsistency(SHARD2); testFinished = true; } finally { if (!testFinished) { printLayoutOnTearDown = true; } } }
Example 16
Source File: UtilizeNodeCmd.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void call(ClusterState state, ZkNodeProps message, @SuppressWarnings({"rawtypes"})NamedList results) throws Exception { ocmh.checkRequired(message, NODE); String nodeName = message.getStr(NODE); String async = message.getStr(ASYNC); AutoScalingConfig autoScalingConfig = ocmh.overseer.getSolrCloudManager().getDistribStateManager().getAutoScalingConfig(); //first look for any violation that may use this replica List<ZkNodeProps> requests = new ArrayList<>(); //first look for suggestions if any List<Suggester.SuggestionInfo> suggestions = PolicyHelper.getSuggestions(autoScalingConfig, ocmh.overseer.getSolrCloudManager()); for (Suggester.SuggestionInfo suggestionInfo : suggestions) { if (log.isInfoEnabled()) { log.info("op: {}", suggestionInfo.getOperation()); } String coll = null; List<String> pieces = StrUtils.splitSmart(suggestionInfo.getOperation().getPath(), '/'); if (pieces.size() > 1) { coll = pieces.get(2); } else { continue; } log.info("coll: {}", coll); if (suggestionInfo.getOperation() instanceof V2Request) { String targetNode = (String) Utils.getObjectByPath(suggestionInfo.getOperation(), true, "command/move-replica/targetNode"); if (Objects.equals(targetNode, nodeName)) { String replica = (String) Utils.getObjectByPath(suggestionInfo.getOperation(), true, "command/move-replica/replica"); requests.add(new ZkNodeProps(COLLECTION_PROP, coll, CollectionParams.TARGET_NODE, targetNode, ASYNC, async, REPLICA_PROP, replica)); } } } executeAll(requests); PolicyHelper.SessionWrapper sessionWrapper = PolicyHelper.getSession(ocmh.overseer.getSolrCloudManager()); Policy.Session session = sessionWrapper.get(); Suggester initialsuggester = session.getSuggester(MOVEREPLICA) .hint(Suggester.Hint.TARGET_NODE, nodeName); Suggester suggester = null; for (; ; ) { suggester = session.getSuggester(MOVEREPLICA) .hint(Suggester.Hint.TARGET_NODE, nodeName); @SuppressWarnings({"rawtypes"}) SolrRequest request = suggester.getSuggestion(); if (requests.size() > 10) { log.info("too_many_suggestions"); PolicyHelper.logState(ocmh.overseer.getSolrCloudManager(), initialsuggester); break; } log.info("SUGGESTION: {}", request); if (request == null) break; session = suggester.getSession(); requests.add(new ZkNodeProps(COLLECTION_PROP, request.getParams().get(COLLECTION_PROP), CollectionParams.TARGET_NODE, request.getParams().get(CollectionParams.TARGET_NODE), REPLICA_PROP, request.getParams().get(REPLICA_PROP), ASYNC, request.getParams().get(ASYNC))); } if (log.isInfoEnabled()) { log.info("total_suggestions: {}", requests.size()); } if (requests.size() == 0) { PolicyHelper.logState(ocmh.overseer.getSolrCloudManager(), initialsuggester); } sessionWrapper.returnSession(session); try { executeAll(requests); } finally { sessionWrapper.release(); } }
Example 17
Source File: BackupCmd.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void call(ClusterState state, ZkNodeProps message, @SuppressWarnings({"rawtypes"})NamedList results) throws Exception { String extCollectionName = message.getStr(COLLECTION_PROP); boolean followAliases = message.getBool(FOLLOW_ALIASES, false); String collectionName; if (followAliases) { collectionName = ocmh.cloudManager.getClusterStateProvider().resolveSimpleAlias(extCollectionName); } else { collectionName = extCollectionName; } String backupName = message.getStr(NAME); String repo = message.getStr(CoreAdminParams.BACKUP_REPOSITORY); Instant startTime = Instant.now(); CoreContainer cc = ocmh.overseer.getCoreContainer(); BackupRepository repository = cc.newBackupRepository(Optional.ofNullable(repo)); BackupManager backupMgr = new BackupManager(repository, ocmh.zkStateReader); // Backup location URI location = repository.createURI(message.getStr(CoreAdminParams.BACKUP_LOCATION)); URI backupPath = repository.resolve(location, backupName); //Validating if the directory already exists. if (repository.exists(backupPath)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "The backup directory already exists: " + backupPath); } // Create a directory to store backup details. repository.createDirectory(backupPath); String strategy = message.getStr(CollectionAdminParams.INDEX_BACKUP_STRATEGY, CollectionAdminParams.COPY_FILES_STRATEGY); switch (strategy) { case CollectionAdminParams.COPY_FILES_STRATEGY: { copyIndexFiles(backupPath, collectionName, message, results); break; } case CollectionAdminParams.NO_INDEX_BACKUP_STRATEGY: { break; } } log.info("Starting to backup ZK data for backupName={}", backupName); //Download the configs String configName = ocmh.zkStateReader.readConfigName(collectionName); backupMgr.downloadConfigDir(location, backupName, configName); //Save the collection's state (coming from the collection's state.json) //We extract the state and back it up as a separate json DocCollection collectionState = ocmh.zkStateReader.getClusterState().getCollection(collectionName); backupMgr.writeCollectionState(location, backupName, collectionName, collectionState); Properties properties = new Properties(); properties.put(BackupManager.BACKUP_NAME_PROP, backupName); properties.put(BackupManager.COLLECTION_NAME_PROP, collectionName); properties.put(BackupManager.COLLECTION_ALIAS_PROP, extCollectionName); properties.put(CollectionAdminParams.COLL_CONF, configName); properties.put(BackupManager.START_TIME_PROP, startTime.toString()); properties.put(BackupManager.INDEX_VERSION_PROP, Version.LATEST.toString()); //TODO: Add MD5 of the configset. If during restore the same name configset exists then we can compare checksums to see if they are the same. //if they are not the same then we can throw an error or have an 'overwriteConfig' flag //TODO save numDocs for the shardLeader. We can use it to sanity check the restore. backupMgr.writeBackupProperties(location, backupName, properties); backupMgr.downloadCollectionProperties(location, backupName, collectionName); log.info("Completed backing up ZK data for backupName={}", backupName); }
Example 18
Source File: NodeMutator.java From lucene-solr with Apache License 2.0 | 4 votes |
public List<ZkWriteCommand> downNode(ClusterState clusterState, ZkNodeProps message) { List<ZkWriteCommand> zkWriteCommands = new ArrayList<>(); String nodeName = message.getStr(ZkStateReader.NODE_NAME_PROP); log.debug("DownNode state invoked for node: {}", nodeName); Map<String, DocCollection> collections = clusterState.getCollectionsMap(); for (Map.Entry<String, DocCollection> entry : collections.entrySet()) { String collection = entry.getKey(); DocCollection docCollection = entry.getValue(); Map<String,Slice> slicesCopy = new LinkedHashMap<>(docCollection.getSlicesMap()); boolean needToUpdateCollection = false; for (Entry<String, Slice> sliceEntry : slicesCopy.entrySet()) { Slice slice = sliceEntry.getValue(); Map<String, Replica> newReplicas = slice.getReplicasCopy(); Collection<Replica> replicas = slice.getReplicas(); for (Replica replica : replicas) { String rNodeName = replica.getNodeName(); if (rNodeName == null) { throw new RuntimeException("Replica without node name! " + replica); } if (rNodeName.equals(nodeName)) { log.debug("Update replica state for {} to {}", replica, Replica.State.DOWN); Map<String, Object> props = replica.shallowCopy(); props.put(ZkStateReader.STATE_PROP, Replica.State.DOWN.toString()); Replica newReplica = new Replica(replica.getName(), props, collection, slice.getName()); newReplicas.put(replica.getName(), newReplica); needToUpdateCollection = true; } } Slice newSlice = new Slice(slice.getName(), newReplicas, slice.shallowCopy(),collection); slicesCopy.put(slice.getName(), newSlice); } if (needToUpdateCollection) { zkWriteCommands.add(new ZkWriteCommand(collection, docCollection.copyWithSlices(slicesCopy))); } } return zkWriteCommands; }
Example 19
Source File: OverseerConfigSetMessageHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings({"unchecked"}) public OverseerSolrResponse processMessage(ZkNodeProps message, String operation) { @SuppressWarnings({"rawtypes"}) NamedList results = new NamedList(); try { if (!operation.startsWith(CONFIGSETS_ACTION_PREFIX)) { throw new SolrException(ErrorCode.BAD_REQUEST, "Operation does not contain proper prefix: " + operation + " expected: " + CONFIGSETS_ACTION_PREFIX); } operation = operation.substring(CONFIGSETS_ACTION_PREFIX.length()); log.info("OverseerConfigSetMessageHandler.processMessage : {}, {}", operation, message); ConfigSetParams.ConfigSetAction action = ConfigSetParams.ConfigSetAction.get(operation); if (action == null) { throw new SolrException(ErrorCode.BAD_REQUEST, "Unknown operation:" + operation); } switch (action) { case CREATE: createConfigSet(message); break; case DELETE: deleteConfigSet(message); break; default: throw new SolrException(ErrorCode.BAD_REQUEST, "Unknown operation:" + operation); } } catch (Exception e) { String configSetName = message.getStr(NAME); if (configSetName == null) { SolrException.log(log, "Operation " + operation + " failed", e); } else { SolrException.log(log, "ConfigSet: " + configSetName + " operation: " + operation + " failed", e); } results.add("Operation " + operation + " caused exception:", e); @SuppressWarnings({"rawtypes"}) SimpleOrderedMap nl = new SimpleOrderedMap(); nl.add("msg", e.getMessage()); nl.add("rspCode", e instanceof SolrException ? ((SolrException) e).code() : -1); results.add("exception", nl); } return new OverseerSolrResponse(results); }
Example 20
Source File: LeaderElectionIntegrationTest.java From lucene-solr with Apache License 2.0 | 3 votes |
private String getLeader(String collection) throws InterruptedException { ZkNodeProps props = cluster.getSolrClient().getZkStateReader().getLeaderRetry(collection, "shard1", 30000); String leader = props.getStr(ZkStateReader.NODE_NAME_PROP); return leader; }