Search in sources :

Example 16 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.

the class RecoveryStrategy method sendPrepRecoveryCmd.

private final void sendPrepRecoveryCmd(String leaderBaseUrl, String leaderCoreName, Slice slice) throws SolrServerException, IOException, InterruptedException, ExecutionException {
    WaitForState prepCmd = new WaitForState();
    prepCmd.setCoreName(leaderCoreName);
    prepCmd.setNodeName(zkController.getNodeName());
    prepCmd.setCoreNodeName(coreZkNodeName);
    prepCmd.setState(Replica.State.RECOVERING);
    prepCmd.setCheckLive(true);
    prepCmd.setOnlyIfLeader(true);
    final Slice.State state = slice.getState();
    if (state != Slice.State.CONSTRUCTION && state != Slice.State.RECOVERY && state != Slice.State.RECOVERY_FAILED) {
        prepCmd.setOnlyIfLeaderActive(true);
    }
    final int maxTries = 30;
    for (int numTries = 0; numTries < maxTries; numTries++) {
        try {
            sendPrepRecoveryCmd(leaderBaseUrl, prepCmd);
            break;
        } catch (ExecutionException e) {
            if (e.getCause() instanceof SolrServerException) {
                SolrServerException solrException = (SolrServerException) e.getCause();
                if (solrException.getRootCause() instanceof SocketTimeoutException && numTries < maxTries) {
                    LOG.warn("Socket timeout on send prep recovery cmd, retrying.. ");
                    continue;
                }
            }
            throw e;
        }
    }
}
Also used : WaitForState(org.apache.solr.client.solrj.request.CoreAdminRequest.WaitForState) SocketTimeoutException(java.net.SocketTimeoutException) Slice(org.apache.solr.common.cloud.Slice) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.

the class LBHttpSolrClient method doRequest.

protected Exception doRequest(HttpSolrClient client, Req req, Rsp rsp, boolean isNonRetryable, boolean isZombie, String zombieKey) throws SolrServerException, IOException {
    Exception ex = null;
    try {
        rsp.server = client.getBaseURL();
        rsp.rsp = client.request(req.getRequest(), (String) null);
        if (isZombie) {
            zombieServers.remove(zombieKey);
        }
    } catch (SolrException e) {
        // unless it's an update - then we only retry on connect exception
        if (!isNonRetryable && RETRY_CODES.contains(e.code())) {
            ex = (!isZombie) ? addZombie(client, e) : e;
        } else {
            // Server is alive but the request was likely malformed or invalid
            if (isZombie) {
                zombieServers.remove(zombieKey);
            }
            throw e;
        }
    } catch (SocketException e) {
        if (!isNonRetryable || e instanceof ConnectException) {
            ex = (!isZombie) ? addZombie(client, e) : e;
        } else {
            throw e;
        }
    } catch (SocketTimeoutException e) {
        if (!isNonRetryable) {
            ex = (!isZombie) ? addZombie(client, e) : e;
        } else {
            throw e;
        }
    } catch (SolrServerException e) {
        Throwable rootCause = e.getRootCause();
        if (!isNonRetryable && rootCause instanceof IOException) {
            ex = (!isZombie) ? addZombie(client, e) : e;
        } else if (isNonRetryable && rootCause instanceof ConnectException) {
            ex = (!isZombie) ? addZombie(client, e) : e;
        } else {
            throw e;
        }
    } catch (Exception e) {
        throw new SolrServerException(e);
    }
    return ex;
}
Also used : SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException) ConnectException(java.net.ConnectException)

Example 18 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.

the class LBHttpSolrClient method request.

