Search in sources :

Example 51 with SolrException

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

the class ConfigSetProperties method readFromInputStream.

public static NamedList readFromInputStream(InputStreamReader reader) {
    try {
        JSONParser jsonParser = new JSONParser(reader);
        Object object = ObjectBuilder.getVal(jsonParser);
        if (!(object instanceof Map)) {
            final String objectClass = object == null ? "null" : object.getClass().getName();
            throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid JSON type " + objectClass + ", expected Map");
        }
        return new NamedList((Map) object);
    } catch (Exception ex) {
        throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to load ConfigSet properties", ex);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) JSONParser(org.noggit.JSONParser) Map(java.util.Map) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 52 with SolrException

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

the class ConfigSetService method getConfig.

/**
   * Load the ConfigSet for a core
   * @param dcore the core's CoreDescriptor
   * @return a ConfigSet
   */
public final ConfigSet getConfig(CoreDescriptor dcore) {
    SolrResourceLoader coreLoader = createCoreResourceLoader(dcore);
    try {
        // ConfigSet properties are loaded from ConfigSetProperties.DEFAULT_FILENAME file.
        // ConfigSet flags are loaded from the metadata of the ZK node of the configset.
        NamedList properties = createConfigSetProperties(dcore, coreLoader);
        NamedList flags = getConfigSetFlags(dcore, coreLoader);
        boolean trusted = (coreLoader instanceof ZkSolrResourceLoader && flags != null && flags.get("trusted") != null && !flags.getBooleanArg("trusted")) ? false : true;
        SolrConfig solrConfig = createSolrConfig(dcore, coreLoader);
        IndexSchema schema = createIndexSchema(dcore, solrConfig);
        return new ConfigSet(configName(dcore), solrConfig, schema, properties, trusted);
    } catch (Exception e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not load conf for core " + dcore.getName() + ": " + e.getMessage(), e);
    }
}
Also used : ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) NamedList(org.apache.solr.common.util.NamedList) IndexSchema(org.apache.solr.schema.IndexSchema) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 53 with SolrException

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

the class CorePropertiesLocator method create.

@Override
public void create(CoreContainer cc, CoreDescriptor... coreDescriptors) {
    for (CoreDescriptor cd : coreDescriptors) {
        Path propertiesFile = this.rootDirectory.resolve(cd.getInstanceDir()).resolve(PROPERTIES_FILENAME);
        if (Files.exists(propertiesFile))
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not create a new core in " + cd.getInstanceDir() + "as another core is already defined there");
        writePropertiesFile(cd, propertiesFile);
    }
}
Also used : Path(java.nio.file.Path) SolrException(org.apache.solr.common.SolrException)

Example 54 with SolrException

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

the class CloserThread method reload.

/**
   * Recreates a SolrCore.
   * While the new core is loading, requests will continue to be dispatched to
   * and processed by the old core
   * 
   * @param name the name of the SolrCore to reload
   */
public void reload(String name) {
    SolrCore core = solrCores.getCoreFromAnyList(name, false);
    if (core != null) {
        // The underlying core properties files may have changed, we don't really know. So we have a (perhaps) stale
        // CoreDescriptor and we need to reload it from the disk files
        CoreDescriptor cd = reloadCoreDescriptor(core.getCoreDescriptor());
        solrCores.addCoreDescriptor(cd);
        try {
            solrCores.waitAddPendingCoreOps(cd.getName());
            ConfigSet coreConfig = coreConfigService.getConfig(cd);
            log.info("Reloading SolrCore '{}' using configuration from {}", cd.getName(), coreConfig.getName());
            SolrCore newCore = core.reload(coreConfig);
            registerCore(cd, newCore, false, false);
            if (getZkController() != null) {
                DocCollection docCollection = getZkController().getClusterState().getCollection(cd.getCollectionName());
                Replica replica = docCollection.getReplica(cd.getCloudDescriptor().getCoreNodeName());
                assert replica != null;
                if (replica.getType() == Replica.Type.TLOG) {
                    //TODO: needed here?
                    getZkController().stopReplicationFromLeader(core.getName());
                    if (!cd.getCloudDescriptor().isLeader()) {
                        getZkController().startReplicationFromLeader(newCore.getName(), true);
                    }
                }
            }
        } catch (SolrCoreState.CoreIsClosedException e) {
            throw e;
        } catch (Exception e) {
            coreInitFailures.put(cd.getName(), new CoreLoadFailure(cd, e));
            throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to reload core [" + cd.getName() + "]", e);
        } finally {
            solrCores.removeFromPendingOps(cd.getName());
        }
    } else {
        CoreLoadFailure clf = coreInitFailures.get(name);
        if (clf != null) {
            create(clf.cd, true, false);
        } else {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such core: " + name);
        }
    }
}
Also used : SolrCoreState(org.apache.solr.update.SolrCoreState) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SolrException(org.apache.solr.common.SolrException)

Example 55 with SolrException

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

the class CloserThread method processCoreCreateException.

/**
   * Take action when we failed to create a SolrCore. If error is due to corrupt index, try to recover. Various recovery
   * strategies can be specified via system properties "-DCoreInitFailedAction={fromleader, none}"
   *
   * @see CoreInitFailedAction
   *
   * @param original
   *          the problem seen when loading the core the first time.
   * @param dcore
   *          core descriptor for the core to create
   * @param coreConfig
   *          core config for the core to create
   * @return if possible
   * @throws SolrException
   *           rethrows the original exception if we will not attempt to recover, throws a new SolrException with the
   *           original exception as a suppressed exception if there is a second problem creating the solr core.
   */
private SolrCore processCoreCreateException(SolrException original, CoreDescriptor dcore, ConfigSet coreConfig) {
    // Traverse full chain since CIE may not be root exception
    Throwable cause = original;
    while ((cause = cause.getCause()) != null) {
        if (cause instanceof CorruptIndexException) {
            break;
        }
    }
    // If no CorruptIndexExeption, nothing we can try here
    if (cause == null)
        throw original;
    CoreInitFailedAction action = CoreInitFailedAction.valueOf(System.getProperty(CoreInitFailedAction.class.getSimpleName(), "none"));
    log.debug("CorruptIndexException while creating core, will attempt to repair via {}", action);
    switch(action) {
        case // Recovery from leader on a CorruptedIndexException
        fromleader:
            if (isZooKeeperAware()) {
                CloudDescriptor desc = dcore.getCloudDescriptor();
                try {
                    Replica leader = getZkController().getClusterState().getCollection(desc.getCollectionName()).getSlice(desc.getShardId()).getLeader();
                    if (leader != null && leader.getState() == State.ACTIVE) {
                        log.info("Found active leader, will attempt to create fresh core and recover.");
                        resetIndexDirectory(dcore, coreConfig);
                        return new SolrCore(this, dcore, coreConfig);
                    }
                } catch (SolrException se) {
                    se.addSuppressed(original);
                    throw se;
                }
            }
            throw original;
        case none:
            throw original;
        default:
            log.warn("Failed to create core, and did not recognize specified 'CoreInitFailedAction': [{}]. Valid options are {}.", action, Arrays.asList(CoreInitFailedAction.values()));
            throw original;
    }
}
Also used : CorruptIndexException(org.apache.lucene.index.CorruptIndexException) Replica(org.apache.solr.common.cloud.Replica) CloudDescriptor(org.apache.solr.cloud.CloudDescriptor) 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