Search in sources :

Example 86 with ModifiableSolrParams

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

the class SolrCmdDistributorTest method testMaxRetries.

private void testMaxRetries() throws IOException {
    final MockStreamingSolrClients streamingClients = new MockStreamingSolrClients(updateShardHandler);
    SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(streamingClients, 5, 0);
    streamingClients.setExp(Exp.CONNECT_EXCEPTION);
    ArrayList<Node> nodes = new ArrayList<>();
    final HttpSolrClient solrclient1 = (HttpSolrClient) clients.get(0);
    final AtomicInteger retries = new AtomicInteger();
    ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient1.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
    RetryNode retryNode = new RetryNode(new ZkCoreNodeProps(nodeProps), null, "collection1", "shard1") {

        @Override
        public boolean checkRetry() {
            retries.incrementAndGet();
            return true;
        }
    };
    nodes.add(retryNode);
    AddUpdateCommand cmd = new AddUpdateCommand(null);
    cmd.solrDoc = sdoc("id", id.incrementAndGet());
    ModifiableSolrParams params = new ModifiableSolrParams();
    cmdDistrib.distribAdd(cmd, nodes, params);
    cmdDistrib.finish();
    assertEquals(6, retries.get());
    assertEquals(1, cmdDistrib.getErrors().size());
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) Node(org.apache.solr.update.SolrCmdDistributor.Node) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) ArrayList(java.util.ArrayList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 87 with ModifiableSolrParams

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

the class SolrCmdDistributorTest method testOneRetry.

private void testOneRetry() throws Exception {
    final HttpSolrClient solrclient = (HttpSolrClient) clients.get(0);
    long numFoundBefore = solrclient.query(new SolrQuery("*:*")).getResults().getNumFound();
    final MockStreamingSolrClients streamingClients = new MockStreamingSolrClients(updateShardHandler);
    SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(streamingClients, 5, 0);
    streamingClients.setExp(Exp.CONNECT_EXCEPTION);
    ArrayList<Node> nodes = new ArrayList<>();
    ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
    final AtomicInteger retries = new AtomicInteger();
    nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
    RetryNode retryNode = new RetryNode(new ZkCoreNodeProps(nodeProps), null, "collection1", "shard1") {

        @Override
        public boolean checkRetry() {
            streamingClients.setExp(null);
            retries.incrementAndGet();
            return true;
        }
    };
    nodes.add(retryNode);
    AddUpdateCommand cmd = new AddUpdateCommand(null);
    cmd.solrDoc = sdoc("id", id.incrementAndGet());
    ModifiableSolrParams params = new ModifiableSolrParams();
    CommitUpdateCommand ccmd = new CommitUpdateCommand(null, false);
    cmdDistrib.distribAdd(cmd, nodes, params);
    cmdDistrib.distribCommit(ccmd, nodes, params);
    cmdDistrib.finish();
    assertEquals(1, retries.get());
    long numFoundAfter = solrclient.query(new SolrQuery("*:*")).getResults().getNumFound();
    // we will get java.net.ConnectException which we retry on
    assertEquals(numFoundBefore + 1, numFoundAfter);
    assertEquals(0, cmdDistrib.getErrors().size());
}
Also used : RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) Node(org.apache.solr.update.SolrCmdDistributor.Node) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) ArrayList(java.util.ArrayList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 88 with ModifiableSolrParams

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

the class HttpClientUtil method createClient.

public static CloseableHttpClient createClient(final SolrParams params, PoolingHttpClientConnectionManager cm, boolean sharedConnectionManager, HttpRequestExecutor httpRequestExecutor) {
    final ModifiableSolrParams config = new ModifiableSolrParams(params);
    if (logger.isDebugEnabled()) {
        logger.debug("Creating new http client, config:" + config);
    }
    cm.setMaxTotal(params.getInt(HttpClientUtil.PROP_MAX_CONNECTIONS, 10000));
    cm.setDefaultMaxPerRoute(params.getInt(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 10000));
    cm.setValidateAfterInactivity(Integer.getInteger(VALIDATE_AFTER_INACTIVITY, VALIDATE_AFTER_INACTIVITY_DEFAULT));
    HttpClientBuilder newHttpClientBuilder = HttpClientBuilder.create();
    if (sharedConnectionManager) {
        newHttpClientBuilder.setConnectionManagerShared(true);
    } else {
        newHttpClientBuilder.setConnectionManagerShared(false);
    }
    ConnectionKeepAliveStrategy keepAliveStrat = new ConnectionKeepAliveStrategy() {

        @Override
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            // we only close connections based on idle time, not ttl expiration
            return -1;
        }
    };
    if (httpClientBuilder.getAuthSchemeRegistryProvider() != null) {
        newHttpClientBuilder.setDefaultAuthSchemeRegistry(httpClientBuilder.getAuthSchemeRegistryProvider().getAuthSchemeRegistry());
    }
    if (httpClientBuilder.getCookieSpecRegistryProvider() != null) {
        newHttpClientBuilder.setDefaultCookieSpecRegistry(httpClientBuilder.getCookieSpecRegistryProvider().getCookieSpecRegistry());
    }
    if (httpClientBuilder.getCredentialsProviderProvider() != null) {
        newHttpClientBuilder.setDefaultCredentialsProvider(httpClientBuilder.getCredentialsProviderProvider().getCredentialsProvider());
    }
    newHttpClientBuilder.addInterceptorLast(new DynamicInterceptor());
    newHttpClientBuilder = newHttpClientBuilder.setKeepAliveStrategy(keepAliveStrat).evictIdleConnections((long) Integer.getInteger(EVICT_IDLE_CONNECTIONS, EVICT_IDLE_CONNECTIONS_DEFAULT), TimeUnit.MILLISECONDS);
    if (httpRequestExecutor != null) {
        newHttpClientBuilder.setRequestExecutor(httpRequestExecutor);
    }
    HttpClientBuilder builder = setupBuilder(newHttpClientBuilder, params);
    HttpClient httpClient = builder.setConnectionManager(cm).build();
    assert ObjectReleaseTracker.track(httpClient);
    return (CloseableHttpClient) httpClient;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ConnectionKeepAliveStrategy(org.apache.http.conn.ConnectionKeepAliveStrategy) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 89 with ModifiableSolrParams

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

the class HttpClusterStateProvider method fetchClusterState.

@SuppressWarnings({ "rawtypes", "unchecked" })
private ClusterState fetchClusterState(SolrClient client, String collection) throws SolrServerException, IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("collection", collection);
    params.set("action", "CLUSTERSTATUS");
    QueryRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    NamedList cluster = (SimpleOrderedMap) client.request(request).get("cluster");
    Map<String, Object> collectionsMap = Collections.singletonMap(collection, ((NamedList) cluster.get("collections")).get(collection));
    int znodeVersion = (int) ((Map<String, Object>) (collectionsMap).get(collection)).get("znodeVersion");
    Set<String> liveNodes = new HashSet((List<String>) (cluster.get("live_nodes")));
    this.liveNodes = liveNodes;
    liveNodesTimestamp = System.nanoTime();
    ClusterState cs = ClusterState.load(znodeVersion, collectionsMap, liveNodes, ZkStateReader.CLUSTER_STATE);
    return cs;
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) HashSet(java.util.HashSet)

