Search in sources :

Example 1 with ObserveViaSeqnoRequest

use of com.couchbase.client.core.msg.kv.ObserveViaSeqnoRequest in project couchbase-jvm-clients by couchbase.

the class Observe method viaMutationToken.

private static Flux<ObserveItem> viaMutationToken(final int bucketReplicas, final ObserveContext ctx, final RequestSpan parent) {
    if (!ctx.mutationToken().isPresent()) {
        throw new IllegalStateException("MutationToken is not present, this is a bug!");
    }
    Duration timeout = ctx.timeout();
    RetryStrategy retryStrategy = ctx.retryStrategy();
    MutationToken mutationToken = ctx.mutationToken().get();
    String id = ctx.key();
    List<ObserveViaSeqnoRequest> requests = new ArrayList<>();
    if (ctx.persistTo() != ObservePersistTo.NONE) {
        final RequestSpan span = ctx.environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_OBSERVE, parent);
        requests.add(new ObserveViaSeqnoRequest(timeout, ctx, ctx.collectionIdentifier(), retryStrategy, 0, true, mutationToken.partitionUUID(), id, span));
    }
    if (ctx.persistTo().touchesReplica() || ctx.replicateTo().touchesReplica()) {
        for (short i = 1; i <= bucketReplicas; i++) {
            final RequestSpan span = ctx.environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_OBSERVE, parent);
            requests.add(new ObserveViaSeqnoRequest(timeout, ctx, ctx.collectionIdentifier(), retryStrategy, i, false, mutationToken.partitionUUID(), id, span));
        }
    }
    return Flux.fromIterable(requests).flatMap(request -> {
        ctx.core().send(request);
        return Reactor.wrap(request, request.response(), true).onErrorResume(t -> Mono.empty()).doFinally(signalType -> request.context().logicallyComplete());
    }).map(response -> ObserveItem.fromMutationToken(mutationToken, response));
}
Also used : Reactor(com.couchbase.client.core.Reactor) Repeat(com.couchbase.client.core.retry.reactor.Repeat) ReplicaNotConfiguredException(com.couchbase.client.core.error.ReplicaNotConfiguredException) FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) Mono(reactor.core.publisher.Mono) CouchbaseBucketConfig(com.couchbase.client.core.config.CouchbaseBucketConfig) ArrayList(java.util.ArrayList) MutationToken(com.couchbase.client.core.msg.kv.MutationToken) Flux(reactor.core.publisher.Flux) List(java.util.List) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) ObserveViaSeqnoRequest(com.couchbase.client.core.msg.kv.ObserveViaSeqnoRequest) Duration(java.time.Duration) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) BucketConfig(com.couchbase.client.core.config.BucketConfig) ObserveViaSeqnoRequest(com.couchbase.client.core.msg.kv.ObserveViaSeqnoRequest) MutationToken(com.couchbase.client.core.msg.kv.MutationToken) ArrayList(java.util.ArrayList) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

Reactor (com.couchbase.client.core.Reactor)1 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 BucketConfig (com.couchbase.client.core.config.BucketConfig)1 CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)1 FeatureNotAvailableException (com.couchbase.client.core.error.FeatureNotAvailableException)1 ReplicaNotConfiguredException (com.couchbase.client.core.error.ReplicaNotConfiguredException)1 MutationToken (com.couchbase.client.core.msg.kv.MutationToken)1 ObserveViaSeqnoRequest (com.couchbase.client.core.msg.kv.ObserveViaSeqnoRequest)1 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 Repeat (com.couchbase.client.core.retry.reactor.Repeat)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Flux (reactor.core.publisher.Flux)1 Mono (reactor.core.publisher.Mono)1