public NamedList<Object> request(final SolrRequest request, String collection, final Integer numServersToTry) throws SolrServerException, IOException {
    Exception ex = null;
    ServerWrapper[] serverList = aliveServerList;
    final int maxTries = (numServersToTry == null ? serverList.length : numServersToTry.intValue());
    int numServersTried = 0;
    Map<String, ServerWrapper> justFailed = null;
    boolean timeAllowedExceeded = false;
    long timeAllowedNano = getTimeAllowedInNanos(request);
    long timeOutTime = System.nanoTime() + timeAllowedNano;
    for (int attempts = 0; attempts < maxTries; attempts++) {
        if (timeAllowedExceeded = isTimeExceeded(timeAllowedNano, timeOutTime)) {
            break;
        }
        int count = counter.incrementAndGet() & Integer.MAX_VALUE;
        ServerWrapper wrapper = serverList[count % serverList.length];
        try {
            ++numServersTried;
            return wrapper.client.request(request, collection);
        } catch (SolrException e) {
            // Server is alive but the request was malformed or invalid
            throw e;
        } catch (SolrServerException e) {
            if (e.getRootCause() instanceof IOException) {
                ex = e;
                moveAliveToDead(wrapper);
                if (justFailed == null)
                    justFailed = new HashMap<>();
                justFailed.put(wrapper.getKey(), wrapper);
            } else {
                throw e;
            }
        } catch (Exception e) {
            throw new SolrServerException(e);
        }
    }
    // try other standard servers that we didn't try just now
    for (ServerWrapper wrapper : zombieServers.values()) {
        if (timeAllowedExceeded = isTimeExceeded(timeAllowedNano, timeOutTime)) {
            break;
        }
        if (wrapper.standard == false || justFailed != null && justFailed.containsKey(wrapper.getKey()))
            continue;
        try {
            ++numServersTried;
            NamedList<Object> rsp = wrapper.client.request(request, collection);
            // remove from zombie list *before* adding to alive to avoid a race that could lose a server
            zombieServers.remove(wrapper.getKey());
            addToAlive(wrapper);
            return rsp;
        } catch (SolrException e) {
            // Server is alive but the request was malformed or invalid
            throw e;
        } catch (SolrServerException e) {
            if (e.getRootCause() instanceof IOException) {
                ex = e;
            // still dead
            } else {
                throw e;
            }
        } catch (Exception e) {
            throw new SolrServerException(e);
        }
    }
    final String solrServerExceptionMessage;
    if (timeAllowedExceeded) {
        solrServerExceptionMessage = "Time allowed to handle this request exceeded";
    } else {
        if (numServersToTry != null && numServersTried > numServersToTry.intValue()) {
            solrServerExceptionMessage = "No live SolrServers available to handle this request:" + " numServersTried=" + numServersTried + " numServersToTry=" + numServersToTry.intValue();
        } else {
            solrServerExceptionMessage = "No live SolrServers available to handle this request";
        }
    }
    if (ex == null) {
        throw new SolrServerException(solrServerExceptionMessage);
    } else {
        throw new SolrServerException(solrServerExceptionMessage, ex);
    }
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SolrException(org.apache.solr.common.SolrException)

Example 19 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.

the class BasicHttpSolrClientTest method testRedirect.

@Test
public void testRedirect() throws Exception {
    final String clientUrl = jetty.getBaseUrl().toString() + "/redirect/foo";
    try (HttpSolrClient client = getHttpSolrClient(clientUrl)) {
        SolrQuery q = new SolrQuery("*:*");
        // default = false
        try {
            client.query(q);
            fail("Should have thrown an exception.");
        } catch (SolrServerException e) {
            assertTrue(e.getMessage().contains("redirect"));
        }
        client.setFollowRedirects(true);
        client.query(q);
        //And back again:
        client.setFollowRedirects(false);
        try {
            client.query(q);
            fail("Should have thrown an exception.");
        } catch (SolrServerException e) {
            assertTrue(e.getMessage().contains("redirect"));
        }
    }
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 20 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.

the class BasicHttpSolrClientTest method testTimeout.

@Test
public void testTimeout() throws Exception {
    SolrQuery q = new SolrQuery("*:*");
    try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/slow/foo")) {
        client.setSoTimeout(2000);
        client.query(q, METHOD.GET);
        fail("No exception thrown.");
    } catch (SolrServerException e) {
        assertTrue(e.getMessage().contains("Timeout"));
    }
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Aggregations

SolrServerException (org.apache.solr.client.solrj.SolrServerException)281 IOException (java.io.IOException)210 SolrQuery (org.apache.solr.client.solrj.SolrQuery)101 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)97 ArrayList (java.util.ArrayList)58 SolrException (org.apache.solr.common.SolrException)57 SolrDocument (org.apache.solr.common.SolrDocument)55 SolrInputDocument (org.apache.solr.common.SolrInputDocument)50 SolrDocumentList (org.apache.solr.common.SolrDocumentList)44 HashMap (java.util.HashMap)30 Map (java.util.Map)29 List (java.util.List)27 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)26 SolrClient (org.apache.solr.client.solrj.SolrClient)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)23 NamedList (org.apache.solr.common.util.NamedList)22 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)19 Date (java.util.Date)18 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)17 SolrParams (org.apache.solr.common.params.SolrParams)13