This is an automated email from the ASF dual-hosted git repository.

sarkaramrit1993 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 48c3e190444 [Ready] SOLR-5939: A failed merged update stream now 
records its error against each request in the stream (#5075)
48c3e190444 is described below

commit 48c3e190444824667e75b9c91e287303ec384330
Author: Nick <[email protected]>
AuthorDate: Sat Nov 21 19:18:58 2026 -0500

    [Ready] SOLR-5939: A failed merged update stream now records its error 
against each request in the stream (#5075)
---
 changelog/unreleased/SOLR-5939.yml                 |  10 ++
 .../org/apache/solr/update/SolrCmdDistributor.java |  15 +-
 .../apache/solr/update/StreamingSolrClients.java   |  55 ++++++-
 .../update/processor/TolerantUpdateProcessor.java  |   7 +
 .../StreamingSolrClientsErrorAttributionTest.java  | 176 +++++++++++++++++++++
 .../jetty/ConcurrentUpdateJettySolrClient.java     |   1 +
 .../solrj/impl/ConcurrentUpdateBaseSolrClient.java |  86 +++++++++-
 .../solrj/impl/ConcurrentUpdateJdkSolrClient.java  |   1 +
 8 files changed, 332 insertions(+), 19 deletions(-)

diff --git a/changelog/unreleased/SOLR-5939.yml 
b/changelog/unreleased/SOLR-5939.yml
new file mode 100644
index 00000000000..dd2362871cc
--- /dev/null
+++ b/changelog/unreleased/SOLR-5939.yml
@@ -0,0 +1,10 @@
+title: >-
+  Distributed update errors from a merged stream are now recorded against each 
request in the
+  stream instead of the first request sent to the node. If a stream is retried 
after a partial
+  failure, forwarded non-idempotent atomic updates such as increments may be 
applied twice.
+type: fixed
+authors:
+  - name: Nick Shanin
+links:
+  - name: SOLR-5939
+    url: https://issues.apache.org/jira/browse/SOLR-5939
diff --git a/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java 
b/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java
index ea1d2789700..acb6ef0791f 100644
--- a/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java
+++ b/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java
@@ -33,7 +33,6 @@ import java.util.concurrent.CompletionService;
 import java.util.concurrent.ExecutorCompletionService;
 import java.util.concurrent.Future;
 import org.apache.solr.client.solrj.SolrClient;
-import org.apache.solr.client.solrj.impl.ConcurrentUpdateBaseSolrClient;
 import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
 import org.apache.solr.client.solrj.request.UpdateRequest;
 import org.apache.solr.client.solrj.response.JavaBinResponseParser;
@@ -175,8 +174,7 @@ public class SolrCmdDistributor implements Closeable {
             err.req.node.getMaxRetries(),
             err.req.cmd,
             err.req.uReq.getParams(),
-            err.statusCode,
-            err.e);
+            err.statusCode);
       } else {
         SolrCmdDistributor.log.error(
             "FROMLEADER request to {} failed - retrying ... retries: {}/{}. {} 
params: {} rsp: {}",
@@ -185,8 +183,7 @@ public class SolrCmdDistributor implements Closeable {
             err.req.node.getMaxRetries(),
             err.req.cmd,
             err.req.uReq.getParams(),
-            err.statusCode,
-            err.e);
+            err.statusCode);
       }
       submit(err.req, false);
     }
