Skip to content

Commit

Permalink
Http2SolrClient - a work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
markrmiller committed May 7, 2018
1 parent ee7b52f commit f1134ee
Show file tree
Hide file tree
Showing 184 changed files with 2,682 additions and 2,073 deletions.
3 changes: 2 additions & 1 deletion lucene/ivy-versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ org.codehaus.janino.version = 2.7.6
/org.codehaus.woodstox/stax2-api = 3.1.4
/org.codehaus.woodstox/woodstox-core-asl = 4.4.1

org.eclipse.jetty.version = 9.4.8.v20171121
org.eclipse.jetty.version = 9.4.9.v20180320
/org.eclipse.jetty/jetty-continuation = ${org.eclipse.jetty.version}
/org.eclipse.jetty/jetty-deploy = ${org.eclipse.jetty.version}
/org.eclipse.jetty/jetty-http = ${org.eclipse.jetty.version}
Expand All @@ -268,6 +268,7 @@ org.eclipse.jetty.version = 9.4.8.v20171121
/org.eclipse.jetty/jetty-util = ${org.eclipse.jetty.version}
/org.eclipse.jetty/jetty-webapp = ${org.eclipse.jetty.version}
/org.eclipse.jetty/jetty-xml = ${org.eclipse.jetty.version}
/org.eclipse.jetty/jetty-client = ${org.eclipse.jetty.version}

org.gagravarr.vorbis.java.version = 0.8
/org.gagravarr/vorbis-java-core = ${org.gagravarr.vorbis.java.version}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import java.util.Iterator;
import java.util.Map;

