diff options
author | Tor Brede Vekterli <vekterli@vespa.ai> | 2024-05-08 16:36:16 +0200 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@vespa.ai> | 2024-05-13 09:43:03 +0000 |
commit | 20f219ca1b2fd61795c9e1f73109ac1941dae7cd (patch) | |
tree | 3002cc0f71a7aee03ea849895606770ffb3b13ce /vespaclient-container-plugin/src/main/java | |
parent | dc1d2982e21098e0dee252f229762960259382ac (diff) |
Explicitly track number of locally entries received through visiting
Using the underlying session's `VisitorStatistics` may not be 1-1
with the actual number of entries the data handler has been invoked
with. This causes issues if anyone tries to cross-check the document
count emitted as part of the results vs. the number of entries
actually present in the result array.
The session updates its statistics based on the what is returned from
the backend as part of _successful_ `CreateVisitorReply` messages.
If a CreateVisitor returns with a transient error, the statistics will
not be updated, but it's unspecified how many (if any) document entries
that particular visitor may already have pushed to the client directly
from the content nodes.
Note that the locally tracked number is only reported if the session
itself is receiving the document data; if a remote data handler is
in use we have to report what the `VisitorStatistics` give us.
Diffstat (limited to 'vespaclient-container-plugin/src/main/java')
-rw-r--r-- | vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java index b483d6977d6..6e07661235e 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java @@ -1397,6 +1397,7 @@ public class DocumentV1ApiHandler extends AbstractRequestHandler { Phaser phaser = new Phaser(2); // Synchronize this thread (dispatch) with the visitor callback thread. AtomicReference<String> error = new AtomicReference<>(); // Set if error occurs during processing of visited documents. callback.onStart(response, fullyApplied); + final AtomicLong locallyReceivedDocCount = new AtomicLong(0); VisitorControlHandler controller = new VisitorControlHandler() { final ScheduledFuture<?> abort = streaming ? visitDispatcher.schedule(this::abort, visitTimeout(request), MILLISECONDS) : null; final AtomicReference<VisitorSession> session = new AtomicReference<>(); @@ -1410,7 +1411,10 @@ public class DocumentV1ApiHandler extends AbstractRequestHandler { try (response) { callback.onEnd(response); - response.writeDocumentCount(getVisitorStatistics() == null ? 0 : getVisitorStatistics().getDocumentsVisited()); + // Locally tracked document count is only correct if we have a local data handler. + // Otherwise, we have to report the statistics received transitively from the content nodes. + long statsDocCount = (getVisitorStatistics() != null ? getVisitorStatistics().getDocumentsVisited() : 0); + response.writeDocumentCount(parameters.getLocalDataHandler() != null ? locallyReceivedDocCount.get() : statsDocCount); if (session.get() != null) response.writeTrace(session.get().getTrace()); @@ -1456,6 +1460,7 @@ public class DocumentV1ApiHandler extends AbstractRequestHandler { if (m instanceof PutDocumentMessage put) document = put.getDocumentPut().getDocument(); else if (parameters.visitRemoves() && m instanceof RemoveDocumentMessage remove) removeId = remove.getDocumentId(); else throw new UnsupportedOperationException("Got unsupported message type: " + m.getClass().getName()); + locallyReceivedDocCount.getAndAdd(1); callback.onDocument(response, document, removeId, |