Example 90 with ModifiableSolrParams

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

the class ModelCache method getModel.

public Tuple getModel(String zkHost, String collection, String modelID, long checkMillis) throws IOException {
    Model model = null;
    long currentTime = new Date().getTime();
    synchronized (this) {
        model = models.get(modelID);
        if (model != null && ((currentTime - model.getLastChecked()) <= checkMillis)) {
            return model.getTuple();
        }
        if (model != null) {
            //model is expired
            models.remove(modelID);
        }
    }
    //Model is not in cache or has expired so fetch the model
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("q", "name_s:" + modelID);
    params.set("fl", "terms_ss, idfs_ds, weights_ds, iteration_i, _version_");
    params.set(SORT, "iteration_i desc");
    StreamContext streamContext = new StreamContext();
    streamContext.setSolrClientCache(solrClientCache);
    CloudSolrStream stream = new CloudSolrStream(zkHost, collection, params);
    stream.setStreamContext(streamContext);
    Tuple tuple = null;
    try {
        stream.open();
        tuple = stream.read();
        if (tuple.EOF) {
            return null;
        }
    } finally {
        stream.close();
    }
    synchronized (this) {
        //check again to see if another thread has updated the same model
        Model m = models.get(modelID);
        if (m != null) {
            Tuple t = m.getTuple();
            long v = t.getLong(VERSION_FIELD);
            if (v >= tuple.getLong(VERSION_FIELD)) {
                return t;
            } else {
                models.put(modelID, new Model(tuple, currentTime));
                return tuple;
            }
        } else {
            models.put(modelID, new Model(tuple, currentTime));
            return tuple;
        }
    }
}
Also used : StreamContext(org.apache.solr.client.solrj.io.stream.StreamContext) CloudSolrStream(org.apache.solr.client.solrj.io.stream.CloudSolrStream) Date(java.util.Date) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)524 Test (org.junit.Test)168 ArrayList (java.util.ArrayList)87 NamedList (org.apache.solr.common.util.NamedList)76 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)74 SolrException (org.apache.solr.common.SolrException)68 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)66 HashMap (java.util.HashMap)61 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)58 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)57 List (java.util.List)56 IOException (java.io.IOException)55 Map (java.util.Map)52 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)52 SolrInputDocument (org.apache.solr.common.SolrInputDocument)51 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)48 Tuple (org.apache.solr.client.solrj.io.Tuple)47 SolrParams (org.apache.solr.common.params.SolrParams)42 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 SolrRequest (org.apache.solr.client.solrj.SolrRequest)36