Search in sources :

Example 6 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult in project vespa by vespa-engine.

the class OperationProcessor method process.

private Result process(EndpointResult endpointResult, int clusterId) {
    synchronized (monitor) {
        if (!docSendInfoByOperationId.containsKey(endpointResult.getOperationId())) {
            log.finer("Received out-of-order or too late result, discarding: " + endpointResult);
            return null;
        }
        DocumentSendInfo documentSendInfo = docSendInfoByOperationId.get(endpointResult.getOperationId());
        if (retriedThis(endpointResult, documentSendInfo, clusterId)) {
            return null;
        }
        if (!documentSendInfo.addIfNotAlreadyThere(endpointResult.getDetail(), clusterId)) {
            // Duplicate message, we have seen this operation before.
            return null;
        }
        // Is this the last operation we are waiting for?
        if (documentSendInfo.detailCount() != numDestinations) {
            return null;
        }
        Result result = documentSendInfo.createResult();
        docSendInfoByOperationId.remove(endpointResult.getOperationId());
        String documentId = documentSendInfo.getDocument().getDocumentId();
        /**
         * If we got a pending operation against this document
         * dont't remove it from inflightDocuments and send blocked document operation
         */
        List<Document> blockedDocuments = blockedDocumentsByDocumentId.get(documentId);
        if (blockedDocuments.isEmpty()) {
            inflightDocumentIds.remove(documentId);
        } else {
            sendToClusters(blockedDocuments.remove(0));
        }
        return result;
    }
}
Also used : Document(com.yahoo.vespa.http.client.core.Document) Result(com.yahoo.vespa.http.client.Result) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult)

Example 7 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult in project vespa by vespa-engine.

the class OperationProcessor method resultReceived.

public void resultReceived(EndpointResult endpointResult, int clusterId) {
    final Result result = process(endpointResult, clusterId);
    if (result != null) {
        incompleteResultsThrottler.resultReady(result.isSuccess());
        resultCallback.onCompletion(result.getDocumentId(), result);
        if (traceToStderr && result.hasLocalTrace()) {
            System.err.println(result.toString());
        }
    }
}
Also used : Result(com.yahoo.vespa.http.client.Result) EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult)

Example 8 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult in project vespa by vespa-engine.

the class IOThreadTest method setupEndpointResultQueueMock.

/**
 * Set up mock so that it can handle both failDocument() and resultReceived().
 * @param expectedDocIdFail on failure, this has to be the doc id, or the mock will fail.
 * @param expectedDocIdOk on ok, this has to be the doc id, or the mock will fail.
 * @param isTransient checked on failure, if different, the mock will fail.
 * @param expectedException checked on failure, if exception toString is different, the mock will fail.
 */
void setupEndpointResultQueueMock(String expectedDocIdFail, String expectedDocIdOk, boolean isTransient, String expectedException) {
    doAnswer(invocation -> {
        EndpointResult endpointResult = (EndpointResult) invocation.getArguments()[0];
        assertThat(endpointResult.getOperationId(), is(expectedDocIdFail));
        assertThat(endpointResult.getDetail().getException().toString(), containsString(expectedException));
        assertThat(endpointResult.getDetail().getResultType(), is(isTransient ? Result.ResultType.TRANSITIVE_ERROR : Result.ResultType.FATAL_ERROR));
        latch.countDown();
        return null;
    }).when(endpointResultQueue).failOperation(anyObject(), eq(0));
    doAnswer(invocation -> {
        EndpointResult endpointResult = (EndpointResult) invocation.getArguments()[0];
        assertThat(endpointResult.getOperationId(), is(expectedDocIdOk));
        assertThat(endpointResult.getDetail().getResultType(), is(Result.ResultType.OPERATION_EXECUTED));
        latch.countDown();
        return null;
    }).when(endpointResultQueue).resultReceived(anyObject(), eq(0));
}
Also used : EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult)

Example 9 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult in project vespa by vespa-engine.

the class IOThread method processResponse.

private ProcessResponse processResponse(InputStream serverResponse) throws IOException {
    final Collection<EndpointResult> endpointResults = EndPointResultFactory.createResult(endpoint, serverResponse);
    statusReceivedCounter.addAndGet(endpointResults.size());
    int transientErrors = 0;
    for (EndpointResult endpointResult : endpointResults) {
        if (endpointResult.getDetail().getResultType() == Result.ResultType.TRANSITIVE_ERROR) {
            transientErrors++;
        }
        resultQueue.resultReceived(endpointResult, clusterId);
    }
    return new ProcessResponse(transientErrors, endpointResults.size());
}
Also used : EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) Endpoint(com.yahoo.vespa.http.client.config.Endpoint)

Example 10 with EndpointResult

use of com.yahoo.vespa.http.client.core.EndpointResult in project vespa by vespa-engine.

the class IOThread method drainDocumentQueueWhenFailingPermanently.

private void drainDocumentQueueWhenFailingPermanently(Exception exception) {
    // first, clear sentOperations:
    resultQueue.failPending(exception);
    for (Document document : documentQueue.removeAllDocuments()) {
        EndpointResult endpointResult = EndPointResultFactory.createError(endpoint, document.getOperationId(), exception);
        resultQueue.failOperation(endpointResult, clusterId);
    }
}
Also used : EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) Document(com.yahoo.vespa.http.client.core.Document)

Aggregations

EndpointResult (com.yahoo.vespa.http.client.core.EndpointResult)18 Test (org.junit.Test)9 SessionParams (com.yahoo.vespa.http.client.config.SessionParams)8 Cluster (com.yahoo.vespa.http.client.config.Cluster)7 Result (com.yahoo.vespa.http.client.Result)4 Endpoint (com.yahoo.vespa.http.client.config.Endpoint)4 Document (com.yahoo.vespa.http.client.core.Document)4 IOException (java.io.IOException)2 OperationStatus (com.yahoo.vespa.http.client.core.OperationStatus)1 ServerResponseException (com.yahoo.vespa.http.client.core.ServerResponseException)1 OperationProcessor (com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor)1 ArrayDeque (java.util.ArrayDeque)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1