import org.apache.http.client.HttpClient;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
Expand All @@ -42,6 +42,7 @@
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.CursorMarkParams;
import org.eclipse.jetty.client.HttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -95,7 +96,7 @@ public void destroy() {
* @return a {@link HttpClient} instance used for interfacing with a source Solr service
*/
protected HttpClient getHttpClient() {
return HttpClientUtil.createClient(null);
return Http2SolrClient.createHttpClient(false);
}

@Override
Expand All @@ -110,21 +111,25 @@ protected void firstInit(Context context) {
}

HttpClient client = getHttpClient();
URL url = new URL(serverPath);
// (wt="javabin|xml") default is javabin
if ("xml".equals(context.getResolvedEntityAttribute(CommonParams.WT))) {
// TODO: it doesn't matter for this impl when passing a client currently, but we should close this!
solrClient = new Builder(url.toExternalForm())
.withHttpClient(client)
.withResponseParser(new XMLResponseParser())
.build();
LOG.info("using XMLResponseParser");
} else {
// TODO: it doesn't matter for this impl when passing a client currently, but we should close this!
solrClient = new Builder(url.toExternalForm())
.withHttpClient(client)
.build();
LOG.info("using BinaryResponseParser");
try {
URL url = new URL(serverPath);
// (wt="javabin|xml") default is javabin
if ("xml".equals(context.getResolvedEntityAttribute(CommonParams.WT))) {
// TODO: it doesn't matter for this impl when passing a client currently, but we should close this!
solrClient = new Builder(url.toExternalForm())
.withHttpClient(client)
.withResponseParser(new XMLResponseParser())
.build();
LOG.info("using XMLResponseParser");
} else {
// TODO: it doesn't matter for this impl when passing a client currently, but we should close this!
solrClient = new Builder(url.toExternalForm())
.withHttpClient(client)
.build();
LOG.info("using BinaryResponseParser");
}
} finally {
Http2SolrClient.close(client);
}
} catch (MalformedURLException e) {
throw new DataImportHandlerException(DataImportHandlerException.SEVERE, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.apache.commons.io.FileUtils;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.request.DirectXmlRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void testSimple() throws Exception {
params.set("command", "full-import");
params.set("clean", "false");
req.setParams(params);
try (HttpSolrClient solrClient = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
try (Http2SolrClient solrClient = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
solrClient.request(req);
ModifiableSolrParams qparams = new ModifiableSolrParams();
qparams.add("q", "*:*");
Expand All @@ -89,7 +89,7 @@ public void testCommitWithin() throws Exception {
"clean", "false", UpdateParams.COMMIT, "false",
UpdateParams.COMMIT_WITHIN, "1000");
req.setParams(params);
try (HttpSolrClient solrServer = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
try (Http2SolrClient solrServer = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
solrServer.request(req);
Thread.sleep(100);
ModifiableSolrParams queryAll = params("q", "*", "df", "desc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.lucene.util.IOUtils;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.common.SolrInputDocument;
import org.junit.After;
import org.junit.AfterClass;
Expand Down Expand Up @@ -305,7 +305,7 @@ private void addDocumentsToSolr(List<Map<String,Object>> docs) throws SolrServer
sidl.add(sd);
}

try (HttpSolrClient solrServer = getHttpSolrClient(getSourceUrl(), 15000, 30000)) {
try (Http2SolrClient solrServer = getHttpSolrClient(getSourceUrl(), 15000, 30000)) {
solrServer.add(sidl);
solrServer.commit(true, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public abstract class LanguageIdentifierUpdateProcessorFactoryTestCase extends SolrTestCaseJ4 {

protected static final SolrRequestParsers _parser = new SolrRequestParsers(null);
protected static final SolrRequestParsers _parser = new SolrRequestParsers(null, null);
protected static final SolrQueryResponse resp = new SolrQueryResponse();
protected LanguageIdentifierUpdateProcessor liProcessor;

Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/api/V2HttpCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
}

private void initAdminRequest(String path) throws Exception {
solrReq = SolrRequestParsers.DEFAULT.parse(null, path, req);
solrReq = SolrRequestParsers.createInstance(cores.getFileCleaningTracker()).parse(null, path, req);
solrReq.getContext().put(CoreContainer.class.getName(), cores);
requestType = AuthorizationContext.RequestType.ADMIN;
action = ADMIN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public EmbeddedSolrServer(CoreContainer coreContainer, String coreName) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Core name cannot be empty");
this.coreContainer = coreContainer;
this.coreName = coreName;
_parser = new SolrRequestParsers(null);
_parser = new SolrRequestParsers(null, null);
}

// TODO-- this implementation sends the response to XML and then parses it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public Builder setPort(int port) {
}

public Builder setContext(String context) {
//assert !context.endsWith("/") : context;
this.context = context;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,11 @@
*/
package org.apache.solr.client.solrj.embedded;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.Security;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.LinkedList;
Expand All @@ -41,10 +32,24 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.conscrypt.OpenSSLProvider;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
Expand Down Expand Up @@ -74,9 +79,9 @@ public class JettySolrRunner {

private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private static final int THREAD_POOL_MAX_THREADS = 10000;
private static final int THREAD_POOL_MAX_THREADS = 300;
// NOTE: needs to be larger than SolrHttpClient.threadPoolSweeperMaxIdleTime
private static final int THREAD_POOL_MAX_IDLE_TIME_MS = 120000;
private static final int THREAD_POOL_MAX_IDLE_TIME_MS = 60000;

Server server;

Expand All @@ -97,6 +102,8 @@ public class JettySolrRunner {
private static final String excludePatterns = "/css/.+,/js/.+,/img/.+,/tpl/.+";

private int proxyPort = -1;

private HttpClient httpClient = Http2SolrClient.createHttpClient(false);

public static class DebugFilter implements Filter {
public final static Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Expand Down Expand Up @@ -212,13 +219,14 @@ private void init(int port) {

QueuedThreadPool qtp = new QueuedThreadPool();
qtp.setMaxThreads(THREAD_POOL_MAX_THREADS);
qtp.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
qtp.setMinThreads(4);
qtp.setIdleTimeout(5000);
qtp.setStopTimeout((int) TimeUnit.MINUTES.toMillis(1));
server = new Server(qtp);
server.manage(qtp);
server.setStopAtShutdown(config.stopAtShutdown);

if (System.getProperty("jetty.testMode") != null) {
if (false) {
// if this property is true, then jetty will be configured to use SSL
// leveraging the same system properties as java to specify
// the keystore/truststore if they are set unless specific config
Expand Down Expand Up @@ -250,11 +258,56 @@ private void init(int port) {
server.setConnectors(new Connector[] {connector});
server.setSessionIdManager(new DefaultSessionIdManager(server, new Random()));
} else {
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());
connector.setPort(port);
// ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());
// connector.setPort(port);
// connector.setSoLingerTime(-1);
// connector.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
// connector.setHost("127.0.0.1");
// server.setConnectors(new Connector[] {connector});

Security.addProvider(new OpenSSLProvider());

SslContextFactory sslcontext = SSLConfig.createContextFactory(config.sslConfig);

ServerConnector connector;
HttpConfiguration configuration = new HttpConfiguration();
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(configuration);

if (sslcontext != null) {

configuration.setSecureScheme("https");
configuration.addCustomizer(new SecureRequestCustomizer());
sslcontext.setProvider("Conscrypt");
connector = new ServerConnector(server, 1, 1, new SslConnectionFactory(sslcontext, "http/1.1"),
new HttpConnectionFactory(configuration));
} else {
connector = new ServerConnector(server, 1, 1, h2);
}

// HTTP/2 Connection Factory
h2.setMaxConcurrentStreams(20);

connector.addConnectionFactory(h2);

connector.setReuseAddress(true);
connector.setSoLingerTime(-1);
connector.setPort(port);
connector.setHost("127.0.0.1");
connector.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
server.setConnectors(new Connector[] {connector});


// TODO: SSL - only Java 9 and up has built in support for SSL over HTTP2 - you need special jar
// and startup params otherwise
// NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
// ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
// alpn.setDefaultProtocol("h2");
// ServerConnector http2Connector = new ServerConnector(server, 1, 1, h2); // use 1 selector and acceptor instead of cpu based default - can be a bunch of jetties
// http2Connector.setReuseAddress(true);
// http2Connector.setSoLingerTime(-1);
// http2Connector.setPort(port);
// http2Connector.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
// http2Connector.setHost("127.0.0.1");
server.addConnector(connector);
}

// Initialize the servlets
Expand Down Expand Up @@ -425,9 +478,12 @@ public void stop() throws Exception {
Map<String, String> prevContext = MDC.getCopyOfContextMap();
MDC.clear();
try {

Filter filter = dispatchFilter.getFilter();

server.stop();

Http2SolrClient.close(httpClient);

if (server.getState().equals(Server.FAILED)) {
filter.destroy();
Expand Down Expand Up @@ -506,15 +562,37 @@ public URL getBaseUrl() {
("Java could not make sense of protocol: " + protocol, e);
}
}

public URL getBaseUrl2() {
String protocol = null;
try {
Connector[] conns = server.getConnectors();
if (0 == conns.length) {
throw new IllegalStateException("Jetty Server has no Connectors");
}
ServerConnector c = (ServerConnector) conns[0];
if (c.getLocalPort() < 0) {
throw new IllegalStateException("Jetty Connector is not open: " +
c.getLocalPort());
}
protocol = c.getDefaultProtocol().startsWith("SSL") ? "https" : "http";
return new URL(protocol, c.getHost(), c.getLocalPort(), config.context);

} catch (MalformedURLException e) {
throw new IllegalStateException
("Java could not make sense of protocol: " + protocol, e);
}
}

public SolrClient newClient() {
return new HttpSolrClient.Builder(getBaseUrl().toString()).build();
return new Http2SolrClient.Builder(getBaseUrl().toString()).withHttpClient(httpClient).build();
}

public SolrClient newClient(int connectionTimeoutMillis, int socketTimeoutMillis) {
return new HttpSolrClient.Builder(getBaseUrl().toString())
.withConnectionTimeout(connectionTimeoutMillis)
.withSocketTimeout(socketTimeoutMillis)
return new Http2SolrClient.Builder(getBaseUrl().toString())
//.withConnectionTimeout(connectionTimeoutMillis)
//.withSocketTimeout(socketTimeoutMillis)
.withHttpClient(httpClient)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void setClientAuth(boolean clientAuth) {

/** All other settings on this object are ignored unless this is true */
public boolean isSSLMode() {
return useSsl;
return false; //nocommit
}

public boolean isClientAuthMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.apache.http.NoHttpResponseException;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.request.CoreAdminRequest.RequestRecovery;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
Expand Down Expand Up @@ -213,9 +213,10 @@ protected void sendRecoveryCommandWithRetry() throws Exception {
log.info("Asking core={} coreNodeName={} on " + recoveryUrl + " to recover", coreNeedingRecovery, replicaCoreNodeName);
}

try (HttpSolrClient client = new HttpSolrClient.Builder(recoveryUrl)
.withConnectionTimeout(15000)
.withSocketTimeout(60000)
// nocommit no shared exec, but this going away anyway...
try (Http2SolrClient client = new Http2SolrClient.Builder(recoveryUrl)
//.withConnectionTimeout(15000)
//.withSocketTimeout(60000)
.build()) {
try {
client.request(recoverRequestCmd);
Expand Down

0 comments on commit f1134ee

Please sign in to comment.