@@ -483,10 +480,10 @@ public class SolrCmdDistributor implements Closeable {
     public int statusCode = -1;
 
     /**
-     * NOTE: This is the request that happened to be executed when this error 
was <b>triggered</b>
-     * the error, but because of how {@link StreamingSolrClients} uses {@link
-     * ConcurrentUpdateBaseSolrClient} it might not actaully be the request 
that <b>caused</b> the
-     * error -- multiple requests are merged &amp; processed as a sequential 
batch.
+     * The request this error is recorded against. When a {@link 
StreamingSolrClients} stream fails,
+     * the error is recorded once against each request that was merged into 
the stream, because a
+     * stream-level failure cannot be narrowed down to the single request 
whose update the remote
+     * node rejected.
      */
     public Req req;
 
diff --git 
a/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java 
b/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java
index dc0b5d77556..46bc5f124b2 100644
--- a/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java
+++ b/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java
@@ -22,6 +22,7 @@ import java.lang.invoke.MethodHandles;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.IdentityHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
@@ -30,6 +31,7 @@ import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.impl.ConcurrentUpdateBaseSolrClient;
 import org.apache.solr.client.solrj.jetty.ConcurrentUpdateJettySolrClient;
 import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
+import org.apache.solr.client.solrj.request.UpdateRequest;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.util.StrUtils;
 import org.apache.solr.update.SolrCmdDistributor.SolrError;
@@ -50,6 +52,10 @@ public class StreamingSolrClients {
   private Map<String, ConcurrentUpdateBaseSolrClient> solrClients = new 
HashMap<>();
   private List<SolrError> errors = Collections.synchronizedList(new 
ArrayList<>());
 
+  // Maps each streamed UpdateRequest to its Req; entries leave when their 
stream completes.
+  private final Map<UpdateRequest, SolrCmdDistributor.Req> reqByUpdateRequest =
+      Collections.synchronizedMap(new IdentityHashMap<>());
+
   private ExecutorService updateExecutor;
 
   public StreamingSolrClients(UpdateShardHandler updateShardHandler) {
@@ -66,6 +72,7 @@ public class StreamingSolrClients {
   }
 
   public synchronized SolrClient getSolrClient(final SolrCmdDistributor.Req 
req) {
+    reqByUpdateRequest.put(req.uReq, req);
     String url = getFullUrl(req.node.getUrl());
     ConcurrentUpdateBaseSolrClient client = solrClients.get(url);
     if (client == null) {
@@ -76,7 +83,7 @@ public class StreamingSolrClients {
           StrUtils.isNotBlank(req.node.getCoreName()) ? req.node.getCoreName() 
: null;
       client =
           new ErrorReportingConcurrentUpdateSolrClient.Builder(
-                  req.node.getBaseUrl(), httpClient, req, errors)
+                  req.node.getBaseUrl(), httpClient, req, errors, 
reqByUpdateRequest)
               .withDefaultCollection(defaultCore)
               .withQueueSize(100)
               .withThreadCount(runnerCount)
@@ -127,26 +134,48 @@ class ErrorReportingConcurrentUpdateSolrClient extends 
ConcurrentUpdateJettySolr
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
   private final SolrCmdDistributor.Req req;
   private final List<SolrError> errors;
+  private final Map<UpdateRequest, SolrCmdDistributor.Req> reqByUpdateRequest;
 
   public ErrorReportingConcurrentUpdateSolrClient(Builder builder) {
     super(builder);
     this.req = builder.req;
     this.errors = builder.errors;
+    this.reqByUpdateRequest = builder.reqByUpdateRequest;
   }
 
   @Override
   public void handleError(Throwable ex) {
-    log.error("Error when calling {} to {}", req, req.node.getUrl(), ex);
+    reqByUpdateRequest.remove(req.uReq);
+    log.error("Update stream failed", ex);
+    recordError(ex, req);
+  }
+
+  @Override
+  protected void handleError(
+      Throwable ex, List<UpdateRequest> requests, List<String> failedIds, 
String collection) {
+    if (requests.isEmpty()) {
+      handleError(ex);
+      return;
+    }
+    log.error("Update stream failed", ex);
+    for (UpdateRequest updateRequest : requests) {
+      SolrCmdDistributor.Req streamReq = 
reqByUpdateRequest.remove(updateRequest);
+      recordError(ex, streamReq != null ? streamReq : req);
+    }
+  }
+
+  private void recordError(Throwable ex, SolrCmdDistributor.Req errorReq) {
+    log.error("Error when calling {} to {}", errorReq, errorReq.node.getUrl());
     SolrError error = new SolrError();
     error.e = (Exception) ex;
     if (ex instanceof SolrException) {
       error.statusCode = ((SolrException) ex).code();
     }
-    error.req = req;
+    error.req = errorReq;
     errors.add(error);
-    if (!req.shouldRetry(error)) {
+    if (!errorReq.shouldRetry(error)) {
       // only track the error if we are not retrying the request
-      req.trackRequestResult(null, null, false);
+      errorReq.trackRequestResult(null, null, false);
     }
   }
 
@@ -156,9 +185,19 @@ class ErrorReportingConcurrentUpdateSolrClient extends 
ConcurrentUpdateJettySolr
     req.trackRequestResult(jettyResponse, respBody, true);
   }
 
+  @Override
+  public void onSuccess(
+      Object responseMetadata, InputStream respBody, List<UpdateRequest> 
requests) {
+    for (UpdateRequest updateRequest : requests) {
+      reqByUpdateRequest.remove(updateRequest);
+    }
+    onSuccess(responseMetadata, respBody);
+  }
+
   static class Builder extends ConcurrentUpdateJettySolrClient.Builder {
     protected SolrCmdDistributor.Req req;
     protected List<SolrError> errors;
+    protected Map<UpdateRequest, SolrCmdDistributor.Req> reqByUpdateRequest;
 
     /**
      * @param baseSolrUrl the base URL of a Solr node. Should <em>not</em> 
contain a collection or
@@ -166,15 +205,19 @@ class ErrorReportingConcurrentUpdateSolrClient extends 
ConcurrentUpdateJettySolr
      * @param client the client to use in making requests
      * @param req the command distributor request object for this client
      * @param errors a collector for any errors
+     * @param reqByUpdateRequest maps each submitted update request back to 
its distributor request,
+     *     for attributing stream errors
      */
     public Builder(
         String baseSolrUrl,
         HttpJettySolrClient client,
         SolrCmdDistributor.Req req,
-        List<SolrError> errors) {
+        List<SolrError> errors,
+        Map<UpdateRequest, SolrCmdDistributor.Req> reqByUpdateRequest) {
       super(baseSolrUrl, client);
       this.req = req;
       this.errors = errors;
+      this.reqByUpdateRequest = reqByUpdateRequest;
     }
 
     @Override
diff --git 
a/solr/core/src/java/org/apache/solr/update/processor/TolerantUpdateProcessor.java
 
b/solr/core/src/java/org/apache/solr/update/processor/TolerantUpdateProcessor.java
index d79df5cc848..7fc0f737082 100644
--- 
a/solr/core/src/java/org/apache/solr/update/processor/TolerantUpdateProcessor.java
+++ 
b/solr/core/src/java/org/apache/solr/update/processor/TolerantUpdateProcessor.java
@@ -19,7 +19,9 @@ package org.apache.solr.update.processor;
 import java.io.IOException;
 import java.lang.invoke.MethodHandles;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.IdentityHashMap;
 import java.util.List;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -233,7 +235,12 @@ public class TolerantUpdateProcessor extends 
UpdateRequestProcessor {
       firstErrTracker.caught(duae);
 
       // adjust our stats based on each of the distributed errors
+      // Errors from one failed stream share an exception; count it once.
+      Set<Exception> aggregatedExceptions = Collections.newSetFromMap(new 
IdentityHashMap<>());
       for (SolrError error : duae.errors) {
+        if (!aggregatedExceptions.add(error.e)) {
+          continue;
+        }
         // we can't trust the req info from the Error, because multiple 
original requests might have
         // been lumped together
         //
diff --git 
a/solr/core/src/test/org/apache/solr/update/StreamingSolrClientsErrorAttributionTest.java
 
b/solr/core/src/test/org/apache/solr/update/StreamingSolrClientsErrorAttributionTest.java
new file mode 100644
index 00000000000..5abe09d803e
--- /dev/null
+++ 
b/solr/core/src/test/org/apache/solr/update/StreamingSolrClientsErrorAttributionTest.java
@@ -0,0 +1,176 @@
+/*
+ * 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.update;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.cloud.ZkCoreNodeProps;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.SuppressForbidden;
+import org.apache.solr.update.SolrCmdDistributor.SolrError;
+import org.apache.solr.update.SolrCmdDistributor.StdNode;
+import org.apache.solr.util.LogListener;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * SOLR-5939: when the streaming client merges several requests into one 
stream and that stream
+ * fails, the error must be recorded against every request that was in the 
stream. Stamping it with
+ * the first request ever sent to the node makes the distributor retry, 
exempt, and account the
+ * wrong request.
+ *
+ * <p>Both tests send requests to a node where nothing listens, so every 
stream fails with a
+ * connection error, and then inspect the errors the distributor collected.
+ */
+public class StreamingSolrClientsErrorAttributionTest extends SolrTestCase {
+
+  private UpdateShardHandler updateShardHandler;
+
+  @BeforeClass
+  public static void beforeClass() {
+    // keep the client's merge window short so a drained stream closes quickly
+    System.setProperty("solr.cloud.client.pollQueueTime", "500");
+  }
+
+  @AfterClass
+  public static void afterClass() {
+    System.clearProperty("solr.cloud.client.pollQueueTime");
+  }
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    updateShardHandler = new 
UpdateShardHandler(UpdateShardHandlerConfig.DEFAULT);
+  }
+
+  @Override
+  @After
+  public void tearDown() throws Exception {
+    if (updateShardHandler != null) {
+      updateShardHandler.close();
+    }
+    super.tearDown();
+  }
+
+  private static StdNode deadNode(int maxRetries) throws IOException {
+    int port;
+    try (ServerSocket socket = new ServerSocket(0, 50, 
InetAddress.getLoopbackAddress())) {
+      port = socket.getLocalPort();
+    }
+    Map<String, Object> props = new HashMap<>();
+    props.put("base_url", "http://127.0.0.1:"; + port + "/solr");
+    props.put("core", "collection1");
+    props.put("node_name", "127.0.0.1:" + port + "_solr");
+    props.put("type", "NRT");
+    props.put("state", "active");
+    Replica replica = new Replica("core_node1", props, "collection1", 
"shard1");
+    return new StdNode(new ZkCoreNodeProps(replica), "collection1", "shard1", 
maxRetries);
+  }
+
+  private static AddUpdateCommand addCmd(String id) {
+    AddUpdateCommand cmd = new AddUpdateCommand(null);
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.addField("id", id);
+    cmd.solrDoc = doc;
+    return cmd;
+  }
+
+  @Test
+  public void testMergedStreamErrorIsAttributedToEveryRequestInTheStream() 
throws Exception {
+    StdNode node = deadNode(0);
+    try (SolrCmdDistributor distrib = new 
SolrCmdDistributor(updateShardHandler)) {
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      distrib.distribAdd(addCmd("1"), List.of(node), params);
+      distrib.distribAdd(addCmd("2"), List.of(node), params);
+      distrib.finish();
+
+      List<SolrError> errors = distrib.getErrors();
+      Set<String> errorDocIds = new HashSet<>();
+      for (SolrError error : errors) {
+        assertEquals(1, error.req.uReq.getDocuments().size());
+        
errorDocIds.add(error.req.uReq.getDocuments().get(0).getFieldValue("id").toString());
+      }
+      assertEquals("errors: " + errors, Set.of("1", "2"), errorDocIds);
+      assertEquals("errors: " + errors, 2, errors.size());
+    }
+  }
+
+  @Test
+  @SuppressForbidden(reason = "LogListener exposes log4j events for 
assertions")
+  public void testDeleteByQueryRetryRuleIsJudgedOnItsOwnRequest() throws 
Exception {
+    StdNode node = deadNode(1);
+    try (LogListener streamLog = 
LogListener.error(ErrorReportingConcurrentUpdateSolrClient.class);
+        LogListener retryLog = 
LogListener.error(SolrCmdDistributor.class).substring("retrying");
+        SolrCmdDistributor distrib = new 
SolrCmdDistributor(updateShardHandler)) {
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      DeleteUpdateCommand delete = new DeleteUpdateCommand(null);
+      delete.setQuery("id:1");
+      distrib.distribDelete(delete, List.of(node), params);
+      distrib.distribAdd(addCmd("3"), List.of(node), params);
+      distrib.finish();
+
+      List<SolrError> errors = distrib.getErrors();
+      assertEquals("errors: " + errors, 2, errors.size());
+      SolrError deleteError = null;
+      SolrError addError = null;
+      for (SolrError error : errors) {
+        if (error.req.uReq.getDeleteQuery() != null && 
!error.req.uReq.getDeleteQuery().isEmpty()) {
+          deleteError = error;
+        } else {
+          addError = error;
+        }
+      }
+      assertNotNull("the delete-by-query must carry its own error", 
deleteError);
+      assertEquals(0, deleteError.req.retries);
+      assertNotNull("the add in the same stream must carry its own error", 
addError);
+      assertEquals("3", 
addError.req.uReq.getDocuments().get(0).getFieldValue("id"));
+      assertEquals(
+          "the add is retriable, so it must have been resubmitted once", 1, 
addError.req.retries);
+
+      int streamFailures = 0;
+      int requestFailures = 0;
+      while (!streamLog.getQueue().isEmpty()) {
+        var event = streamLog.getQueue().remove();
+        if (event.getMessage().getFormattedMessage().equals("Update stream 
failed")) {
+          assertNotNull(event.getThrown());
+          streamFailures++;
+        } else {
+          
assertTrue(event.getMessage().getFormattedMessage().startsWith("Error when 
calling"));
+          assertNull(event.getThrown());
+          requestFailures++;
+        }
+      }
+      assertTrue(streamFailures > 0);
+      assertTrue(requestFailures >= 2);
+      assertEquals(1, retryLog.getCount());
+      assertNull(retryLog.getQueue().remove().getThrown());
+    }
+  }
+}
diff --git 
a/solr/solrj-jetty/src/java/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClient.java
 
b/solr/solrj-jetty/src/java/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClient.java
index 458f57004b7..735b36e8d4a 100644
--- 
a/solr/solrj-jetty/src/java/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClient.java
+++ 
b/solr/solrj-jetty/src/java/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClient.java
@@ -89,6 +89,7 @@ public class ConcurrentUpdateJettySolrClient extends 
ConcurrentUpdateBaseSolrCli
           queue.add(upd);
           break;
         }
+        recordStreamedUpdate(upd);
         send(out, upd);
         out.flush();
 
diff --git 
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateBaseSolrClient.java
 
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateBaseSolrClient.java
index e85545c1cb3..c0a7339474d 100644
--- 
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateBaseSolrClient.java
+++ 
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateBaseSolrClient.java
@@ -253,6 +253,39 @@ public abstract class ConcurrentUpdateBaseSolrClient 
extends SolrClient {
     return ids;
   }
 
+  /**
+   * The updates written into the stream the calling runner thread is 
currently sending. Stream
+   * implementations report them via {@link #recordStreamedUpdate(Update)} so 
that a failure of the
+   * stream can be attributed to the requests it contained.
+   */
+  private final ThreadLocal<List<Update>> updatesInCurrentStream = new 
ThreadLocal<>();
+
+  /**
+   * Records that {@code update} was written into the stream currently being 
sent on this thread.
+   * Implementations of {@link #doSendUpdateStream(Update)} that merge several 
queued updates into
+   * one stream must call this for every update they write; updates that are 
polled but returned to
+   * the queue unsent must not be recorded.
+   */
+  protected final void recordStreamedUpdate(Update update) {
+    List<Update> updates = updatesInCurrentStream.get();
+    if (updates != null) {
+      updates.add(update);
+    }
+  }
+
+  /** The requests written into the stream that {@code firstUpdate} started, 
in write order. */
+  private List<UpdateRequest> requestsInStream(Update firstUpdate) {
+    List<Update> updates = updatesInCurrentStream.get();
+    if (updates == null || updates.isEmpty()) {
+      return firstUpdate == null ? List.of() : List.of(firstUpdate.request());
+    }
+    List<UpdateRequest> requests = new ArrayList<>(updates.size());
+    for (Update update : updates) {
+      requests.add(update.request());
+    }
+    return requests;
+  }
+
   /** Opens a connection and sends everything... */
   class Runner implements Runnable {
 
@@ -303,13 +336,15 @@ public abstract class ConcurrentUpdateBaseSolrClient 
extends SolrClient {
           InputStream rspBody = null;
           List<String> docIds = List.of();
           String collection = null;
+          Update update = null;
           try {
             notifyQueueAndRunnersIfEmptyQueue();
-            Update update = queue.poll(pollQueueTimeMillis, 
TimeUnit.MILLISECONDS);
+            update = queue.poll(pollQueueTimeMillis, TimeUnit.MILLISECONDS);
 
             if (update == null) {
               break;
             }
+            updatesInCurrentStream.set(new ArrayList<>());
 
             SentStream sent = doSendUpdateStream(update);
             StreamingResponse responseListener = sent.response();
@@ -335,23 +370,26 @@ public abstract class ConcurrentUpdateBaseSolrClient 
extends SolrClient {
                 solrExc = new RemoteSolrException(basePath, statusCode, 
remoteError);
               }
 
-              handleError(solrExc, docIds, collection);
+              handleError(solrExc, requestsInStream(update), docIds, 
collection);
             } else {
-              onSuccess(responseListener.getUnderlyingResponse(), rspBody);
+              onSuccess(
+                  responseListener.getUnderlyingResponse(), rspBody, 
requestsInStream(update));
             }
             stallDetection.incrementProcessedCount();
 
           } catch (OutOfMemoryError | InterruptedException e) {
             throw e;
           } catch (RemoteSolrException e) {
-            handleError(e, docIds, collection);
+            handleError(e, requestsInStream(update), docIds, collection);
           } catch (Throwable e) {
             handleError(
                 new SolrServerException(
                     "Error from server at " + basePath + ": " + 
e.getMessage(), e),
+                requestsInStream(update),
                 docIds,
                 collection);
           } finally {
+            updatesInCurrentStream.remove();
             try {
               consumeFully(rspBody);
             } catch (Exception e) {
@@ -619,6 +657,28 @@ public abstract class ConcurrentUpdateBaseSolrClient 
extends SolrClient {
     }
   }
 
+  /**
+   * Called when sending a stream of updates fails. {@code requests} holds the 
update requests that
+   * were written into the failed stream, in the order they were written, so a 
subclass can
+   * attribute the failure to the requests it actually involved. Stream 
implementations report the
+   * merged requests via {@link #recordStreamedUpdate(Update)}; when none were 
reported, {@code
+   * requests} holds only the request the stream was started with.
+   *
+   * <p>The default implementation reports the failure to the registered 
{@link UpdateErrorHandler},
+   * or calls {@link #handleError(Throwable)} if none is registered. Override 
it to react per
+   * request instead.
+   *
+   * @param ex the failure
+   * @param requests the update requests written into the failed stream
+   * @param failedIds ids of the documents in the stream, as computed for an 
{@link
+   *     UpdateErrorHandler}; empty when no error handler is registered
+   * @param collection the collection the stream was sent to, or null
+   */
+  protected void handleError(
+      Throwable ex, List<UpdateRequest> requests, List<String> failedIds, 
String collection) {
+    handleError(ex, failedIds, collection);
+  }
+
   public void handleError(Throwable ex) {
     log.error("error", ex);
   }
@@ -650,6 +710,24 @@ public abstract class ConcurrentUpdateBaseSolrClient 
extends SolrClient {
     // no-op by design, override to add functionality
   }
 
+  /**
+   * Called when a stream of updates completes successfully. {@code requests} 
holds the update
+   * requests that were written into the stream, in the order they were 
written, mirroring {@link
+   * #handleError(Throwable, List, List, String)}; when none were reported, 
{@code requests} holds
+   * only the request the stream was started with.
+   *
+   * <p>The default implementation delegates to {@link #onSuccess(Object, 
InputStream)}.
+   *
+   * @param responseMetadata implementation-specific response object (e.g., 
Jetty Response), may be
+   *     null
+   * @param respBody the body of the response, subclasses must not close this 
stream
+   * @param requests the update requests written into the successful stream
+   */
+  public void onSuccess(
+      Object responseMetadata, InputStream respBody, List<UpdateRequest> 
requests) {
+    onSuccess(responseMetadata, respBody);
+  }
+
   @Override
   public synchronized void close() {
     if (closed) {
diff --git 
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateJdkSolrClient.java
 
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateJdkSolrClient.java
index fc11824775d..d83982e5f16 100644
--- 
a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateJdkSolrClient.java
+++ 
b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateJdkSolrClient.java
@@ -37,6 +37,7 @@ public class ConcurrentUpdateJdkSolrClient extends 
ConcurrentUpdateBaseSolrClien
 
   @Override
   protected SentStream doSendUpdateStream(Update update) {
+    recordStreamedUpdate(update);
     UpdateRequest req = update.request();
     String collection = update.collection();
     CompletableFuture<HttpResponse<InputStream>> resp =

Reply via email to