Search in sources :

Example 1 with IndividualReplicaGetFailedEvent

use of com.couchbase.client.core.cnc.events.request.IndividualReplicaGetFailedEvent in project couchbase-jvm-clients by couchbase.

the class ReplicaHelper method getAllReplicasReactive.

/**
 * @param clientContext (nullable)
 * @param parentSpan (nullable)
 */
public static Flux<GetReplicaResponse> getAllReplicasReactive(final Core core, final CollectionIdentifier collectionIdentifier, final String documentId, final Duration timeout, final RetryStrategy retryStrategy, Map<String, Object> clientContext, RequestSpan parentSpan) {
    notNullOrEmpty(documentId, "Id", () -> ReducedKeyValueErrorContext.create(documentId, collectionIdentifier));
    CoreEnvironment env = core.context().environment();
    RequestSpan getAllSpan = env.requestTracer().requestSpan(TracingIdentifiers.SPAN_GET_ALL_REPLICAS, parentSpan);
    getAllSpan.attribute(TracingIdentifiers.ATTR_SYSTEM, TracingIdentifiers.ATTR_SYSTEM_COUCHBASE);
    return Reactor.toMono(() -> getAllReplicasRequests(core, collectionIdentifier, documentId, clientContext, retryStrategy, timeout, getAllSpan)).flux().flatMap(Flux::fromStream).flatMap(request -> Reactor.wrap(request, get(core, request), true).onErrorResume(t -> {
        env.eventBus().publish(new IndividualReplicaGetFailedEvent(request.context()));
        // Swallow any errors from individual replicas
        return Mono.empty();
    }).map(response -> new GetReplicaResponse(response, request instanceof ReplicaGetRequest))).doFinally(signalType -> getAllSpan.end());
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) CouchbaseBucketConfig(com.couchbase.client.core.config.CouchbaseBucketConfig) ArrayList(java.util.ArrayList) DefaultErrorUtil.keyValueStatusToException(com.couchbase.client.core.error.DefaultErrorUtil.keyValueStatusToException) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DocumentUnretrievableException(com.couchbase.client.core.error.DocumentUnretrievableException) CoreContext(com.couchbase.client.core.CoreContext) Duration(java.time.Duration) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Stability(com.couchbase.client.core.annotation.Stability) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) GetResponse(com.couchbase.client.core.msg.kv.GetResponse) IndividualReplicaGetFailedEvent(com.couchbase.client.core.cnc.events.request.IndividualReplicaGetFailedEvent) BucketConfig(com.couchbase.client.core.config.BucketConfig) Reactor(com.couchbase.client.core.Reactor) CommonExceptions(com.couchbase.client.core.error.CommonExceptions) Mono(reactor.core.publisher.Mono) CompletionException(java.util.concurrent.CompletionException) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) Collectors(java.util.stream.Collectors) Validators.notNullOrEmpty(com.couchbase.client.core.util.Validators.notNullOrEmpty) Flux(reactor.core.publisher.Flux) List(java.util.List) Stream(java.util.stream.Stream) GetRequest(com.couchbase.client.core.msg.kv.GetRequest) ReplicaGetRequest(com.couchbase.client.core.msg.kv.ReplicaGetRequest) ErrorContext(com.couchbase.client.core.error.context.ErrorContext) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) Core(com.couchbase.client.core.Core) ReducedKeyValueErrorContext(com.couchbase.client.core.error.context.ReducedKeyValueErrorContext) Collections(java.util.Collections) AggregateErrorContext(com.couchbase.client.core.error.context.AggregateErrorContext) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) IndividualReplicaGetFailedEvent(com.couchbase.client.core.cnc.events.request.IndividualReplicaGetFailedEvent) Flux(reactor.core.publisher.Flux) ReplicaGetRequest(com.couchbase.client.core.msg.kv.ReplicaGetRequest) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

Core (com.couchbase.client.core.Core)1 CoreContext (com.couchbase.client.core.CoreContext)1 Reactor (com.couchbase.client.core.Reactor)1 Stability (com.couchbase.client.core.annotation.Stability)1 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 IndividualReplicaGetFailedEvent (com.couchbase.client.core.cnc.events.request.IndividualReplicaGetFailedEvent)1 BucketConfig (com.couchbase.client.core.config.BucketConfig)1 CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)1 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)1 CommonExceptions (com.couchbase.client.core.error.CommonExceptions)1 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)1 DefaultErrorUtil.keyValueStatusToException (com.couchbase.client.core.error.DefaultErrorUtil.keyValueStatusToException)1 DocumentUnretrievableException (com.couchbase.client.core.error.DocumentUnretrievableException)1 AggregateErrorContext (com.couchbase.client.core.error.context.AggregateErrorContext)1 ErrorContext (com.couchbase.client.core.error.context.ErrorContext)1 ReducedKeyValueErrorContext (com.couchbase.client.core.error.context.ReducedKeyValueErrorContext)1 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)1 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)1 GetResponse (com.couchbase.client.core.msg.kv.GetResponse)1