private async Task <IGetReplicaResult> GetReplica(string id, short index, IInternalSpan span, CancellationToken cancellationToken, ITranscoderOverrideOptions options) { using var childSpan = _tracer.InternalSpan(OperationNames.ReplicaRead, span); using var getOp = new ReplicaRead <object> { Key = id, Cid = Cid, CName = Name, ReplicaIdx = index, Span = childSpan }; _operationConfigurator.Configure(getOp, options); await _bucket.RetryAsync(getOp, cancellationToken).ConfigureAwait(false); return(new GetReplicaResult(getOp.ExtractBody(), getOp.Transcoder, _getLogger) { Id = getOp.Key, Cas = getOp.Cas, OpCode = getOp.OpCode, Flags = getOp.Flags, Header = getOp.Header, IsActive = false }); }
private async Task <IGetReplicaResult> GetPrimary(string id, IInternalSpan span, CancellationToken cancellationToken, ITranscoderOverrideOptions options) { using var childSpan = _tracer.InternalSpan(OperationNames.Get, span); using var getOp = new Get <object> { Key = id, Cid = Cid, CName = Name, Span = childSpan }; _operationConfigurator.Configure(getOp, options); using var cts = CreateRetryTimeoutCancellationTokenSource((ITimeoutOptions)options, getOp); await _bucket.RetryAsync(getOp, cts.Token).ConfigureAwait(false); return(new GetReplicaResult(getOp.ExtractBody(), getOp.Transcoder, _getLogger) { Id = getOp.Key, Cas = getOp.Cas, OpCode = getOp.OpCode, Flags = getOp.Flags, Header = getOp.Header, IsActive = true }); }
internal static IInternalSpan WithDefaultAttributes(this IInternalSpan span) { span.WithTag(CouchbaseTags.OpenTracingTags.Component, ClientIdentifier.GetClientDescription()); span.WithTag(CouchbaseTags.OpenTracingTags.DbType, CouchbaseTags.DbTypeCouchbase); span.WithTag(CouchbaseTags.OpenTracingTags.SpanKind, CouchbaseTags.OpenTracingTags.SpanKindClient); return(span); }
protected async Task <string> SaslList(IConnection connection, IInternalSpan span, CancellationToken token) { using var op = new SaslList() { Transcoder = Transcoder, Timeout = Timeout, Span = span, }; return(await SendAsync(op, connection, token).ConfigureAwait(false)); }
protected async Task <string> SaslList(IConnection connection, IInternalSpan span, CancellationToken token) { using var op = new SaslList() { Timeout = Timeout, Span = span, }; OperationConfigurator.Configure(op, SaslOptions.Instance); return(await SendAsync(op, connection, token).ConfigureAwait(false)); }
private async Task <IGetReplicaResult> GetPrimary(string id, IInternalSpan span, CancellationToken cancellationToken, ITypeTranscoder transcoder) { using var childSpan = _tracer.InternalSpan(OperationNames.Get, span); using var getOp = new Get <object> { Key = id, Cid = Cid, CName = Name, Transcoder = transcoder, Span = childSpan }; await _bucket.RetryAsync(getOp, cancellationToken).ConfigureAwait(false); return(new GetReplicaResult(getOp.ExtractData(), transcoder, _getLogger) { Id = getOp.Key, Cas = getOp.Cas, OpCode = getOp.OpCode, Flags = getOp.Flags, Header = getOp.Header, IsActive = true }); }
internal static IInternalSpan OperationId(this IInternalSpan span, OperationBase op) => !span.IsNullSpan ? span.OperationId($"0x{op.Opaque:X}") : span;
internal static IInternalSpan OperationId(this IInternalSpan span, string operationId) => span.WithTag(CouchbaseTags.OperationId, operationId);
protected async Task <string> SaslStep(IConnection connection, string message, IInternalSpan span, CancellationToken token) { using var childSpan = Tracer.InternalSpan(OperationNames.SaslStep, span); using var op = new SaslStep() { Key = "SCRAM-SHA1",//MechanismType.GetDescription(), Content = message, Transcoder = Transcoder, Timeout = Timeout, Span = childSpan, }; return(await SendAsync(op, connection, token).ConfigureAwait(false)); }
internal static IInternalSpan WithLocalAddress(this IInternalSpan span) => span.WithTag(CouchbaseTags.LocalAddress, Dns.GetHostName());
internal static IInternalSpan OperationId(this IInternalSpan span, OperationBase op) => span.OperationId($"0x{op.Opaque:X}");
protected async Task <string> SaslStart(IConnection connection, string message, IInternalSpan span, CancellationToken token) { using var childSpan = Tracer.InternalSpan(OperationNames.SaslStart, span); using var authOp = new SaslStart { Key = MechanismType.GetDescription(), Content = message, Timeout = Timeout, Span = childSpan }; OperationConfigurator.Configure(authOp, SaslOptions.Instance); return(await SendAsync(authOp, connection, token).ConfigureAwait(false)); }
private async Task <MultiLookup <byte[]> > ExecuteLookupIn(string id, IEnumerable <LookupInSpec> specs, LookupInOptions options, IInternalSpan span) { //sanity check for deferred bootstrapping errors _bucket.ThrowIfBootStrapFailed(); // convert new style specs into old style builder var builder = new LookupInBuilder <byte[]>(null, null, id, specs); //add the virtual xttar attribute to get the doc expiration time if (options.ExpiryValue) { builder.Get(VirtualXttrs.DocExpiryTime, SubdocPathFlags.Xattr); } var lookup = new MultiLookup <byte[]> { Key = id, Builder = builder, Cid = Cid, CName = Name, DocFlags = options.AccessDeletedValue ? SubdocDocFlags.AccessDeleted : SubdocDocFlags.None, Span = span }; _operationConfigurator.Configure(lookup, options); await RetryUntilTimeoutOrSuccessAsync(options.TokenValue, options.TimeoutValue, lookup).ConfigureAwait(false); return(lookup); }
private async Task <IQueryResult <T> > ExecuteQuery <T>(QueryOptions options, ITypeSerializer serializer, IInternalSpan span) { // try get Query node var queryUri = _serviceUriProvider.GetRandomQueryUri(); span.WithRemoteAddress(queryUri); using var encodingSpan = span.StartPayloadEncoding(); var body = options.GetFormValuesAsJson(); encodingSpan.Dispose(); _logger.LogDebug("Sending query {contextId} to node {endpoint}.", options.CurrentContextId, queryUri); QueryResultBase <T> queryResult; using var content = new StringContent(body, System.Text.Encoding.UTF8, MediaType.Json); try { using var dispatchSpan = span.StartDispatch(); var response = await HttpClient.PostAsync(queryUri, content, options.Token).ConfigureAwait(false); dispatchSpan.Dispose(); var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); if (serializer is IStreamingTypeDeserializer streamingDeserializer) { queryResult = new StreamingQueryResult <T>(stream, streamingDeserializer); } else { queryResult = new BlockQueryResult <T>(stream, serializer); } queryResult.HttpStatusCode = response.StatusCode; queryResult.Success = response.StatusCode == HttpStatusCode.OK; //read the header and stop when we reach the queried rows await queryResult.InitializeAsync(options.Token).ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.OK || queryResult.MetaData?.Status != QueryStatus.Success) { var currentContextId = options.CurrentContextId ?? Guid.Empty.ToString(); _logger.LogDebug("Request {currentContextId} has failed because {status}.", currentContextId, queryResult.MetaData?.Status); if (queryResult.ShouldRetry(EnhancedPreparedStatementsEnabled)) { if (queryResult.Errors.Any(x => x.Code == 4040 && EnhancedPreparedStatementsEnabled)) { //clear the cache of stale query plan var statement = options.StatementValue ?? string.Empty; if (_queryCache.TryRemove(statement, out var queryPlan)) { _logger.LogDebug("Query plan is stale for {currentContextId}. Purging plan {queryPlanName}.", currentContextId, queryPlan.Name); } ; } _logger.LogDebug("Request {currentContextId} is being retried.", currentContextId); return(queryResult); } var context = new QueryErrorContext { ClientContextId = options.CurrentContextId, Parameters = options.GetAllParametersAsJson(), Statement = options.ToString(), Message = GetErrorMessage(queryResult, currentContextId, response.StatusCode), Errors = queryResult.Errors, HttpStatus = response.StatusCode, QueryStatus = queryResult.MetaData?.Status ?? QueryStatus.Fatal }; if (queryResult.MetaData?.Status == QueryStatus.Timeout) { if (options.IsReadOnly) { throw new AmbiguousTimeoutException { Context = context }; } throw new UnambiguousTimeoutException { Context = context }; } queryResult.ThrowExceptionOnError(context); } } catch (OperationCanceledException e) { var context = new QueryErrorContext { ClientContextId = options.CurrentContextId, Parameters = options.GetAllParametersAsJson(), Statement = options.ToString(), HttpStatus = HttpStatusCode.RequestTimeout, QueryStatus = QueryStatus.Fatal }; _logger.LogDebug(LoggingEvents.QueryEvent, e, "Request timeout."); if (options.IsReadOnly) { throw new UnambiguousTimeoutException("The query was timed out via the Token.", e) { Context = context }; } throw new AmbiguousTimeoutException("The query was timed out via the Token.", e) { Context = context }; } catch (HttpRequestException e) { _logger.LogDebug(LoggingEvents.QueryEvent, e, "Request canceled"); var context = new QueryErrorContext { ClientContextId = options.CurrentContextId, Parameters = options.GetAllParametersAsJson(), Statement = options.ToString(), HttpStatus = HttpStatusCode.RequestTimeout, QueryStatus = QueryStatus.Fatal }; throw new RequestCanceledException("The query was canceled.", e) { Context = context }; } _logger.LogDebug($"Request {options.CurrentContextId} has succeeded."); return(queryResult); }
internal static IInternalSpan WithRemoteAddress(this IInternalSpan span, Uri remoteUri) => !span.IsNullSpan ? span.WithTag(CouchbaseTags.RemoteAddress, $"{remoteUri.Host}:{remoteUri.Port}") : span;
internal static IInternalSpan WithLocalAddress(this IInternalSpan span) => !span.IsNullSpan ? span.WithTag(CouchbaseTags.LocalAddress, _dnsHostName ??= Dns.GetHostName()) : span;
public void AddTags(IInternalSpan span) { span.WithTag(CouchbaseTags.RemoteAddress, _endPointString); span.WithTag(CouchbaseTags.LocalAddress, _localEndPointString); span.WithTag(CouchbaseTags.LocalId, _connectionIdString); }