dsmiley commented on code in PR #2805: URL: https://github.com/apache/solr/pull/2805#discussion_r1821228771
########## solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClientBase.java: ########## @@ -0,0 +1,288 @@ +/* + * 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.client.solrj.impl; + +import static org.apache.solr.common.params.CommonParams.ADMIN_PATHS; + +import java.io.IOException; +import java.net.ConnectException; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.util.Arrays; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.solr.client.solrj.ResponseParser; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.request.IsUpdateRequest; +import org.apache.solr.client.solrj.request.RequestWriter; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.util.NamedList; +import org.slf4j.MDC; + +/** + * LBHttp2SolrClient or "LoadBalanced LBHttp2SolrClient" is a load balancing wrapper around {@link Review Comment: references to Http2SolrClient here should be replaced; could just refer to an Http based SolrClient. ########## solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientIntegrationTest.java: ########## @@ -337,8 +349,27 @@ public void startJetty() throws Exception { fail("TESTING FAILURE: could not grab requested port."); } this.port = newPort; - // System.out.println("waiting........."); - // Thread.sleep(5000); + } + } + + private static class LBClientHolder implements AutoCloseable { Review Comment: instead of a holder, could client return an anonymous subclass that propagates the close? ########## solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClientBase.java: ########## @@ -0,0 +1,288 @@ +/* + * 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.client.solrj.impl; + +import static org.apache.solr.common.params.CommonParams.ADMIN_PATHS; + +import java.io.IOException; +import java.net.ConnectException; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.util.Arrays; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.solr.client.solrj.ResponseParser; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.request.IsUpdateRequest; +import org.apache.solr.client.solrj.request.RequestWriter; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.util.NamedList; +import org.slf4j.MDC; + +/** + * LBHttp2SolrClient or "LoadBalanced LBHttp2SolrClient" is a load balancing wrapper around {@link + * Http2SolrClient}. This is useful when you have multiple Solr endpoints and requests need to be + * Load Balanced among them. + * + * <p>Do <b>NOT</b> use this class for indexing in leader/follower scenarios since documents must be + * sent to the correct leader; no inter-node routing is done. + * + * <p>In SolrCloud (leader/replica) scenarios, it is usually better to use {@link CloudSolrClient}, + * but this class may be used for updates because the server will forward them to the appropriate + * leader. + * + * <p>It offers automatic failover when a server goes down, and it detects when the server comes + * back up. + * + * <p>Load balancing is done using a simple round-robin on the list of endpoints. Endpoint URLs are + * expected to point to the Solr "root" path (i.e. "/solr"). + * + * <blockquote> + * + * <pre> + * SolrClient client = new LBHttp2SolrClient.Builder(http2SolrClient, + * new LBSolrClient.Endpoint("http://host1:8080/solr"), new LBSolrClient.Endpoint("http://host2:8080/solr")) + * .build(); + * </pre> + * + * </blockquote> + * + * Users who wish to balance traffic across a specific set of replicas or cores may specify each + * endpoint as a root-URL and core-name pair. For example: + * + * <blockquote> + * + * <pre> + * SolrClient client = new LBHttp2SolrClient.Builder(http2SolrClient, + * new LBSolrClient.Endpoint("http://host1:8080/solr", "coreA"), + * new LBSolrClient.Endpoint("http://host2:8080/solr", "coreB")) + * .build(); + * </pre> + * + * </blockquote> + * + * <p>If a request to an endpoint fails by an IOException due to a connection timeout or read + * timeout then the host is taken off the list of live endpoints and moved to a 'dead endpoint list' + * and the request is resent to the next live endpoint. This process is continued till it tries all + * the live endpoints. If at least one endpoint is alive, the request succeeds, and if not it fails. + * + * <p>Dead endpoints are periodically healthchecked on a fixed interval controlled by {@link + * LBHttp2SolrClient.Builder#setAliveCheckInterval(int, TimeUnit)}. The default is set to one + * minute. + * + * <p><b>When to use this?</b><br> + * This can be used as a software load balancer when you do not wish to set up an external load + * balancer. Alternatives to this code are to use a dedicated hardware load balancer or using Apache + * httpd with mod_proxy_balancer as a load balancer. See <a + * href="http://en.wikipedia.org/wiki/Load_balancing_(computing)">Load balancing on Wikipedia</a> + * + * @since solr 8.0 + */ +public abstract class LBHttpSolrClientBase<C extends HttpSolrClientBase> extends LBSolrClient { Review Comment: Do we need subclassing? In other words, can we have a general (not abstract) LB SolrClient that accepts an HttpSolrClientBase ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org