id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c178400
s := t.pool().Get().(Checksum) s.Reset() return s }
c178401
name: "tchan", template: template.Must(parseTemplate(tchannelTmpl)), }) } for _, f := range templateFiles { t, err := parseTemplateFile(f) if err != nil { return nil, err } templates = append(templates, t) } return templates, nil }
c178402
stringSliceFlag flag.Var(&ss, name, usage) return (*[]string)(&ss) }
c178403
{ return t.template.Funcs(map[string]interface{}{ "goType": td.global.goType, }) }
c178404
_, otherChan := range channels { if ch == otherChan { continue } channelInfos = append(channelInfos, otherChan.ReportInfo(opts)) } states[svc] = channelInfos } return states }
c178405
ID: ch.chID, CreatedStack: ch.createdStack, LocalPeer: ch.PeerInfo(), } }
c178406
map[string]PeerRuntimeState { return fromPeerList(l, opts) }
c178407
for k := range hmap.handlers { methods = append(methods, k) } sort.Strings(methods) state.Handler.Methods = methods } else { state.Handler.Type = overrideHandler } m[k] = state } subChMap.RUnlock() return m }
c178408
getConnectionRuntimeState(p.outboundConnections, opts), ChosenCount: p.chosenCount.Load(), SCCount: p.scCount, } }
c178409
LocalHostPort: c.conn.LocalAddr().String(), RemoteHostPort: c.conn.RemoteAddr().String(), OutboundHostPort: c.outboundHP, RemotePeer: c.remotePeerInfo, InboundExchange: c.inbound.IntrospectState(opts), OutboundExchange: c.outbound.IntrospectState(opts), HealthChecks: c.healthCheckHistory.asBools(), LastActivity: c.lastActivity.Load(), } if c.relay != nil { state.Relayer = c.relay.IntrospectState(opts) } return state }
c178410
"inbound"), OutboundItems: r.outbound.IntrospectState(opts, "outbound"), MaxTimeout: r.maxTimeout, } }
c178411
k, v := range ri.items { if !opts.IncludeTombstones && v.tomb { continue } state := RelayItemState{ ID: k, RemapID: v.remapID, DestinationConnectionID: v.destination.conn.connID, Tomb: v.tomb, } setState.Items[strconv.Itoa(int(k))] = state } } return setState }
c178412
state := ExchangeRuntimeState{ ID: k, MessageType: v.msgType, } setState.Exchanges[strconv.Itoa(int(k))] = state } } mexset.RUnlock() return setState }
c178413
{ ctx, cancel := tchannel.NewContext(timeout) return tchannel.WrapWithHeaders(ctx, nil), cancel }
c178414
} } if err := tchannel.NewArgWriter(response.Arg2Writer()).Write(resp.Arg2); err != nil { return err } return tchannel.NewArgWriter(response.Arg3Writer()).Write(resp.Arg3) }
c178415
err) return } resp, err := handler.Handle(ctx, args) response := call.Response() if err != nil { resp = &Res{ SystemErr: err, } } if err := WriteResponse(response, resp); err != nil { handler.OnError(ctx, err) } }) }
c178416
span.Tracer().Inject(span.Context(), zipkinSpanFormat, s) }
c178417
ext.SpanKindRPCClient.Set(span) ext.PeerService.Set(span, serviceName) c.setPeerHostPort(span) span.SetTag("as", call.callReq.Headers[ArgScheme]) var injectable injectableSpan if err := injectable.initFromOpenTracing(span); err == nil { call.callReq.Tracing = Span(injectable) } else { call.callReq.Tracing.initRandom() } return span }
c178418
& 0xff), byte(ip >> 8 & 0xff), byte(ip & 0xff), } }
c178419
port := strconv.Itoa(int(peer.Port)) return net.JoinHostPort(host, port) }
c178420
{ return nil, err } return NewStatsdReporterClient(client), nil }
c178421
return nil } return fmt.Errorf("invalid ToS %q", string(data)) }
c178422
ph.peerScores = append(ph.peerScores, item) }
c178423
for safety ph.peerScores = old.peerScores[:n-1] return item }
c178424
*peerScore) { heap.Fix(ph, peerScore.index) }
c178425
*peerScore) { heap.Remove(ph, peerScore.index) }
c178426
+ 1 peerScore.order = newOrder + uint64(ph.rng.Intn(randRange)) heap.Push(ph, peerScore) }
c178427
peerScore. r := ph.rng.Intn(ph.Len()) ph.swapOrder(peerScore.index, r) }
c178428
ch.GetSubChannel(serviceName), serviceName: serviceName, } if opts != nil { client.opts = *opts } return client }
c178429
return p } var p *Peer // To avoid duplicate connections, only the root list should create new // peers. All other lists should keep refs to the root list's peers. p = newPeer(l.channel, hostPort, l.onPeerStatusChanged, l.onClosedConnRemoved) l.peersByHostPort[hostPort] = p return p }
c178430
{ l.RLock() p, ok := l.peersByHostPort[hostPort] l.RUnlock() return p, ok }
c178431
*options) { opts.timeout = timeout } }
c178432
&Method{m, s, s.state}) } sort.Sort(byMethodName(s.methods)) return s.methods }
c178433
s.inheritedMethods = append(s.inheritedMethods, m) } } sort.Strings(s.inheritedMethods) return s.inheritedMethods }
c178434
= append(args, &Field{f, m.state}) } return args }
c178435
args = append(args, arg.Declaration()) } return strings.Join(args, ", ") }
c178436
append(args, reqStruct+"."+arg.ArgStructName()) } return strings.Join(args, ", ") }
c178437
"error" } return fmt.Sprintf("(%v, %v)", m.state.goType(m.Method.ReturnType), "error") }
c178438
} if m.state.isResultPointer(m.ReturnType) { return respVar } return "&" + respVar }
c178439
} return fmt.Sprintf("%v, %v", respName, errName) }
c178440
%s", a.Name(), a.ArgType()) }
c178441
maxIdleTime: opts.MaxIdleTime, idleCheckInterval: opts.IdleCheckInterval, } is.start() return is }
c178442
is.idleCheckInterval}, LogField{"maxIdleTime", is.maxIdleTime}, ).Info("Starting idle connections poller.") is.started = true is.stopCh = make(chan struct{}) go is.pollerLoop() }
c178443
is.ch.log.Info("Stopping idle connections poller.") close(is.stopCh) }
c178444
if _, err := os.Stat(file); !os.IsNotExist(err) { return file, nil } } return "", fmt.Errorf("file not found on GOPATH: %q", filename) }
c178445
= state[include.file].services searchFor = parts[1] } foundService := sort.Search(len(searchServices), func(i int) bool { return searchServices[i].Name >= searchFor }) if foundService == len(searchServices) { return fmt.Errorf("failed to find base service %q for %q", s.Extends, s.Name) } s.ExtendsService = searchServices[foundService] } } return nil }
c178446
hmap.handlers = make(map[string]Handler) } hmap.handlers[method] = h }
c178447
return newExternalClient(hosts, opts) } if opts.numClients > 1 { return newInternalMultiClient(hosts, opts) } return newClient(hosts, opts) }
c178448
nil, err } return listenIP(interfaces) }
c178449
{ return err } s.cond.L.Lock() for s.refs > 0 { s.cond.Wait() } s.cond.L.Unlock() return nil }
c178450
!= nil { return nil, nil, err } if err := tchannel.NewArgReader(r.Arg3Reader()).Read(&arg3); err != nil { return nil, nil, err } return arg2, arg3, nil }
c178451
nil { return nil, nil, nil, err } resp := call.Response() var respArg2 []byte if err := tchannel.NewArgReader(resp.Arg2Reader()).Read(&respArg2); err != nil { return nil, nil, nil, err } var respArg3 []byte if err := tchannel.NewArgReader(resp.Arg3Reader()).Read(&respArg3); err != nil { return nil, nil, nil, err } return respArg2, respArg3, resp, nil }
c178452
hostPort, serviceName, method, nil) if err != nil { return nil, nil, nil, err } return WriteArgs(call, arg2, arg3) }
c178453
nil) if err != nil { return nil, nil, nil, err } return WriteArgs(call, arg2, arg3) }
c178454
WriteArgs(call, cArgs.Arg2, cArgs.Arg3) if err != nil { return nil, err } return &CRes{ Arg2: arg2, Arg3: arg3, AppError: res.ApplicationError(), }, nil }
c178455
return nil, err } if err := ch.ListenAndServe("127.0.0.1:0"); err != nil { return nil, err } return &realRelay{ ch: ch, hosts: hosts, }, nil }
c178456
if ch, ok := registrar.(*tchannel.Channel); ok { // Register the meta endpoints on the "tchannel" service name. NewServer(ch.GetSubChannel("tchannel")) } return server }
c178457
Context, r HealthRequest) (bool, string) { return f(ctx) } s.metaHandler.setHandler(wrapped) }
c178458
s.RUnlock() if !ok { log.Fatalf("Handle got call for service %v which is not registered", service) } if err := s.handle(ctx, handler, method, call); err != nil { s.onError(call, err) } }
c178459
return "unexpected-error" case ErrCodeBadRequest: return "bad-request" case ErrCodeNetwork: return "network-error" case ErrCodeProtocol: return "protocol-error" default: return c.String() } }
c178460
SystemError{code: code, msg: fmt.Sprintf(msg, args...)} }
c178461
return SystemError{code: code, msg: fmt.Sprint(wrapped), wrapped: wrapped} }
c178462
fmt.Sprintf("tchannel error %v: %s", se.Code(), se.msg) }
c178463
err == context.Canceled { return ErrRequestCancelled } return err }
c178464
err.(SystemError); ok { return se.Code() } return ErrCodeUnexpected }
c178465
c.outbound.removeExchange(req.ID()) if err := c.sendMessage(req); err != nil { return c.connectionError("send ping", err) } return c.recvMessage(ctx, &pingRes{}, mex) }
c178466
return true } // ping req is waiting for this frame, and will release it. return false }
c178467
pingRes := &pingRes{id: frame.Header.ID} if err := c.sendMessage(pingRes); err != nil { c.connectionError("send pong", err) } }
c178468
not send error frame on closed connection.") return fmt.Errorf("failed to send error frame, connection state %v", c.state) } select { case c.sendCh <- frame: // Good to go return nil default: // If the send buffer is full, log and return an error. } c.log.WithFields( LogField{"remotePeer", c.remotePeerInfo}, LogField{"id", id}, ErrField(err), ).Warn("Couldn't send outbound frame.") return fmt.Errorf("failed to send error frame, buffer full") }) }
c178469
ErrField(err), } } c.stopHealthCheck() err = c.logConnectionError(site, err) c.close(closeLogFields...) // On any connection error, notify the exchanges of this error. if c.stoppedExchanges.CAS(false, true) { c.outbound.stopExchanges(err) c.inbound.stopExchanges(err) } // checkExchanges will close the connection due to stoppedExchanges. c.checkExchanges() return err }
c178470
error { c.stateMut.Lock() err := f() c.stateMut.Unlock() return err }
c178471
error { c.stateMut.RLock() err := f() c.stateMut.RUnlock() return err }
c178472
:= c.opts.FramePool.Get() if err := frame.ReadBody(headerBuf, c.conn); err != nil { handleErr(err) c.opts.FramePool.Release(frame) return } c.updateLastActivity(frame) var releaseFrame bool if c.relay == nil { releaseFrame = c.handleFrameNoRelay(frame) } else { releaseFrame = c.handleFrameRelay(frame) } if releaseFrame { c.opts.FramePool.Release(frame) } } }
c178473
If there are frames in sendCh, we want to drain them. if len(c.sendCh) > 0 { continue } // Close the network once we're no longer writing frames. c.closeNetwork() return } } }
c178474
} if !c.relay.canClose() { return true } return false }
c178475
&& moveState(connectionInboundClosed, connectionClosed) { curState = connectionClosed } } if curState != origState { // If the connection is closed, we can notify writeFrames to stop which // closes the underlying network connection. We never close sendCh to avoid // races causing panics, see 93ef5c112c8b321367ae52d2bd79396e2e874f31 if curState == connectionClosed { close(c.stopCh) } c.log.WithFields( LogField{"newState", curState}, ).Debug("Connection state updated during shutdown.") c.callOnCloseStateChange() } }
c178476
c.conn.Close(); err != nil { c.log.WithFields( LogField{"remotePeer", c.remotePeerInfo}, ErrField(err), ).Warn("Couldn't close connection to peer.") } }
c178477
time.Unix(0, c.lastActivity.Load()) }
c178478
{ if err := validateMethod(svc, m); err != nil { return err } } return nil }
c178479
logFn = errLogger.Warn } logFn("Hyperbahn client registration failed, will retry.") }
c178480
registration failure, will retry") // Back off for a while. sleepFor := fuzzInterval(advertiseRetryInterval * time.Duration(1<<attempt)) c.sleep(sleepFor) } return err }
c178481
f.Payload[_serviceNameIndex : _serviceNameIndex+l] }
c178482
: _ttlIndex+_ttlLen]) return time.Duration(ttl) * time.Millisecond }
c178483
/ time.Millisecond) binary.BigEndian.PutUint32(f.Payload[_ttlIndex:_ttlIndex+_ttlLen], ttl) }
c178484
flags := f.Payload[_flagsIndex] return flags&hasMoreFragmentsFlag == 0 default: return false } }
c178485
ss := range ps.Platform { for _, s := range ss { unique[s] = struct{}{} } } flat := make([]string, 0, len(unique)) for s := range unique { flat = append(flat, s) } sort.Strings(flat) return flat }
c178486
else if r != "" { rs = append(rs, r) } } return rs, nil } result, _ := ps.MapSlice(mapSlice) return result, errors }
c178487
} rm := make(map[Platform][]string) for k, ss := range m { ss = mapSlice(ss) if len(ss) > 0 { rm[k] = ss } } if len(rm) == 0 { return nil } return rm } result := PlatformStrings{ Generic: mapSlice(ps.Generic), OS: mapStringMap(ps.OS), Arch: mapStringMap(ps.Arch), Platform: mapPlatformMap(ps.Platform), } return result, errors }
c178488
return nil } return pc.(*ProtoConfig) }
c178489
} } if isEmpty { return nil } ret := *expr ret.List = cases return &ret case *bzl.CallExpr: if x, ok := expr.X.(*bzl.Ident); !ok || x.Name != "select" || len(expr.List) != 1 { log.Panicf("unexpected call expression in generated imports: %#v", e) } arg := MapExprStrings(expr.List[0], f) if arg == nil { return nil } call := *expr call.List[0] = arg return &call case *bzl.BinaryExpr: x := MapExprStrings(expr.X, f) y := MapExprStrings(expr.Y, f) if x == nil { return y } if y == nil { return x } binop := *expr binop.X = x binop.Y = y return &binop default: return nil } }
c178490
return false } for _, elem := range l.List { if !addElem(elem) { return false } } return true } addDict := func(d *bzl.DictExpr) bool { for _, kv := range d.List { if !addList(kv.(*bzl.KeyValueExpr).Value) { return false } } return true } if ps.generic != nil { if !addList(ps.generic) { return e } } for _, d := range []*bzl.DictExpr{ps.os, ps.arch, ps.platform} { if d == nil { continue } if !addDict(d) { return e } } return ls.list() }
c178491
} } var parts []bzl.Expr if ps.generic != nil { parts = append(parts, ps.generic) } if ps.os != nil { parts = append(parts, makeSelect(ps.os)) } if ps.arch != nil { parts = append(parts, makeSelect(ps.arch)) } if ps.platform != nil { parts = append(parts, makeSelect(ps.platform)) } if len(parts) == 0 { return nil } if len(parts) == 1 { return parts[0] } expr := parts[0] forceMultiline(expr) for _, part := range parts[1:] { forceMultiline(part) expr = &bzl.BinaryExpr{ Op: "+", X: expr, Y: part, } } return expr }
c178492
p.OS + "_" + p.Arch case p.OS != "": return p.OS case p.Arch != "": return p.Arch default: return "" } }
c178493
if err == nil { return dir, nil } if !os.IsNotExist(err) { return "", err } if strings.HasSuffix(dir, string(os.PathSeparator)) { // stop at root dir return "", os.ErrNotExist } dir = filepath.Dir(dir) } }
c178494
dirs...) } cmd := exec.Command(args[0], args[1:]...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr log.Printf("running gazelle: %s\n", strings.Join(cmd.Args, " ")) return cmd.Run() }
c178495
} restoreBuildFilesInDir(path) return nil }) if err != nil { log.Print(err) } }
c178496
{ if usedKinds[file] == nil { usedKinds[file] = make(map[string]bool) } usedKinds[file][kind] = true } } // Fix the load statements. The order is important, so we iterate over // knownLoads instead of knownFiles. for _, known := range knownLoads { file := known.Name first := true for _, l := range loads { if l.Name() != file { continue } if first { fixLoad(l, file, usedKinds[file], knownKinds) first = false } else { fixLoad(l, file, nil, knownKinds) } if l.IsEmpty() { l.Delete() } } if first { load := fixLoad(nil, file, usedKinds[file], knownKinds) if load != nil { index := newLoadIndex(f, known.After) load.Insert(f, index) } } } }
c178497
{ return nil } load = rule.NewLoad(file) } for k := range kinds { load.Add(k) } for _, k := range load.Symbols() { if knownKinds[k] != "" && !kinds[k] { load.Remove(k) } } return load }
c178498
if r.Kind() == a && r.Index() >= index { index = r.Index() + 1 } } } return index }
c178499
l.Remove("go_repository") if l.IsEmpty() { l.Delete() } } } }