jdyer1 commented on code in PR #2259:
URL: https://github.com/apache/solr/pull/2259#discussion_r1506571244


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrJdkClient.java:
##########
@@ -0,0 +1,453 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.lang.invoke.MethodHandles;
+import java.net.CookieHandler;
+import java.net.InetSocketAddress;
+import java.net.ProxySelector;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.net.http.HttpTimeoutException;
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import javax.net.ssl.SSLContext;
+import org.apache.solr.client.solrj.ResponseParser;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.RequestWriter;
+import org.apache.solr.client.solrj.util.ClientUtils;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.ExecutorUtil;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.ObjectReleaseTracker;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
+import org.eclipse.jetty.util.BlockingArrayQueue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HttpSolrJdkClient extends HttpSolrClientBase {
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private static final String USER_AGENT =
+      "Solr[" + MethodHandles.lookup().lookupClass().getName() + "] 1.0";
+
+  protected HttpClient client;
+
+  protected ExecutorService executor;
+
+  private boolean shutdownExecutor;
+
+  protected HttpSolrJdkClient(String serverBaseUrl, HttpSolrJdkClient.Builder 
builder) {
+    super(serverBaseUrl, builder);
+
+    HttpClient.Redirect followRedirects =
+        Boolean.TRUE.equals(builder.followRedirects)
+            ? HttpClient.Redirect.NORMAL
+            : HttpClient.Redirect.NEVER;
+    HttpClient.Builder b = 
HttpClient.newBuilder().followRedirects(followRedirects);
+    if (builder.sslContext != null) {
+      b.sslContext(builder.sslContext);
+    }
+
+    if (builder.executor != null) {
+      this.executor = builder.executor;
+      this.shutdownExecutor = false;
+    } else {
+      BlockingArrayQueue<Runnable> queue = new BlockingArrayQueue<>(32, 32);
+      this.executor =
+          new ExecutorUtil.MDCAwareThreadPoolExecutor(
+              4,
+              256,
+              60,
+              TimeUnit.SECONDS,
+              queue,
+              new SolrNamedThreadFactory(this.getClass().getSimpleName()));
+      this.shutdownExecutor = true;
+    }
+    b.executor(this.executor);
+
+    if (builder.useHttp1_1) {
+      b.version(HttpClient.Version.HTTP_1_1);

Review Comment:
   Well, maybe.  The ping is not needed if the user says they prefer http/1..  
Then again the JDK client perhaps might still use Http/2 if the server doesn't 
support http/1.1.  In any case it also is unnecessary if the connection is over 
TLS/SSL.  All of started to seem complicated to me so I just had it try a ping 
every time.
   
   My real worry about this is how it might fail.  I do not know much about 
Http/2 nor about how this Jdk implementation works.  I worry there is no 
guarantee it _never_ will try to do an upgrade request with a chunked POST in 
the future.  I am afraid to release this just to find out it fails 
intermittently for users in production.
   
   The safest thing I think would be to have some type of retry logic, if a 
POST request fails with this kind of problem, then try a ping (or a HEAD 
request?) and then try again, and then if it still fails to fallback to 
http/1.1.  But this also seems like a terrible thing to have to go do.



-- 
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

Reply via email to