Search in sources :

Example 1 with MemcachedBucketConfig

use of com.couchbase.client.core.config.MemcachedBucketConfig in project couchbase-jvm-clients by couchbase.

the class KeyValueLocator method dispatch.

@Override
public void dispatch(final Request<? extends Response> request, final List<Node> nodes, final ClusterConfig config, final CoreContext ctx) {
    if (request.target() != null) {
        dispatchTargeted(request, nodes, ctx);
    } else {
        KeyValueRequest r = (KeyValueRequest) request;
        String bucket = r.bucket();
        BucketConfig bucketConfig = config.bucketConfig(bucket);
        if (bucketConfig == null) {
            // Since a bucket is opened lazily, it might not be available yet (or for some
            // other reason the config is gone) - send it into retry!
            RetryOrchestrator.maybeRetry(ctx, request, ctx.core().configurationProvider().bucketConfigLoadInProgress() ? RetryReason.BUCKET_OPEN_IN_PROGRESS : RetryReason.BUCKET_NOT_AVAILABLE);
            return;
        }
        if (bucketConfig instanceof CouchbaseBucketConfig) {
            couchbaseBucket(r, nodes, (CouchbaseBucketConfig) bucketConfig, ctx);
        } else if (bucketConfig instanceof MemcachedBucketConfig) {
            memcacheBucket(r, nodes, (MemcachedBucketConfig) bucketConfig, ctx);
        } else {
            throw new IllegalStateException("Unsupported Bucket Type: " + bucketConfig + " for request " + request);
        }
    }
}
Also used : KeyValueRequest(com.couchbase.client.core.msg.kv.KeyValueRequest) CouchbaseBucketConfig(com.couchbase.client.core.config.CouchbaseBucketConfig) MemcachedBucketConfig(com.couchbase.client.core.config.MemcachedBucketConfig) CouchbaseBucketConfig(com.couchbase.client.core.config.CouchbaseBucketConfig) MemcachedBucketConfig(com.couchbase.client.core.config.MemcachedBucketConfig) BucketConfig(com.couchbase.client.core.config.BucketConfig)

Example 2 with MemcachedBucketConfig

use of com.couchbase.client.core.config.MemcachedBucketConfig in project couchbase-jvm-clients by couchbase.

the class KeyValueMessageHandler method write.

@Override
@SuppressWarnings({ "unchecked" })
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
    if (msg instanceof KeyValueRequest) {
        KeyValueRequest<Response> request = (KeyValueRequest<Response>) msg;
        int opaque = request.opaque();
        writtenRequests.put(opaque, request);
        try {
            ctx.write(request.encode(ctx.alloc(), opaque, channelContext), promise);
            writtenRequestDispatchTimings.put(opaque, (Long) System.nanoTime());
            if (request.requestSpan() != null) {
                RequestTracer tracer = endpointContext.environment().requestTracer();
                RequestSpan dispatchSpan = tracer.requestSpan(TracingIdentifiers.SPAN_DISPATCH, request.requestSpan());
                if (!isInternalTracer) {
                    setCommonDispatchSpanAttributes(dispatchSpan, ctx.channel().attr(ChannelAttributes.CHANNEL_ID_KEY).get(), ioContext.localHostname(), ioContext.localPort(), endpoint.remoteHostname(), endpoint.remotePort(), null);
                    setNumericOperationId(dispatchSpan, request.opaque());
                    setCommonKVSpanAttributes(dispatchSpan, request);
                }
                writtenRequestDispatchSpans.put(opaque, dispatchSpan);
            }
        } catch (Throwable err) {
            writtenRequests.remove(opaque);
            if (err instanceof CollectionNotFoundException) {
                if (channelContext.collectionsEnabled()) {
                    ConfigurationProvider cp = ioContext.core().configurationProvider();
                    if (cp.collectionRefreshInProgress(request.collectionIdentifier())) {
                        RetryOrchestrator.maybeRetry(ioContext, request, RetryReason.COLLECTION_MAP_REFRESH_IN_PROGRESS);
                    } else if (cp.config().bucketConfig(request.bucket()) instanceof MemcachedBucketConfig) {
                        request.fail(FeatureNotAvailableException.collectionsForMemcached());
                    } else {
                        handleOutdatedCollection(request, RetryReason.COLLECTION_NOT_FOUND);
                    }
                    return;
                }
            }
            request.fail(err);
        }
    } else {
        eventBus.publish(new InvalidRequestDetectedEvent(ioContext, ServiceType.KV, msg));
        ctx.channel().close().addListener(f -> eventBus.publish(new ChannelClosedProactivelyEvent(ioContext, ChannelClosedProactivelyEvent.Reason.INVALID_REQUEST_DETECTED)));
    }
}
Also used : Response(com.couchbase.client.core.msg.Response) KeyValueRequest(com.couchbase.client.core.msg.kv.KeyValueRequest) ChannelClosedProactivelyEvent(com.couchbase.client.core.cnc.events.io.ChannelClosedProactivelyEvent) ConfigurationProvider(com.couchbase.client.core.config.ConfigurationProvider) MemcachedBucketConfig(com.couchbase.client.core.config.MemcachedBucketConfig) RequestTracer(com.couchbase.client.core.cnc.RequestTracer) BaseEndpoint(com.couchbase.client.core.endpoint.BaseEndpoint) CollectionNotFoundException(com.couchbase.client.core.error.CollectionNotFoundException) InvalidRequestDetectedEvent(com.couchbase.client.core.cnc.events.io.InvalidRequestDetectedEvent) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

MemcachedBucketConfig (com.couchbase.client.core.config.MemcachedBucketConfig)2 KeyValueRequest (com.couchbase.client.core.msg.kv.KeyValueRequest)2 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 RequestTracer (com.couchbase.client.core.cnc.RequestTracer)1 ChannelClosedProactivelyEvent (com.couchbase.client.core.cnc.events.io.ChannelClosedProactivelyEvent)1 InvalidRequestDetectedEvent (com.couchbase.client.core.cnc.events.io.InvalidRequestDetectedEvent)1 BucketConfig (com.couchbase.client.core.config.BucketConfig)1 ConfigurationProvider (com.couchbase.client.core.config.ConfigurationProvider)1 CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)1 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)1 CollectionNotFoundException (com.couchbase.client.core.error.CollectionNotFoundException)1 Response (com.couchbase.client.core.msg.Response)1