org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler Maven / Gradle / Ivy
Show all versions of solr-core Show documentation
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.cloud.api.collections;
import static org.apache.solr.cloud.api.collections.CollectionHandlingUtils.addExceptionToNamedList;
import static org.apache.solr.cloud.api.collections.CollectionHandlingUtils.logFailedOperation;
import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICA_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.SHARD_ID_PROP;
import static org.apache.solr.common.params.CommonParams.NAME;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
import org.apache.solr.cloud.LockTree;
import org.apache.solr.cloud.Overseer;
import org.apache.solr.cloud.OverseerMessageHandler;
import org.apache.solr.cloud.OverseerNodePrioritizer;
import org.apache.solr.cloud.OverseerSolrResponse;
import org.apache.solr.cloud.Stats;
import org.apache.solr.common.SolrCloseable;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CollectionParams.CollectionAction;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.handler.component.HttpShardHandlerFactory;
import org.apache.solr.logging.MDCLoggingContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A {@link OverseerMessageHandler} that handles Collections API related overseer messages.
*
* A lot of the content that was in this class got moved to {@link CollectionHandlingUtils} and
* {@link CollApiCmds}.
*
*
The equivalent of this class for distributed Collection API command execution is {@link
* DistributedCollectionConfigSetCommandRunner}.
*/
public class OverseerCollectionMessageHandler implements OverseerMessageHandler, SolrCloseable {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Overseer overseer;
HttpShardHandlerFactory shardHandlerFactory;
String adminPath;
ZkStateReader zkStateReader;
SolrCloudManager cloudManager;
String myId;
Stats stats;
TimeSource timeSource;
// Set that tracks collections that are currently being processed by a running task.
// This is used for handling mutual exclusion of the tasks.
private final LockTree lockTree = new LockTree();
ExecutorService tpe =
new ExecutorUtil.MDCAwareThreadPoolExecutor(
5,
10,
0L,
TimeUnit.MILLISECONDS,
new SynchronousQueue<>(),
new SolrNamedThreadFactory("OverseerCollectionMessageHandlerThreadFactory"));
private final CollApiCmds.CommandMap commandMapper;
private volatile boolean isClosed;
public OverseerCollectionMessageHandler(
ZkStateReader zkStateReader,
String myId,
final HttpShardHandlerFactory shardHandlerFactory,
String adminPath,
Stats stats,
Overseer overseer,
OverseerNodePrioritizer overseerPrioritizer) {
this.zkStateReader = zkStateReader;
this.shardHandlerFactory = shardHandlerFactory;
this.adminPath = adminPath;
this.myId = myId;
this.stats = stats;
this.overseer = overseer;
this.cloudManager = overseer.getSolrCloudManager();
this.timeSource = cloudManager.getTimeSource();
this.isClosed = false;
commandMapper =
new CollApiCmds.CommandMap(new OcmhCollectionCommandContext(this), overseerPrioritizer);
}
@Override
public OverseerSolrResponse processMessage(ZkNodeProps message, String operation) {
// sometimes overseer messages have the collection name in 'name' field, not 'collection'
MDCLoggingContext.setCollection(
message.getStr(COLLECTION_PROP) != null
? message.getStr(COLLECTION_PROP)
: message.getStr(NAME));
MDCLoggingContext.setShard(message.getStr(SHARD_ID_PROP));
MDCLoggingContext.setReplica(message.getStr(REPLICA_PROP));
log.debug("OverseerCollectionMessageHandler.processMessage : {} , {}", operation, message);
NamedList