Search in sources :

Example 66 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class CollectionsHandler method invokeAction.

void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer cores, CollectionAction action, CollectionOperation operation) throws Exception {
    if (!coreContainer.isZooKeeperAware()) {
        throw new SolrException(BAD_REQUEST, "Invalid request. collections can be accessed only in SolrCloud mode");
    }
    SolrResponse response = null;
    Map<String, Object> props = operation.execute(req, rsp, this);
    String asyncId = req.getParams().get(ASYNC);
    if (props != null) {
        if (asyncId != null) {
            props.put(ASYNC, asyncId);
        }
        props.put(QUEUE_OPERATION, operation.action.toLower());
        ZkNodeProps zkProps = new ZkNodeProps(props);
        if (operation.sendToOCPQueue) {
            response = handleResponse(operation.action.toLower(), zkProps, rsp, operation.timeOut);
        } else
            Overseer.getStateUpdateQueue(coreContainer.getZkController().getZkClient()).offer(Utils.toJSON(props));
        final String collectionName = zkProps.getStr(NAME);
        if (action.equals(CollectionAction.CREATE) && asyncId == null) {
            if (rsp.getException() == null) {
                waitForActiveCollection(collectionName, zkProps, cores, response);
            }
        }
    }
}
Also used : ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) SolrResponse(org.apache.solr.client.solrj.SolrResponse) OverseerSolrResponse(org.apache.solr.cloud.OverseerSolrResponse) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString) SolrException(org.apache.solr.common.SolrException)

Example 67 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class CollectionsHandler method forceLeaderElection.

private static void forceLeaderElection(SolrQueryRequest req, CollectionsHandler handler) {
    ClusterState clusterState = handler.coreContainer.getZkController().getClusterState();
    String collectionName = req.getParams().required().get(COLLECTION_PROP);
    String sliceId = req.getParams().required().get(SHARD_ID_PROP);
    log.info("Force leader invoked, state: {}", clusterState);
    DocCollection collection = clusterState.getCollection(collectionName);
    Slice slice = collection.getSlice(sliceId);
    if (slice == null) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "No shard with name " + sliceId + " exists for collection " + collectionName);
    }
    try {
        // if an active replica is the leader, then all is fine already
        Replica leader = slice.getLeader();
        if (leader != null && leader.getState() == State.ACTIVE) {
            throw new SolrException(ErrorCode.SERVER_ERROR, "The shard already has an active leader. Force leader is not applicable. State: " + slice);
        }
        // Clear out any LIR state
        String lirPath = handler.coreContainer.getZkController().getLeaderInitiatedRecoveryZnodePath(collectionName, sliceId);
        if (handler.coreContainer.getZkController().getZkClient().exists(lirPath, true)) {
            StringBuilder sb = new StringBuilder();
            handler.coreContainer.getZkController().getZkClient().printLayout(lirPath, 4, sb);
            log.info("Cleaning out LIR data, which was: {}", sb);
            handler.coreContainer.getZkController().getZkClient().clean(lirPath);
        }
        // state to active.
        for (Replica rep : slice.getReplicas()) {
            if (clusterState.getLiveNodes().contains(rep.getNodeName())) {
                ShardHandler shardHandler = handler.coreContainer.getShardHandlerFactory().getShardHandler();
                ModifiableSolrParams params = new ModifiableSolrParams();
                params.set(CoreAdminParams.ACTION, CoreAdminAction.FORCEPREPAREFORLEADERSHIP.toString());
                params.set(CoreAdminParams.CORE, rep.getStr("core"));
                String nodeName = rep.getNodeName();
                OverseerCollectionMessageHandler.sendShardRequest(nodeName, params, shardHandler, null, null, CommonParams.CORES_HANDLER_PATH, // synchronous request
                handler.coreContainer.getZkController().getZkStateReader());
            }
        }
        // Wait till we have an active leader
        boolean success = false;
        for (int i = 0; i < 9; i++) {
            Thread.sleep(5000);
            clusterState = handler.coreContainer.getZkController().getClusterState();
            collection = clusterState.getCollection(collectionName);
            slice = collection.getSlice(sliceId);
            if (slice.getLeader() != null && slice.getLeader().getState() == State.ACTIVE) {
                success = true;
                break;
            }
            log.warn("Force leader attempt {}. Waiting 5 secs for an active leader. State of the slice: {}", (i + 1), slice);
        }
        if (success) {
            log.info("Successfully issued FORCELEADER command for collection: {}, shard: {}", collectionName, sliceId);
        } else {
            log.info("Couldn't successfully force leader, collection: {}, shard: {}. Cluster state: {}", collectionName, sliceId, clusterState);
        }
    } catch (SolrException e) {
        throw e;
    } catch (Exception e) {
        throw new SolrException(ErrorCode.SERVER_ERROR, "Error executing FORCELEADER operation for collection: " + collectionName + " shard: " + sliceId, e);
    }
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString) DocCollection(org.apache.solr.common.cloud.DocCollection) ShardHandler(org.apache.solr.handler.component.ShardHandler) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException)

