MCPcopy
hub / github.com/grpc/grpc-go / newAttemptLocked

Method newAttemptLocked

stream.go:439–498  ·  view source on GitHub ↗

newAttemptLocked creates a new csAttempt without a transport or stream.

(isTransparent bool)

Source from the content-addressed store, hash-verified

437
438// newAttemptLocked creates a new csAttempt without a transport or stream.
439func (cs *clientStream) newAttemptLocked(isTransparent bool) (*csAttempt, error) {
440 if err := cs.ctx.Err(); err != nil {
441 return nil, toRPCErr(err)
442 }
443 if err := cs.cc.ctx.Err(); err != nil {
444 return nil, ErrClientConnClosing
445 }
446
447 ctx := newContextWithRPCInfo(cs.ctx, cs.callInfo.failFast, cs.callInfo.codec, cs.compressorV0, cs.compressorV1)
448 method := cs.callHdr.Method
449 var beginTime time.Time
450 sh := cs.cc.statsHandler
451 if sh != nil {
452 beginTime = time.Now()
453 ctx = sh.TagRPC(ctx, &stats.RPCTagInfo{
454 FullMethodName: method, FailFast: cs.callInfo.failFast,
455 NameResolutionDelay: cs.nameResolutionDelay,
456 })
457 sh.HandleRPC(ctx, &stats.Begin{
458 Client: true,
459 BeginTime: beginTime,
460 FailFast: cs.callInfo.failFast,
461 IsClientStream: cs.desc.ClientStreams,
462 IsServerStream: cs.desc.ServerStreams,
463 IsTransparentRetryAttempt: isTransparent,
464 })
465 }
466
467 var trInfo *traceInfo
468 if EnableTracing {
469 trInfo = &traceInfo{
470 tr: newTrace("grpc.Sent."+methodFamily(method), method),
471 firstLine: firstLine{
472 client: true,
473 },
474 }
475 if deadline, ok := ctx.Deadline(); ok {
476 trInfo.firstLine.deadline = time.Until(deadline)
477 }
478 trInfo.tr.LazyLog(&trInfo.firstLine, false)
479 ctx = newTraceContext(ctx, trInfo.tr)
480 }
481
482 if cs.cc.parsedTarget.URL.Scheme == internal.GRPCResolverSchemeExtraMetadata {
483 // Add extra metadata (metadata that will be added by transport) to context
484 // so the balancer can see them.
485 ctx = grpcutil.WithExtraMetadata(ctx, metadata.Pairs(
486 "content-type", grpcutil.ContentType(cs.callHdr.ContentSubtype),
487 ))
488 }
489
490 return &csAttempt{
491 ctx: ctx,
492 beginTime: beginTime,
493 cs: cs,
494 decompressorV0: cs.cc.dopts.dc,
495 statsHandler: sh,
496 trInfo: trInfo,

Callers 2

retryLockedMethod · 0.95
withRetryMethod · 0.95

Calls 13

WithExtraMetadataFunction · 0.92
PairsFunction · 0.92
ContentTypeFunction · 0.92
toRPCErrFunction · 0.85
newContextWithRPCInfoFunction · 0.85
methodFamilyFunction · 0.85
ErrMethod · 0.80
NowMethod · 0.80
newTraceFunction · 0.70
newTraceContextFunction · 0.70
TagRPCMethod · 0.65
HandleRPCMethod · 0.65

Tested by

no test coverage detected