Java Code Examples for org.apache.solr.common.cloud.ZkNodeProps#containsKey()
The following examples show how to use
org.apache.solr.common.cloud.ZkNodeProps#containsKey() .
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: OverseerTaskQueue.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Returns true if the queue contains a task with the specified async id. */ public boolean containsTaskWithRequestId(String requestIdKey, String requestId) throws KeeperException, InterruptedException { List<String> childNames = zookeeper.getChildren(dir, null, true); stats.setQueueLength(childNames.size()); for (String childName : childNames) { if (childName != null && childName.startsWith(PREFIX)) { try { byte[] data = zookeeper.getData(dir + "/" + childName, null, null, true); if (data != null) { ZkNodeProps message = ZkNodeProps.load(data); if (message.containsKey(requestIdKey)) { if (log.isDebugEnabled()) { log.debug("Looking for {}, found {}", message.get(requestIdKey), requestId); } if(message.get(requestIdKey).equals(requestId)) return true; } } } catch (KeeperException.NoNodeException e) { // Another client removed the node first, try next } } } return false; }
Example 2
Source File: OverseerCollectionMessageHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public String getTaskKey(ZkNodeProps message) { return message.containsKey(COLLECTION_PROP) ? message.getStr(COLLECTION_PROP) : message.getStr(NAME); }
Example 3
Source File: CreateCollectionCmd.java From lucene-solr with Apache License 2.0 | 4 votes |
private static void getConfName(DistribStateManager stateManager, String collection, String collectionPath, Map<String,Object> collectionProps) throws IOException, KeeperException, InterruptedException { // check for configName log.debug("Looking for collection configName"); if (collectionProps.containsKey("configName")) { if (log.isInfoEnabled()) { log.info("configName was passed as a param {}", collectionProps.get("configName")); } return; } List<String> configNames = null; int retry = 1; int retryLimt = 6; for (; retry < retryLimt; retry++) { if (stateManager.hasData(collectionPath)) { VersionedData data = stateManager.getData(collectionPath); ZkNodeProps cProps = ZkNodeProps.load(data.getData()); if (cProps.containsKey(ZkController.CONFIGNAME_PROP)) { break; } } try { configNames = stateManager.listData(ZkConfigManager.CONFIGS_ZKNODE); } catch (NoSuchElementException | NoNodeException e) { // just keep trying } // check if there's a config set with the same name as the collection if (configNames != null && configNames.contains(collection)) { log.info("Could not find explicit collection configName, but found config name matching collection name - using that set."); collectionProps.put(ZkController.CONFIGNAME_PROP, collection); break; } // if _default exists, use that if (configNames != null && configNames.contains(ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME)) { log.info("Could not find explicit collection configName, but found _default config set - using that set."); collectionProps.put(ZkController.CONFIGNAME_PROP, ConfigSetsHandlerApi.DEFAULT_CONFIGSET_NAME); break; } // if there is only one conf, use that if (configNames != null && configNames.size() == 1) { // no config set named, but there is only 1 - use it if (log.isInfoEnabled()) { log.info("Only one config set found in zk - using it: {}", configNames.get(0)); } collectionProps.put(ZkController.CONFIGNAME_PROP, configNames.get(0)); break; } log.info("Could not find collection configName - pausing for 3 seconds and trying again - try: {}", retry); Thread.sleep(3000); } if (retry == retryLimt) { log.error("Could not find configName for collection {}", collection); throw new ZooKeeperException( SolrException.ErrorCode.SERVER_ERROR, "Could not find configName for collection " + collection + " found:" + configNames); } }
Example 4
Source File: MigrateCmd.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void call(ClusterState clusterState, ZkNodeProps message, @SuppressWarnings({"rawtypes"})NamedList results) throws Exception { String extSourceCollectionName = message.getStr("collection"); String splitKey = message.getStr("split.key"); String extTargetCollectionName = message.getStr("target.collection"); int timeout = message.getInt("forward.timeout", 10 * 60) * 1000; boolean followAliases = message.getBool(FOLLOW_ALIASES, false); String sourceCollectionName; String targetCollectionName; if (followAliases) { sourceCollectionName = ocmh.cloudManager.getClusterStateProvider().resolveSimpleAlias(extSourceCollectionName); targetCollectionName = ocmh.cloudManager.getClusterStateProvider().resolveSimpleAlias(extTargetCollectionName); } else { sourceCollectionName = extSourceCollectionName; targetCollectionName = extTargetCollectionName; } DocCollection sourceCollection = clusterState.getCollection(sourceCollectionName); if (sourceCollection == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown source collection: " + sourceCollectionName); } DocCollection targetCollection = clusterState.getCollection(targetCollectionName); if (targetCollection == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown target collection: " + sourceCollectionName); } if (!(sourceCollection.getRouter() instanceof CompositeIdRouter)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Source collection must use a compositeId router"); } if (!(targetCollection.getRouter() instanceof CompositeIdRouter)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Target collection must use a compositeId router"); } if (splitKey == null || splitKey.trim().length() == 0) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "The split.key cannot be null or empty"); } CompositeIdRouter sourceRouter = (CompositeIdRouter) sourceCollection.getRouter(); CompositeIdRouter targetRouter = (CompositeIdRouter) targetCollection.getRouter(); Collection<Slice> sourceSlices = sourceRouter.getSearchSlicesSingle(splitKey, null, sourceCollection); if (sourceSlices.isEmpty()) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No active slices available in source collection: " + sourceCollection + "for given split.key: " + splitKey); } Collection<Slice> targetSlices = targetRouter.getSearchSlicesSingle(splitKey, null, targetCollection); if (targetSlices.isEmpty()) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No active slices available in target collection: " + targetCollection + "for given split.key: " + splitKey); } String asyncId = null; if (message.containsKey(ASYNC) && message.get(ASYNC) != null) asyncId = message.getStr(ASYNC); for (Slice sourceSlice : sourceSlices) { for (Slice targetSlice : targetSlices) { log.info("Migrating source shard: {} to target shard: {} for split.key = {}", sourceSlice, targetSlice, splitKey); migrateKey(clusterState, sourceCollection, sourceSlice, targetCollection, targetSlice, splitKey, timeout, results, asyncId, message); } } }