Example 68 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class UpdateRequestHandlerApi method getApiImpl.

private Api getApiImpl() {
    return new Api(ApiBag.getSpec("core.Update")) {

        @Override
        public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
            String path = req.getPath();
            String target = mapping.get(path);
            if (target != null)
                req.getContext().put("path", target);
            try {
                handleRequest(req, rsp);
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
            }
        }
    };
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Api(org.apache.solr.api.Api) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 69 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ReplicationHandler method readIntervalNs.

private static Long readIntervalNs(String interval) {
    if (interval == null)
        return null;
    int result = 0;
    Matcher m = INTERVAL_PATTERN.matcher(interval.trim());
    if (m.find()) {
        String hr = m.group(1);
        String min = m.group(2);
        String sec = m.group(3);
        result = 0;
        try {
            if (sec != null && sec.length() > 0)
                result += Integer.parseInt(sec);
            if (min != null && min.length() > 0)
                result += (60 * Integer.parseInt(min));
            if (hr != null && hr.length() > 0)
                result += (60 * 60 * Integer.parseInt(hr));
            return TimeUnit.NANOSECONDS.convert(result, TimeUnit.SECONDS);
        } catch (NumberFormatException e) {
            throw new SolrException(ErrorCode.SERVER_ERROR, INTERVAL_ERR_MSG);
        }
    } else {
        throw new SolrException(ErrorCode.SERVER_ERROR, INTERVAL_ERR_MSG);
    }
}
Also used : Matcher(java.util.regex.Matcher) SolrException(org.apache.solr.common.SolrException)

Example 70 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class PingRequestHandler method handleRequestBody.

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    SolrParams params = req.getParams();
    // in this case, we want to default distrib to false so
    // we only ping the single node
    Boolean distrib = params.getBool(DISTRIB);
    if (distrib == null) {
        ModifiableSolrParams mparams = new ModifiableSolrParams(params);
        mparams.set(DISTRIB, false);
        req.setParams(mparams);
    }
    String actionParam = params.get("action");
    ACTIONS action = null;
    if (actionParam == null) {
        action = ACTIONS.PING;
    } else {
        try {
            action = ACTIONS.valueOf(actionParam.toUpperCase(Locale.ROOT));
        } catch (IllegalArgumentException iae) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown action: " + actionParam);
        }
    }
    switch(action) {
        case PING:
            if (isPingDisabled()) {
                SolrException e = new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Service disabled");
                rsp.setException(e);
                return;
            }
            handlePing(req, rsp);
            break;
        case ENABLE:
            handleEnable(true);
            break;
        case DISABLE:
            handleEnable(false);
            break;
        case STATUS:
            if (healthcheck == null) {
                SolrException e = new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "healthcheck not configured");
                rsp.setException(e);
            } else {
                rsp.add("status", isPingDisabled() ? "disabled" : "enabled");
            }
    }
}
Also used : ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrException (org.apache.solr.common.SolrException)617 IOException (java.io.IOException)172 ArrayList (java.util.ArrayList)100 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)80 NamedList (org.apache.solr.common.util.NamedList)79 HashMap (java.util.HashMap)75 Map (java.util.Map)70 SolrParams (org.apache.solr.common.params.SolrParams)64 KeeperException (org.apache.zookeeper.KeeperException)60 Test (org.junit.Test)55 Replica (org.apache.solr.common.cloud.Replica)48 Slice (org.apache.solr.common.cloud.Slice)45 DocCollection (org.apache.solr.common.cloud.DocCollection)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)39 SchemaField (org.apache.solr.schema.SchemaField)39 List (java.util.List)38 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)38 SolrServerException (org.apache.solr.client.solrj.SolrServerException)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 SolrCore (org.apache.solr.core.SolrCore)33