repo
stringlengths 5
67
| path
stringlengths 4
218
| func_name
stringlengths 0
151
| original_string
stringlengths 52
373k
| language
stringclasses 6
values | code
stringlengths 52
373k
| code_tokens
listlengths 10
512
| docstring
stringlengths 3
47.2k
| docstring_tokens
listlengths 3
234
| sha
stringlengths 40
40
| url
stringlengths 85
339
| partition
stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
uber/tchannel-go
|
reqres.go
|
argReader
|
func (r *reqResReader) argReader(last bool, inState reqResReaderState, outState reqResReaderState) (ArgReader, error) {
if r.state != inState {
return nil, r.failed(errReqResReaderStateMismatch{state: r.state, expectedState: inState})
}
argReader, err := r.contents.ArgReader(last)
if err != nil {
return nil, r.failed(err)
}
r.state = outState
return argReader, nil
}
|
go
|
func (r *reqResReader) argReader(last bool, inState reqResReaderState, outState reqResReaderState) (ArgReader, error) {
if r.state != inState {
return nil, r.failed(errReqResReaderStateMismatch{state: r.state, expectedState: inState})
}
argReader, err := r.contents.ArgReader(last)
if err != nil {
return nil, r.failed(err)
}
r.state = outState
return argReader, nil
}
|
[
"func",
"(",
"r",
"*",
"reqResReader",
")",
"argReader",
"(",
"last",
"bool",
",",
"inState",
"reqResReaderState",
",",
"outState",
"reqResReaderState",
")",
"(",
"ArgReader",
",",
"error",
")",
"{",
"if",
"r",
".",
"state",
"!=",
"inState",
"{",
"return",
"nil",
",",
"r",
".",
"failed",
"(",
"errReqResReaderStateMismatch",
"{",
"state",
":",
"r",
".",
"state",
",",
"expectedState",
":",
"inState",
"}",
")",
"\n",
"}",
"\n",
"argReader",
",",
"err",
":=",
"r",
".",
"contents",
".",
"ArgReader",
"(",
"last",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"r",
".",
"failed",
"(",
"err",
")",
"\n",
"}",
"\n",
"r",
".",
"state",
"=",
"outState",
"\n",
"return",
"argReader",
",",
"nil",
"\n",
"}"
] |
// argReader returns an ArgReader that can be used to read an argument. The
// ReadCloser must be closed once the argument has been read.
|
[
"argReader",
"returns",
"an",
"ArgReader",
"that",
"can",
"be",
"used",
"to",
"read",
"an",
"argument",
".",
"The",
"ReadCloser",
"must",
"be",
"closed",
"once",
"the",
"argument",
"has",
"been",
"read",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L211-L223
|
test
|
uber/tchannel-go
|
reqres.go
|
recvNextFragment
|
func (r *reqResReader) recvNextFragment(initial bool) (*readableFragment, error) {
if r.initialFragment != nil {
fragment := r.initialFragment
r.initialFragment = nil
r.previousFragment = fragment
return fragment, nil
}
// Wait for the appropriate message from the peer
message := r.messageForFragment(initial)
frame, err := r.mex.recvPeerFrameOfType(message.messageType())
if err != nil {
if err, ok := err.(errorMessage); ok {
// If we received a serialized error from the other side, then we should go through
// the normal doneReading path so stats get updated with this error.
r.err = err.AsSystemError()
return nil, err
}
return nil, r.failed(err)
}
// Parse the message and setup the fragment
fragment, err := parseInboundFragment(r.mex.framePool, frame, message)
if err != nil {
return nil, r.failed(err)
}
r.previousFragment = fragment
return fragment, nil
}
|
go
|
func (r *reqResReader) recvNextFragment(initial bool) (*readableFragment, error) {
if r.initialFragment != nil {
fragment := r.initialFragment
r.initialFragment = nil
r.previousFragment = fragment
return fragment, nil
}
// Wait for the appropriate message from the peer
message := r.messageForFragment(initial)
frame, err := r.mex.recvPeerFrameOfType(message.messageType())
if err != nil {
if err, ok := err.(errorMessage); ok {
// If we received a serialized error from the other side, then we should go through
// the normal doneReading path so stats get updated with this error.
r.err = err.AsSystemError()
return nil, err
}
return nil, r.failed(err)
}
// Parse the message and setup the fragment
fragment, err := parseInboundFragment(r.mex.framePool, frame, message)
if err != nil {
return nil, r.failed(err)
}
r.previousFragment = fragment
return fragment, nil
}
|
[
"func",
"(",
"r",
"*",
"reqResReader",
")",
"recvNextFragment",
"(",
"initial",
"bool",
")",
"(",
"*",
"readableFragment",
",",
"error",
")",
"{",
"if",
"r",
".",
"initialFragment",
"!=",
"nil",
"{",
"fragment",
":=",
"r",
".",
"initialFragment",
"\n",
"r",
".",
"initialFragment",
"=",
"nil",
"\n",
"r",
".",
"previousFragment",
"=",
"fragment",
"\n",
"return",
"fragment",
",",
"nil",
"\n",
"}",
"\n",
"message",
":=",
"r",
".",
"messageForFragment",
"(",
"initial",
")",
"\n",
"frame",
",",
"err",
":=",
"r",
".",
"mex",
".",
"recvPeerFrameOfType",
"(",
"message",
".",
"messageType",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
",",
"ok",
":=",
"err",
".",
"(",
"errorMessage",
")",
";",
"ok",
"{",
"r",
".",
"err",
"=",
"err",
".",
"AsSystemError",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"nil",
",",
"r",
".",
"failed",
"(",
"err",
")",
"\n",
"}",
"\n",
"fragment",
",",
"err",
":=",
"parseInboundFragment",
"(",
"r",
".",
"mex",
".",
"framePool",
",",
"frame",
",",
"message",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"r",
".",
"failed",
"(",
"err",
")",
"\n",
"}",
"\n",
"r",
".",
"previousFragment",
"=",
"fragment",
"\n",
"return",
"fragment",
",",
"nil",
"\n",
"}"
] |
// recvNextFragment receives the next fragment from the underlying message exchange.
|
[
"recvNextFragment",
"receives",
"the",
"next",
"fragment",
"from",
"the",
"underlying",
"message",
"exchange",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L226-L256
|
test
|
uber/tchannel-go
|
reqres.go
|
releasePreviousFragment
|
func (r *reqResReader) releasePreviousFragment() {
fragment := r.previousFragment
r.previousFragment = nil
if fragment != nil {
fragment.done()
}
}
|
go
|
func (r *reqResReader) releasePreviousFragment() {
fragment := r.previousFragment
r.previousFragment = nil
if fragment != nil {
fragment.done()
}
}
|
[
"func",
"(",
"r",
"*",
"reqResReader",
")",
"releasePreviousFragment",
"(",
")",
"{",
"fragment",
":=",
"r",
".",
"previousFragment",
"\n",
"r",
".",
"previousFragment",
"=",
"nil",
"\n",
"if",
"fragment",
"!=",
"nil",
"{",
"fragment",
".",
"done",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// releasePreviousFrament releases the last fragment returned by the reader if
// it's still around. This operation is idempotent.
|
[
"releasePreviousFrament",
"releases",
"the",
"last",
"fragment",
"returned",
"by",
"the",
"reader",
"if",
"it",
"s",
"still",
"around",
".",
"This",
"operation",
"is",
"idempotent",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L260-L266
|
test
|
uber/tchannel-go
|
reqres.go
|
failed
|
func (r *reqResReader) failed(err error) error {
r.log.Debugf("reader failed: %v existing err: %v", err, r.err)
if r.err != nil {
return r.err
}
r.mex.shutdown()
r.err = err
return r.err
}
|
go
|
func (r *reqResReader) failed(err error) error {
r.log.Debugf("reader failed: %v existing err: %v", err, r.err)
if r.err != nil {
return r.err
}
r.mex.shutdown()
r.err = err
return r.err
}
|
[
"func",
"(",
"r",
"*",
"reqResReader",
")",
"failed",
"(",
"err",
"error",
")",
"error",
"{",
"r",
".",
"log",
".",
"Debugf",
"(",
"\"reader failed: %v existing err: %v\"",
",",
"err",
",",
"r",
".",
"err",
")",
"\n",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"r",
".",
"err",
"\n",
"}",
"\n",
"r",
".",
"mex",
".",
"shutdown",
"(",
")",
"\n",
"r",
".",
"err",
"=",
"err",
"\n",
"return",
"r",
".",
"err",
"\n",
"}"
] |
// failed indicates the reader failed
|
[
"failed",
"indicates",
"the",
"reader",
"failed"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L269-L278
|
test
|
uber/tchannel-go
|
reqres.go
|
parseInboundFragment
|
func parseInboundFragment(framePool FramePool, frame *Frame, message message) (*readableFragment, error) {
rbuf := typed.NewReadBuffer(frame.SizedPayload())
fragment := new(readableFragment)
fragment.flags = rbuf.ReadSingleByte()
if err := message.read(rbuf); err != nil {
return nil, err
}
fragment.checksumType = ChecksumType(rbuf.ReadSingleByte())
fragment.checksum = rbuf.ReadBytes(fragment.checksumType.ChecksumSize())
fragment.contents = rbuf
fragment.onDone = func() {
framePool.Release(frame)
}
return fragment, rbuf.Err()
}
|
go
|
func parseInboundFragment(framePool FramePool, frame *Frame, message message) (*readableFragment, error) {
rbuf := typed.NewReadBuffer(frame.SizedPayload())
fragment := new(readableFragment)
fragment.flags = rbuf.ReadSingleByte()
if err := message.read(rbuf); err != nil {
return nil, err
}
fragment.checksumType = ChecksumType(rbuf.ReadSingleByte())
fragment.checksum = rbuf.ReadBytes(fragment.checksumType.ChecksumSize())
fragment.contents = rbuf
fragment.onDone = func() {
framePool.Release(frame)
}
return fragment, rbuf.Err()
}
|
[
"func",
"parseInboundFragment",
"(",
"framePool",
"FramePool",
",",
"frame",
"*",
"Frame",
",",
"message",
"message",
")",
"(",
"*",
"readableFragment",
",",
"error",
")",
"{",
"rbuf",
":=",
"typed",
".",
"NewReadBuffer",
"(",
"frame",
".",
"SizedPayload",
"(",
")",
")",
"\n",
"fragment",
":=",
"new",
"(",
"readableFragment",
")",
"\n",
"fragment",
".",
"flags",
"=",
"rbuf",
".",
"ReadSingleByte",
"(",
")",
"\n",
"if",
"err",
":=",
"message",
".",
"read",
"(",
"rbuf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"fragment",
".",
"checksumType",
"=",
"ChecksumType",
"(",
"rbuf",
".",
"ReadSingleByte",
"(",
")",
")",
"\n",
"fragment",
".",
"checksum",
"=",
"rbuf",
".",
"ReadBytes",
"(",
"fragment",
".",
"checksumType",
".",
"ChecksumSize",
"(",
")",
")",
"\n",
"fragment",
".",
"contents",
"=",
"rbuf",
"\n",
"fragment",
".",
"onDone",
"=",
"func",
"(",
")",
"{",
"framePool",
".",
"Release",
"(",
"frame",
")",
"\n",
"}",
"\n",
"return",
"fragment",
",",
"rbuf",
".",
"Err",
"(",
")",
"\n",
"}"
] |
// parseInboundFragment parses an incoming fragment based on the given message
|
[
"parseInboundFragment",
"parses",
"an",
"incoming",
"fragment",
"based",
"on",
"the",
"given",
"message"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L281-L296
|
test
|
uber/tchannel-go
|
thrift/context.go
|
NewContext
|
func NewContext(timeout time.Duration) (Context, context.CancelFunc) {
ctx, cancel := tchannel.NewContext(timeout)
return Wrap(ctx), cancel
}
|
go
|
func NewContext(timeout time.Duration) (Context, context.CancelFunc) {
ctx, cancel := tchannel.NewContext(timeout)
return Wrap(ctx), cancel
}
|
[
"func",
"NewContext",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"Context",
",",
"context",
".",
"CancelFunc",
")",
"{",
"ctx",
",",
"cancel",
":=",
"tchannel",
".",
"NewContext",
"(",
"timeout",
")",
"\n",
"return",
"Wrap",
"(",
"ctx",
")",
",",
"cancel",
"\n",
"}"
] |
// NewContext returns a Context that can be used to make Thrift calls.
|
[
"NewContext",
"returns",
"a",
"Context",
"that",
"can",
"be",
"used",
"to",
"make",
"Thrift",
"calls",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/context.go#L34-L37
|
test
|
uber/tchannel-go
|
thrift/context.go
|
WithHeaders
|
func WithHeaders(ctx context.Context, headers map[string]string) Context {
return tchannel.WrapWithHeaders(ctx, headers)
}
|
go
|
func WithHeaders(ctx context.Context, headers map[string]string) Context {
return tchannel.WrapWithHeaders(ctx, headers)
}
|
[
"func",
"WithHeaders",
"(",
"ctx",
"context",
".",
"Context",
",",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"Context",
"{",
"return",
"tchannel",
".",
"WrapWithHeaders",
"(",
"ctx",
",",
"headers",
")",
"\n",
"}"
] |
// WithHeaders returns a Context that can be used to make a call with request headers.
|
[
"WithHeaders",
"returns",
"a",
"Context",
"that",
"can",
"be",
"used",
"to",
"make",
"a",
"call",
"with",
"request",
"headers",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/context.go#L45-L47
|
test
|
uber/tchannel-go
|
health.go
|
healthCheck
|
func (c *Connection) healthCheck(connID uint32) {
defer close(c.healthCheckDone)
opts := c.opts.HealthChecks
ticker := c.timeTicker(opts.Interval)
defer ticker.Stop()
consecutiveFailures := 0
for {
select {
case <-ticker.C:
case <-c.healthCheckCtx.Done():
return
}
ctx, cancel := context.WithTimeout(c.healthCheckCtx, opts.Timeout)
err := c.ping(ctx)
cancel()
c.healthCheckHistory.add(err == nil)
if err == nil {
if c.log.Enabled(LogLevelDebug) {
c.log.Debug("Performed successful active health check.")
}
consecutiveFailures = 0
continue
}
// If the health check failed because the connection closed or health
// checks were stopped, we don't need to log or close the connection.
if GetSystemErrorCode(err) == ErrCodeCancelled || err == ErrInvalidConnectionState {
c.log.WithFields(ErrField(err)).Debug("Health checker stopped.")
return
}
consecutiveFailures++
c.log.WithFields(LogFields{
{"consecutiveFailures", consecutiveFailures},
ErrField(err),
{"failuresToClose", opts.FailuresToClose},
}...).Warn("Failed active health check.")
if consecutiveFailures >= opts.FailuresToClose {
c.close(LogFields{
{"reason", "health check failure"},
ErrField(err),
}...)
return
}
}
}
|
go
|
func (c *Connection) healthCheck(connID uint32) {
defer close(c.healthCheckDone)
opts := c.opts.HealthChecks
ticker := c.timeTicker(opts.Interval)
defer ticker.Stop()
consecutiveFailures := 0
for {
select {
case <-ticker.C:
case <-c.healthCheckCtx.Done():
return
}
ctx, cancel := context.WithTimeout(c.healthCheckCtx, opts.Timeout)
err := c.ping(ctx)
cancel()
c.healthCheckHistory.add(err == nil)
if err == nil {
if c.log.Enabled(LogLevelDebug) {
c.log.Debug("Performed successful active health check.")
}
consecutiveFailures = 0
continue
}
// If the health check failed because the connection closed or health
// checks were stopped, we don't need to log or close the connection.
if GetSystemErrorCode(err) == ErrCodeCancelled || err == ErrInvalidConnectionState {
c.log.WithFields(ErrField(err)).Debug("Health checker stopped.")
return
}
consecutiveFailures++
c.log.WithFields(LogFields{
{"consecutiveFailures", consecutiveFailures},
ErrField(err),
{"failuresToClose", opts.FailuresToClose},
}...).Warn("Failed active health check.")
if consecutiveFailures >= opts.FailuresToClose {
c.close(LogFields{
{"reason", "health check failure"},
ErrField(err),
}...)
return
}
}
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"healthCheck",
"(",
"connID",
"uint32",
")",
"{",
"defer",
"close",
"(",
"c",
".",
"healthCheckDone",
")",
"\n",
"opts",
":=",
"c",
".",
"opts",
".",
"HealthChecks",
"\n",
"ticker",
":=",
"c",
".",
"timeTicker",
"(",
"opts",
".",
"Interval",
")",
"\n",
"defer",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"consecutiveFailures",
":=",
"0",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"ticker",
".",
"C",
":",
"case",
"<-",
"c",
".",
"healthCheckCtx",
".",
"Done",
"(",
")",
":",
"return",
"\n",
"}",
"\n",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"c",
".",
"healthCheckCtx",
",",
"opts",
".",
"Timeout",
")",
"\n",
"err",
":=",
"c",
".",
"ping",
"(",
"ctx",
")",
"\n",
"cancel",
"(",
")",
"\n",
"c",
".",
"healthCheckHistory",
".",
"add",
"(",
"err",
"==",
"nil",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"c",
".",
"log",
".",
"Enabled",
"(",
"LogLevelDebug",
")",
"{",
"c",
".",
"log",
".",
"Debug",
"(",
"\"Performed successful active health check.\"",
")",
"\n",
"}",
"\n",
"consecutiveFailures",
"=",
"0",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"GetSystemErrorCode",
"(",
"err",
")",
"==",
"ErrCodeCancelled",
"||",
"err",
"==",
"ErrInvalidConnectionState",
"{",
"c",
".",
"log",
".",
"WithFields",
"(",
"ErrField",
"(",
"err",
")",
")",
".",
"Debug",
"(",
"\"Health checker stopped.\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"consecutiveFailures",
"++",
"\n",
"c",
".",
"log",
".",
"WithFields",
"(",
"LogFields",
"{",
"{",
"\"consecutiveFailures\"",
",",
"consecutiveFailures",
"}",
",",
"ErrField",
"(",
"err",
")",
",",
"{",
"\"failuresToClose\"",
",",
"opts",
".",
"FailuresToClose",
"}",
",",
"}",
"...",
")",
".",
"Warn",
"(",
"\"Failed active health check.\"",
")",
"\n",
"if",
"consecutiveFailures",
">=",
"opts",
".",
"FailuresToClose",
"{",
"c",
".",
"close",
"(",
"LogFields",
"{",
"{",
"\"reason\"",
",",
"\"health check failure\"",
"}",
",",
"ErrField",
"(",
"err",
")",
",",
"}",
"...",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// healthCheck will do periodic pings on the connection to check the state of the connection.
// We accept connID on the stack so can more easily debug panics or leaked goroutines.
|
[
"healthCheck",
"will",
"do",
"periodic",
"pings",
"on",
"the",
"connection",
"to",
"check",
"the",
"state",
"of",
"the",
"connection",
".",
"We",
"accept",
"connID",
"on",
"the",
"stack",
"so",
"can",
"more",
"easily",
"debug",
"panics",
"or",
"leaked",
"goroutines",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/health.go#L111-L161
|
test
|
uber/tchannel-go
|
context_builder.go
|
SetTimeout
|
func (cb *ContextBuilder) SetTimeout(timeout time.Duration) *ContextBuilder {
cb.Timeout = timeout
return cb
}
|
go
|
func (cb *ContextBuilder) SetTimeout(timeout time.Duration) *ContextBuilder {
cb.Timeout = timeout
return cb
}
|
[
"func",
"(",
"cb",
"*",
"ContextBuilder",
")",
"SetTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"ContextBuilder",
"{",
"cb",
".",
"Timeout",
"=",
"timeout",
"\n",
"return",
"cb",
"\n",
"}"
] |
// SetTimeout sets the timeout for the Context.
|
[
"SetTimeout",
"sets",
"the",
"timeout",
"for",
"the",
"Context",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_builder.go#L77-L80
|
test
|
uber/tchannel-go
|
context_builder.go
|
AddHeader
|
func (cb *ContextBuilder) AddHeader(key, value string) *ContextBuilder {
if cb.Headers == nil {
cb.Headers = map[string]string{key: value}
} else {
cb.Headers[key] = value
}
return cb
}
|
go
|
func (cb *ContextBuilder) AddHeader(key, value string) *ContextBuilder {
if cb.Headers == nil {
cb.Headers = map[string]string{key: value}
} else {
cb.Headers[key] = value
}
return cb
}
|
[
"func",
"(",
"cb",
"*",
"ContextBuilder",
")",
"AddHeader",
"(",
"key",
",",
"value",
"string",
")",
"*",
"ContextBuilder",
"{",
"if",
"cb",
".",
"Headers",
"==",
"nil",
"{",
"cb",
".",
"Headers",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"key",
":",
"value",
"}",
"\n",
"}",
"else",
"{",
"cb",
".",
"Headers",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"return",
"cb",
"\n",
"}"
] |
// AddHeader adds a single application header to the Context.
|
[
"AddHeader",
"adds",
"a",
"single",
"application",
"header",
"to",
"the",
"Context",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_builder.go#L83-L90
|
test
|
uber/tchannel-go
|
context_builder.go
|
SetHeaders
|
func (cb *ContextBuilder) SetHeaders(headers map[string]string) *ContextBuilder {
cb.Headers = headers
cb.replaceParentHeaders = true
return cb
}
|
go
|
func (cb *ContextBuilder) SetHeaders(headers map[string]string) *ContextBuilder {
cb.Headers = headers
cb.replaceParentHeaders = true
return cb
}
|
[
"func",
"(",
"cb",
"*",
"ContextBuilder",
")",
"SetHeaders",
"(",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"ContextBuilder",
"{",
"cb",
".",
"Headers",
"=",
"headers",
"\n",
"cb",
".",
"replaceParentHeaders",
"=",
"true",
"\n",
"return",
"cb",
"\n",
"}"
] |
// SetHeaders sets the application headers for this Context.
// If there is a ParentContext, its headers will be ignored after the call to this method.
|
[
"SetHeaders",
"sets",
"the",
"application",
"headers",
"for",
"this",
"Context",
".",
"If",
"there",
"is",
"a",
"ParentContext",
"its",
"headers",
"will",
"be",
"ignored",
"after",
"the",
"call",
"to",
"this",
"method",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_builder.go#L94-L98
|
test
|
uber/tchannel-go
|
context_builder.go
|
SetConnectTimeout
|
func (cb *ContextBuilder) SetConnectTimeout(d time.Duration) *ContextBuilder {
cb.ConnectTimeout = d
return cb
}
|
go
|
func (cb *ContextBuilder) SetConnectTimeout(d time.Duration) *ContextBuilder {
cb.ConnectTimeout = d
return cb
}
|
[
"func",
"(",
"cb",
"*",
"ContextBuilder",
")",
"SetConnectTimeout",
"(",
"d",
"time",
".",
"Duration",
")",
"*",
"ContextBuilder",
"{",
"cb",
".",
"ConnectTimeout",
"=",
"d",
"\n",
"return",
"cb",
"\n",
"}"
] |
// SetConnectTimeout sets the ConnectionTimeout for this context.
// The context timeout applies to the whole call, while the connect
// timeout only applies to creating a new connection.
|
[
"SetConnectTimeout",
"sets",
"the",
"ConnectionTimeout",
"for",
"this",
"context",
".",
"The",
"context",
"timeout",
"applies",
"to",
"the",
"whole",
"call",
"while",
"the",
"connect",
"timeout",
"only",
"applies",
"to",
"creating",
"a",
"new",
"connection",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_builder.go#L139-L142
|
test
|
uber/tchannel-go
|
context_builder.go
|
SetRetryOptions
|
func (cb *ContextBuilder) SetRetryOptions(retryOptions *RetryOptions) *ContextBuilder {
cb.RetryOptions = retryOptions
return cb
}
|
go
|
func (cb *ContextBuilder) SetRetryOptions(retryOptions *RetryOptions) *ContextBuilder {
cb.RetryOptions = retryOptions
return cb
}
|
[
"func",
"(",
"cb",
"*",
"ContextBuilder",
")",
"SetRetryOptions",
"(",
"retryOptions",
"*",
"RetryOptions",
")",
"*",
"ContextBuilder",
"{",
"cb",
".",
"RetryOptions",
"=",
"retryOptions",
"\n",
"return",
"cb",
"\n",
"}"
] |
// SetRetryOptions sets RetryOptions in the context.
|
[
"SetRetryOptions",
"sets",
"RetryOptions",
"in",
"the",
"context",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_builder.go#L164-L167
|
test
|
uber/tchannel-go
|
context_builder.go
|
SetTimeoutPerAttempt
|
func (cb *ContextBuilder) SetTimeoutPerAttempt(timeoutPerAttempt time.Duration) *ContextBuilder {
if cb.RetryOptions == nil {
cb.RetryOptions = &RetryOptions{}
}
cb.RetryOptions.TimeoutPerAttempt = timeoutPerAttempt
return cb
}
|
go
|
func (cb *ContextBuilder) SetTimeoutPerAttempt(timeoutPerAttempt time.Duration) *ContextBuilder {
if cb.RetryOptions == nil {
cb.RetryOptions = &RetryOptions{}
}
cb.RetryOptions.TimeoutPerAttempt = timeoutPerAttempt
return cb
}
|
[
"func",
"(",
"cb",
"*",
"ContextBuilder",
")",
"SetTimeoutPerAttempt",
"(",
"timeoutPerAttempt",
"time",
".",
"Duration",
")",
"*",
"ContextBuilder",
"{",
"if",
"cb",
".",
"RetryOptions",
"==",
"nil",
"{",
"cb",
".",
"RetryOptions",
"=",
"&",
"RetryOptions",
"{",
"}",
"\n",
"}",
"\n",
"cb",
".",
"RetryOptions",
".",
"TimeoutPerAttempt",
"=",
"timeoutPerAttempt",
"\n",
"return",
"cb",
"\n",
"}"
] |
// SetTimeoutPerAttempt sets TimeoutPerAttempt in RetryOptions.
|
[
"SetTimeoutPerAttempt",
"sets",
"TimeoutPerAttempt",
"in",
"RetryOptions",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_builder.go#L170-L176
|
test
|
uber/tchannel-go
|
context_builder.go
|
SetParentContext
|
func (cb *ContextBuilder) SetParentContext(ctx context.Context) *ContextBuilder {
cb.ParentContext = ctx
return cb
}
|
go
|
func (cb *ContextBuilder) SetParentContext(ctx context.Context) *ContextBuilder {
cb.ParentContext = ctx
return cb
}
|
[
"func",
"(",
"cb",
"*",
"ContextBuilder",
")",
"SetParentContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"*",
"ContextBuilder",
"{",
"cb",
".",
"ParentContext",
"=",
"ctx",
"\n",
"return",
"cb",
"\n",
"}"
] |
// SetParentContext sets the parent for the Context.
|
[
"SetParentContext",
"sets",
"the",
"parent",
"for",
"the",
"Context",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_builder.go#L179-L182
|
test
|
uber/tchannel-go
|
context_builder.go
|
Build
|
func (cb *ContextBuilder) Build() (ContextWithHeaders, context.CancelFunc) {
params := &tchannelCtxParams{
options: cb.CallOptions,
call: cb.incomingCall,
retryOptions: cb.RetryOptions,
connectTimeout: cb.ConnectTimeout,
hideListeningOnOutbound: cb.hideListeningOnOutbound,
tracingDisabled: cb.TracingDisabled,
}
parent := cb.ParentContext
if parent == nil {
parent = context.Background()
} else if headerCtx, ok := parent.(headerCtx); ok {
// Unwrap any headerCtx, since we'll be rewrapping anyway.
parent = headerCtx.Context
}
var (
ctx context.Context
cancel context.CancelFunc
)
// All contexts created must have a timeout, but if the parent
// already has a timeout, and the user has not specified one, then we
// can use context.WithCancel
_, parentHasDeadline := parent.Deadline()
if cb.Timeout == 0 && parentHasDeadline {
ctx, cancel = context.WithCancel(parent)
} else {
ctx, cancel = context.WithTimeout(parent, cb.Timeout)
}
ctx = context.WithValue(ctx, contextKeyTChannel, params)
return WrapWithHeaders(ctx, cb.getHeaders()), cancel
}
|
go
|
func (cb *ContextBuilder) Build() (ContextWithHeaders, context.CancelFunc) {
params := &tchannelCtxParams{
options: cb.CallOptions,
call: cb.incomingCall,
retryOptions: cb.RetryOptions,
connectTimeout: cb.ConnectTimeout,
hideListeningOnOutbound: cb.hideListeningOnOutbound,
tracingDisabled: cb.TracingDisabled,
}
parent := cb.ParentContext
if parent == nil {
parent = context.Background()
} else if headerCtx, ok := parent.(headerCtx); ok {
// Unwrap any headerCtx, since we'll be rewrapping anyway.
parent = headerCtx.Context
}
var (
ctx context.Context
cancel context.CancelFunc
)
// All contexts created must have a timeout, but if the parent
// already has a timeout, and the user has not specified one, then we
// can use context.WithCancel
_, parentHasDeadline := parent.Deadline()
if cb.Timeout == 0 && parentHasDeadline {
ctx, cancel = context.WithCancel(parent)
} else {
ctx, cancel = context.WithTimeout(parent, cb.Timeout)
}
ctx = context.WithValue(ctx, contextKeyTChannel, params)
return WrapWithHeaders(ctx, cb.getHeaders()), cancel
}
|
[
"func",
"(",
"cb",
"*",
"ContextBuilder",
")",
"Build",
"(",
")",
"(",
"ContextWithHeaders",
",",
"context",
".",
"CancelFunc",
")",
"{",
"params",
":=",
"&",
"tchannelCtxParams",
"{",
"options",
":",
"cb",
".",
"CallOptions",
",",
"call",
":",
"cb",
".",
"incomingCall",
",",
"retryOptions",
":",
"cb",
".",
"RetryOptions",
",",
"connectTimeout",
":",
"cb",
".",
"ConnectTimeout",
",",
"hideListeningOnOutbound",
":",
"cb",
".",
"hideListeningOnOutbound",
",",
"tracingDisabled",
":",
"cb",
".",
"TracingDisabled",
",",
"}",
"\n",
"parent",
":=",
"cb",
".",
"ParentContext",
"\n",
"if",
"parent",
"==",
"nil",
"{",
"parent",
"=",
"context",
".",
"Background",
"(",
")",
"\n",
"}",
"else",
"if",
"headerCtx",
",",
"ok",
":=",
"parent",
".",
"(",
"headerCtx",
")",
";",
"ok",
"{",
"parent",
"=",
"headerCtx",
".",
"Context",
"\n",
"}",
"\n",
"var",
"(",
"ctx",
"context",
".",
"Context",
"\n",
"cancel",
"context",
".",
"CancelFunc",
"\n",
")",
"\n",
"_",
",",
"parentHasDeadline",
":=",
"parent",
".",
"Deadline",
"(",
")",
"\n",
"if",
"cb",
".",
"Timeout",
"==",
"0",
"&&",
"parentHasDeadline",
"{",
"ctx",
",",
"cancel",
"=",
"context",
".",
"WithCancel",
"(",
"parent",
")",
"\n",
"}",
"else",
"{",
"ctx",
",",
"cancel",
"=",
"context",
".",
"WithTimeout",
"(",
"parent",
",",
"cb",
".",
"Timeout",
")",
"\n",
"}",
"\n",
"ctx",
"=",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"contextKeyTChannel",
",",
"params",
")",
"\n",
"return",
"WrapWithHeaders",
"(",
"ctx",
",",
"cb",
".",
"getHeaders",
"(",
")",
")",
",",
"cancel",
"\n",
"}"
] |
// Build returns a ContextWithHeaders that can be used to make calls.
|
[
"Build",
"returns",
"a",
"ContextWithHeaders",
"that",
"can",
"be",
"used",
"to",
"make",
"calls",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_builder.go#L210-L244
|
test
|
uber/tchannel-go
|
calloptions.go
|
overrideHeaders
|
func (c *CallOptions) overrideHeaders(headers transportHeaders) {
if c.Format != "" {
headers[ArgScheme] = c.Format.String()
}
if c.ShardKey != "" {
headers[ShardKey] = c.ShardKey
}
if c.RoutingKey != "" {
headers[RoutingKey] = c.RoutingKey
}
if c.RoutingDelegate != "" {
headers[RoutingDelegate] = c.RoutingDelegate
}
if c.callerName != "" {
headers[CallerName] = c.callerName
}
}
|
go
|
func (c *CallOptions) overrideHeaders(headers transportHeaders) {
if c.Format != "" {
headers[ArgScheme] = c.Format.String()
}
if c.ShardKey != "" {
headers[ShardKey] = c.ShardKey
}
if c.RoutingKey != "" {
headers[RoutingKey] = c.RoutingKey
}
if c.RoutingDelegate != "" {
headers[RoutingDelegate] = c.RoutingDelegate
}
if c.callerName != "" {
headers[CallerName] = c.callerName
}
}
|
[
"func",
"(",
"c",
"*",
"CallOptions",
")",
"overrideHeaders",
"(",
"headers",
"transportHeaders",
")",
"{",
"if",
"c",
".",
"Format",
"!=",
"\"\"",
"{",
"headers",
"[",
"ArgScheme",
"]",
"=",
"c",
".",
"Format",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"c",
".",
"ShardKey",
"!=",
"\"\"",
"{",
"headers",
"[",
"ShardKey",
"]",
"=",
"c",
".",
"ShardKey",
"\n",
"}",
"\n",
"if",
"c",
".",
"RoutingKey",
"!=",
"\"\"",
"{",
"headers",
"[",
"RoutingKey",
"]",
"=",
"c",
".",
"RoutingKey",
"\n",
"}",
"\n",
"if",
"c",
".",
"RoutingDelegate",
"!=",
"\"\"",
"{",
"headers",
"[",
"RoutingDelegate",
"]",
"=",
"c",
".",
"RoutingDelegate",
"\n",
"}",
"\n",
"if",
"c",
".",
"callerName",
"!=",
"\"\"",
"{",
"headers",
"[",
"CallerName",
"]",
"=",
"c",
".",
"callerName",
"\n",
"}",
"\n",
"}"
] |
// overrideHeaders sets headers if the call options contains non-default values.
|
[
"overrideHeaders",
"sets",
"headers",
"if",
"the",
"call",
"options",
"contains",
"non",
"-",
"default",
"values",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/calloptions.go#L72-L88
|
test
|
uber/tchannel-go
|
arguments.go
|
Read
|
func (r ArgReadHelper) Read(bs *[]byte) error {
return r.read(func() error {
var err error
*bs, err = ioutil.ReadAll(r.reader)
return err
})
}
|
go
|
func (r ArgReadHelper) Read(bs *[]byte) error {
return r.read(func() error {
var err error
*bs, err = ioutil.ReadAll(r.reader)
return err
})
}
|
[
"func",
"(",
"r",
"ArgReadHelper",
")",
"Read",
"(",
"bs",
"*",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"r",
".",
"read",
"(",
"func",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"*",
"bs",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"reader",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n",
"}"
] |
// Read reads from the reader into the byte slice.
|
[
"Read",
"reads",
"from",
"the",
"reader",
"into",
"the",
"byte",
"slice",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/arguments.go#L86-L92
|
test
|
uber/tchannel-go
|
arguments.go
|
ReadJSON
|
func (r ArgReadHelper) ReadJSON(data interface{}) error {
return r.read(func() error {
// TChannel allows for 0 length values (not valid JSON), so we use a bufio.Reader
// to check whether data is of 0 length.
reader := bufio.NewReader(r.reader)
if _, err := reader.Peek(1); err == io.EOF {
// If the data is 0 length, then we don't try to read anything.
return nil
} else if err != nil {
return err
}
d := json.NewDecoder(reader)
return d.Decode(data)
})
}
|
go
|
func (r ArgReadHelper) ReadJSON(data interface{}) error {
return r.read(func() error {
// TChannel allows for 0 length values (not valid JSON), so we use a bufio.Reader
// to check whether data is of 0 length.
reader := bufio.NewReader(r.reader)
if _, err := reader.Peek(1); err == io.EOF {
// If the data is 0 length, then we don't try to read anything.
return nil
} else if err != nil {
return err
}
d := json.NewDecoder(reader)
return d.Decode(data)
})
}
|
[
"func",
"(",
"r",
"ArgReadHelper",
")",
"ReadJSON",
"(",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"r",
".",
"read",
"(",
"func",
"(",
")",
"error",
"{",
"reader",
":=",
"bufio",
".",
"NewReader",
"(",
"r",
".",
"reader",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"reader",
".",
"Peek",
"(",
"1",
")",
";",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"d",
":=",
"json",
".",
"NewDecoder",
"(",
"reader",
")",
"\n",
"return",
"d",
".",
"Decode",
"(",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// ReadJSON deserializes JSON from the underlying reader into data.
|
[
"ReadJSON",
"deserializes",
"JSON",
"from",
"the",
"underlying",
"reader",
"into",
"data",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/arguments.go#L95-L110
|
test
|
uber/tchannel-go
|
arguments.go
|
NewArgWriter
|
func NewArgWriter(writer io.WriteCloser, err error) ArgWriteHelper {
return ArgWriteHelper{writer, err}
}
|
go
|
func NewArgWriter(writer io.WriteCloser, err error) ArgWriteHelper {
return ArgWriteHelper{writer, err}
}
|
[
"func",
"NewArgWriter",
"(",
"writer",
"io",
".",
"WriteCloser",
",",
"err",
"error",
")",
"ArgWriteHelper",
"{",
"return",
"ArgWriteHelper",
"{",
"writer",
",",
"err",
"}",
"\n",
"}"
] |
// NewArgWriter wraps the result of calling ArgXWriter to provider a simpler
// interface for writing arguments.
|
[
"NewArgWriter",
"wraps",
"the",
"result",
"of",
"calling",
"ArgXWriter",
"to",
"provider",
"a",
"simpler",
"interface",
"for",
"writing",
"arguments",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/arguments.go#L120-L122
|
test
|
uber/tchannel-go
|
arguments.go
|
Write
|
func (w ArgWriteHelper) Write(bs []byte) error {
return w.write(func() error {
_, err := w.writer.Write(bs)
return err
})
}
|
go
|
func (w ArgWriteHelper) Write(bs []byte) error {
return w.write(func() error {
_, err := w.writer.Write(bs)
return err
})
}
|
[
"func",
"(",
"w",
"ArgWriteHelper",
")",
"Write",
"(",
"bs",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"w",
".",
"write",
"(",
"func",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"w",
".",
"writer",
".",
"Write",
"(",
"bs",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n",
"}"
] |
// Write writes the given bytes to the underlying writer.
|
[
"Write",
"writes",
"the",
"given",
"bytes",
"to",
"the",
"underlying",
"writer",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/arguments.go#L137-L142
|
test
|
uber/tchannel-go
|
arguments.go
|
WriteJSON
|
func (w ArgWriteHelper) WriteJSON(data interface{}) error {
return w.write(func() error {
e := json.NewEncoder(w.writer)
return e.Encode(data)
})
}
|
go
|
func (w ArgWriteHelper) WriteJSON(data interface{}) error {
return w.write(func() error {
e := json.NewEncoder(w.writer)
return e.Encode(data)
})
}
|
[
"func",
"(",
"w",
"ArgWriteHelper",
")",
"WriteJSON",
"(",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"w",
".",
"write",
"(",
"func",
"(",
")",
"error",
"{",
"e",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
".",
"writer",
")",
"\n",
"return",
"e",
".",
"Encode",
"(",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// WriteJSON writes the given object as JSON.
|
[
"WriteJSON",
"writes",
"the",
"given",
"object",
"as",
"JSON",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/arguments.go#L145-L150
|
test
|
uber/tchannel-go
|
pprof/pprof.go
|
Register
|
func Register(registrar tchannel.Registrar) {
handler := func(ctx context.Context, call *tchannel.InboundCall) {
req, err := thttp.ReadRequest(call)
if err != nil {
registrar.Logger().WithFields(
tchannel.LogField{Key: "err", Value: err.Error()},
).Warn("Failed to read HTTP request.")
return
}
serveHTTP(req, call.Response())
}
registrar.Register(tchannel.HandlerFunc(handler), "_pprof")
}
|
go
|
func Register(registrar tchannel.Registrar) {
handler := func(ctx context.Context, call *tchannel.InboundCall) {
req, err := thttp.ReadRequest(call)
if err != nil {
registrar.Logger().WithFields(
tchannel.LogField{Key: "err", Value: err.Error()},
).Warn("Failed to read HTTP request.")
return
}
serveHTTP(req, call.Response())
}
registrar.Register(tchannel.HandlerFunc(handler), "_pprof")
}
|
[
"func",
"Register",
"(",
"registrar",
"tchannel",
".",
"Registrar",
")",
"{",
"handler",
":=",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"call",
"*",
"tchannel",
".",
"InboundCall",
")",
"{",
"req",
",",
"err",
":=",
"thttp",
".",
"ReadRequest",
"(",
"call",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"registrar",
".",
"Logger",
"(",
")",
".",
"WithFields",
"(",
"tchannel",
".",
"LogField",
"{",
"Key",
":",
"\"err\"",
",",
"Value",
":",
"err",
".",
"Error",
"(",
")",
"}",
",",
")",
".",
"Warn",
"(",
"\"Failed to read HTTP request.\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"serveHTTP",
"(",
"req",
",",
"call",
".",
"Response",
"(",
")",
")",
"\n",
"}",
"\n",
"registrar",
".",
"Register",
"(",
"tchannel",
".",
"HandlerFunc",
"(",
"handler",
")",
",",
"\"_pprof\"",
")",
"\n",
"}"
] |
// Register registers pprof endpoints on the given registrar under _pprof.
// The _pprof endpoint uses as-http and is a tunnel to the default serve mux.
|
[
"Register",
"registers",
"pprof",
"endpoints",
"on",
"the",
"given",
"registrar",
"under",
"_pprof",
".",
"The",
"_pprof",
"endpoint",
"uses",
"as",
"-",
"http",
"and",
"is",
"a",
"tunnel",
"to",
"the",
"default",
"serve",
"mux",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/pprof/pprof.go#L41-L54
|
test
|
uber/tchannel-go
|
relay.go
|
Count
|
func (r *relayItems) Count() int {
r.RLock()
n := len(r.items) - int(r.tombs)
r.RUnlock()
return n
}
|
go
|
func (r *relayItems) Count() int {
r.RLock()
n := len(r.items) - int(r.tombs)
r.RUnlock()
return n
}
|
[
"func",
"(",
"r",
"*",
"relayItems",
")",
"Count",
"(",
")",
"int",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"n",
":=",
"len",
"(",
"r",
".",
"items",
")",
"-",
"int",
"(",
"r",
".",
"tombs",
")",
"\n",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"n",
"\n",
"}"
] |
// Count returns the number of non-tombstone items in the relay.
|
[
"Count",
"returns",
"the",
"number",
"of",
"non",
"-",
"tombstone",
"items",
"in",
"the",
"relay",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L86-L91
|
test
|
uber/tchannel-go
|
relay.go
|
Get
|
func (r *relayItems) Get(id uint32) (relayItem, bool) {
r.RLock()
item, ok := r.items[id]
r.RUnlock()
return item, ok
}
|
go
|
func (r *relayItems) Get(id uint32) (relayItem, bool) {
r.RLock()
item, ok := r.items[id]
r.RUnlock()
return item, ok
}
|
[
"func",
"(",
"r",
"*",
"relayItems",
")",
"Get",
"(",
"id",
"uint32",
")",
"(",
"relayItem",
",",
"bool",
")",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"item",
",",
"ok",
":=",
"r",
".",
"items",
"[",
"id",
"]",
"\n",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"item",
",",
"ok",
"\n",
"}"
] |
// Get checks for a relay item by ID, returning the item and a bool indicating
// whether the item was found.
|
[
"Get",
"checks",
"for",
"a",
"relay",
"item",
"by",
"ID",
"returning",
"the",
"item",
"and",
"a",
"bool",
"indicating",
"whether",
"the",
"item",
"was",
"found",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L95-L101
|
test
|
uber/tchannel-go
|
relay.go
|
Add
|
func (r *relayItems) Add(id uint32, item relayItem) {
r.Lock()
r.items[id] = item
r.Unlock()
}
|
go
|
func (r *relayItems) Add(id uint32, item relayItem) {
r.Lock()
r.items[id] = item
r.Unlock()
}
|
[
"func",
"(",
"r",
"*",
"relayItems",
")",
"Add",
"(",
"id",
"uint32",
",",
"item",
"relayItem",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"r",
".",
"items",
"[",
"id",
"]",
"=",
"item",
"\n",
"r",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// Add adds a relay item.
|
[
"Add",
"adds",
"a",
"relay",
"item",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L104-L108
|
test
|
uber/tchannel-go
|
relay.go
|
Entomb
|
func (r *relayItems) Entomb(id uint32, deleteAfter time.Duration) (relayItem, bool) {
r.Lock()
if r.tombs > _maxRelayTombs {
r.Unlock()
r.logger.WithFields(LogField{"id", id}).Warn("Too many tombstones, deleting relay item immediately.")
return r.Delete(id)
}
item, ok := r.items[id]
if !ok {
r.Unlock()
r.logger.WithFields(LogField{"id", id}).Warn("Can't find relay item to entomb.")
return item, false
}
if item.tomb {
r.Unlock()
r.logger.WithFields(LogField{"id", id}).Warn("Re-entombing a tombstone.")
return item, false
}
r.tombs++
item.tomb = true
r.items[id] = item
r.Unlock()
// TODO: We should be clearing these out in batches, rather than creating
// individual timers for each item.
time.AfterFunc(deleteAfter, func() { r.Delete(id) })
return item, true
}
|
go
|
func (r *relayItems) Entomb(id uint32, deleteAfter time.Duration) (relayItem, bool) {
r.Lock()
if r.tombs > _maxRelayTombs {
r.Unlock()
r.logger.WithFields(LogField{"id", id}).Warn("Too many tombstones, deleting relay item immediately.")
return r.Delete(id)
}
item, ok := r.items[id]
if !ok {
r.Unlock()
r.logger.WithFields(LogField{"id", id}).Warn("Can't find relay item to entomb.")
return item, false
}
if item.tomb {
r.Unlock()
r.logger.WithFields(LogField{"id", id}).Warn("Re-entombing a tombstone.")
return item, false
}
r.tombs++
item.tomb = true
r.items[id] = item
r.Unlock()
// TODO: We should be clearing these out in batches, rather than creating
// individual timers for each item.
time.AfterFunc(deleteAfter, func() { r.Delete(id) })
return item, true
}
|
[
"func",
"(",
"r",
"*",
"relayItems",
")",
"Entomb",
"(",
"id",
"uint32",
",",
"deleteAfter",
"time",
".",
"Duration",
")",
"(",
"relayItem",
",",
"bool",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"if",
"r",
".",
"tombs",
">",
"_maxRelayTombs",
"{",
"r",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"logger",
".",
"WithFields",
"(",
"LogField",
"{",
"\"id\"",
",",
"id",
"}",
")",
".",
"Warn",
"(",
"\"Too many tombstones, deleting relay item immediately.\"",
")",
"\n",
"return",
"r",
".",
"Delete",
"(",
"id",
")",
"\n",
"}",
"\n",
"item",
",",
"ok",
":=",
"r",
".",
"items",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"r",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"logger",
".",
"WithFields",
"(",
"LogField",
"{",
"\"id\"",
",",
"id",
"}",
")",
".",
"Warn",
"(",
"\"Can't find relay item to entomb.\"",
")",
"\n",
"return",
"item",
",",
"false",
"\n",
"}",
"\n",
"if",
"item",
".",
"tomb",
"{",
"r",
".",
"Unlock",
"(",
")",
"\n",
"r",
".",
"logger",
".",
"WithFields",
"(",
"LogField",
"{",
"\"id\"",
",",
"id",
"}",
")",
".",
"Warn",
"(",
"\"Re-entombing a tombstone.\"",
")",
"\n",
"return",
"item",
",",
"false",
"\n",
"}",
"\n",
"r",
".",
"tombs",
"++",
"\n",
"item",
".",
"tomb",
"=",
"true",
"\n",
"r",
".",
"items",
"[",
"id",
"]",
"=",
"item",
"\n",
"r",
".",
"Unlock",
"(",
")",
"\n",
"time",
".",
"AfterFunc",
"(",
"deleteAfter",
",",
"func",
"(",
")",
"{",
"r",
".",
"Delete",
"(",
"id",
")",
"}",
")",
"\n",
"return",
"item",
",",
"true",
"\n",
"}"
] |
// Entomb sets the tomb bit on a relayItem and schedules a garbage collection. It
// returns the entombed item, along with a bool indicating whether we completed
// a relayed call.
|
[
"Entomb",
"sets",
"the",
"tomb",
"bit",
"on",
"a",
"relayItem",
"and",
"schedules",
"a",
"garbage",
"collection",
".",
"It",
"returns",
"the",
"entombed",
"item",
"along",
"with",
"a",
"bool",
"indicating",
"whether",
"we",
"completed",
"a",
"relayed",
"call",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L135-L162
|
test
|
uber/tchannel-go
|
relay.go
|
NewRelayer
|
func NewRelayer(ch *Channel, conn *Connection) *Relayer {
r := &Relayer{
relayHost: ch.RelayHost(),
maxTimeout: ch.relayMaxTimeout,
localHandler: ch.relayLocal,
outbound: newRelayItems(conn.log.WithFields(LogField{"relayItems", "outbound"})),
inbound: newRelayItems(conn.log.WithFields(LogField{"relayItems", "inbound"})),
peers: ch.RootPeers(),
conn: conn,
relayConn: &relay.Conn{
RemoteAddr: conn.conn.RemoteAddr().String(),
RemoteProcessName: conn.RemotePeerInfo().ProcessName,
IsOutbound: conn.connDirection == outbound,
},
logger: conn.log,
}
r.timeouts = newRelayTimerPool(r.timeoutRelayItem, ch.relayTimerVerify)
return r
}
|
go
|
func NewRelayer(ch *Channel, conn *Connection) *Relayer {
r := &Relayer{
relayHost: ch.RelayHost(),
maxTimeout: ch.relayMaxTimeout,
localHandler: ch.relayLocal,
outbound: newRelayItems(conn.log.WithFields(LogField{"relayItems", "outbound"})),
inbound: newRelayItems(conn.log.WithFields(LogField{"relayItems", "inbound"})),
peers: ch.RootPeers(),
conn: conn,
relayConn: &relay.Conn{
RemoteAddr: conn.conn.RemoteAddr().String(),
RemoteProcessName: conn.RemotePeerInfo().ProcessName,
IsOutbound: conn.connDirection == outbound,
},
logger: conn.log,
}
r.timeouts = newRelayTimerPool(r.timeoutRelayItem, ch.relayTimerVerify)
return r
}
|
[
"func",
"NewRelayer",
"(",
"ch",
"*",
"Channel",
",",
"conn",
"*",
"Connection",
")",
"*",
"Relayer",
"{",
"r",
":=",
"&",
"Relayer",
"{",
"relayHost",
":",
"ch",
".",
"RelayHost",
"(",
")",
",",
"maxTimeout",
":",
"ch",
".",
"relayMaxTimeout",
",",
"localHandler",
":",
"ch",
".",
"relayLocal",
",",
"outbound",
":",
"newRelayItems",
"(",
"conn",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"relayItems\"",
",",
"\"outbound\"",
"}",
")",
")",
",",
"inbound",
":",
"newRelayItems",
"(",
"conn",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"relayItems\"",
",",
"\"inbound\"",
"}",
")",
")",
",",
"peers",
":",
"ch",
".",
"RootPeers",
"(",
")",
",",
"conn",
":",
"conn",
",",
"relayConn",
":",
"&",
"relay",
".",
"Conn",
"{",
"RemoteAddr",
":",
"conn",
".",
"conn",
".",
"RemoteAddr",
"(",
")",
".",
"String",
"(",
")",
",",
"RemoteProcessName",
":",
"conn",
".",
"RemotePeerInfo",
"(",
")",
".",
"ProcessName",
",",
"IsOutbound",
":",
"conn",
".",
"connDirection",
"==",
"outbound",
",",
"}",
",",
"logger",
":",
"conn",
".",
"log",
",",
"}",
"\n",
"r",
".",
"timeouts",
"=",
"newRelayTimerPool",
"(",
"r",
".",
"timeoutRelayItem",
",",
"ch",
".",
"relayTimerVerify",
")",
"\n",
"return",
"r",
"\n",
"}"
] |
// NewRelayer constructs a Relayer.
|
[
"NewRelayer",
"constructs",
"a",
"Relayer",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L202-L220
|
test
|
uber/tchannel-go
|
relay.go
|
Relay
|
func (r *Relayer) Relay(f *Frame) error {
if f.messageType() != messageTypeCallReq {
err := r.handleNonCallReq(f)
if err == errUnknownID {
// This ID may be owned by an outgoing call, so check the outbound
// message exchange, and if it succeeds, then the frame has been
// handled successfully.
if err := r.conn.outbound.forwardPeerFrame(f); err == nil {
return nil
}
}
return err
}
return r.handleCallReq(newLazyCallReq(f))
}
|
go
|
func (r *Relayer) Relay(f *Frame) error {
if f.messageType() != messageTypeCallReq {
err := r.handleNonCallReq(f)
if err == errUnknownID {
// This ID may be owned by an outgoing call, so check the outbound
// message exchange, and if it succeeds, then the frame has been
// handled successfully.
if err := r.conn.outbound.forwardPeerFrame(f); err == nil {
return nil
}
}
return err
}
return r.handleCallReq(newLazyCallReq(f))
}
|
[
"func",
"(",
"r",
"*",
"Relayer",
")",
"Relay",
"(",
"f",
"*",
"Frame",
")",
"error",
"{",
"if",
"f",
".",
"messageType",
"(",
")",
"!=",
"messageTypeCallReq",
"{",
"err",
":=",
"r",
".",
"handleNonCallReq",
"(",
"f",
")",
"\n",
"if",
"err",
"==",
"errUnknownID",
"{",
"if",
"err",
":=",
"r",
".",
"conn",
".",
"outbound",
".",
"forwardPeerFrame",
"(",
"f",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"r",
".",
"handleCallReq",
"(",
"newLazyCallReq",
"(",
"f",
")",
")",
"\n",
"}"
] |
// Relay is called for each frame that is read on the connection.
|
[
"Relay",
"is",
"called",
"for",
"each",
"frame",
"that",
"is",
"read",
"on",
"the",
"connection",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L223-L237
|
test
|
uber/tchannel-go
|
relay.go
|
Receive
|
func (r *Relayer) Receive(f *Frame, fType frameType) (sent bool, failureReason string) {
id := f.Header.ID
// If we receive a response frame, we expect to find that ID in our outbound.
// If we receive a request frame, we expect to find that ID in our inbound.
items := r.receiverItems(fType)
item, ok := items.Get(id)
if !ok {
r.logger.WithFields(
LogField{"id", id},
).Warn("Received a frame without a RelayItem.")
return false, _relayErrorNotFound
}
finished := finishesCall(f)
if item.tomb {
// Call timed out, ignore this frame. (We've already handled stats.)
// TODO: metrics for late-arriving frames.
return true, ""
}
// call res frames don't include the OK bit, so we can't wait until the last
// frame of a relayed RPC to determine if the call succeeded.
if fType == responseFrame {
// If we've gotten a response frame, we're the originating relayer and
// should handle stats.
if succeeded, failMsg := determinesCallSuccess(f); succeeded {
item.call.Succeeded()
} else if len(failMsg) > 0 {
item.call.Failed(failMsg)
}
}
select {
case r.conn.sendCh <- f:
default:
// Buffer is full, so drop this frame and cancel the call.
r.logger.WithFields(
LogField{"id", id},
).Warn("Dropping call due to slow connection.")
items := r.receiverItems(fType)
err := _relayErrorDestConnSlow
// If we're dealing with a response frame, then the client is slow.
if fType == responseFrame {
err = _relayErrorSourceConnSlow
}
r.failRelayItem(items, id, err)
return false, err
}
if finished {
r.finishRelayItem(items, id)
}
return true, ""
}
|
go
|
func (r *Relayer) Receive(f *Frame, fType frameType) (sent bool, failureReason string) {
id := f.Header.ID
// If we receive a response frame, we expect to find that ID in our outbound.
// If we receive a request frame, we expect to find that ID in our inbound.
items := r.receiverItems(fType)
item, ok := items.Get(id)
if !ok {
r.logger.WithFields(
LogField{"id", id},
).Warn("Received a frame without a RelayItem.")
return false, _relayErrorNotFound
}
finished := finishesCall(f)
if item.tomb {
// Call timed out, ignore this frame. (We've already handled stats.)
// TODO: metrics for late-arriving frames.
return true, ""
}
// call res frames don't include the OK bit, so we can't wait until the last
// frame of a relayed RPC to determine if the call succeeded.
if fType == responseFrame {
// If we've gotten a response frame, we're the originating relayer and
// should handle stats.
if succeeded, failMsg := determinesCallSuccess(f); succeeded {
item.call.Succeeded()
} else if len(failMsg) > 0 {
item.call.Failed(failMsg)
}
}
select {
case r.conn.sendCh <- f:
default:
// Buffer is full, so drop this frame and cancel the call.
r.logger.WithFields(
LogField{"id", id},
).Warn("Dropping call due to slow connection.")
items := r.receiverItems(fType)
err := _relayErrorDestConnSlow
// If we're dealing with a response frame, then the client is slow.
if fType == responseFrame {
err = _relayErrorSourceConnSlow
}
r.failRelayItem(items, id, err)
return false, err
}
if finished {
r.finishRelayItem(items, id)
}
return true, ""
}
|
[
"func",
"(",
"r",
"*",
"Relayer",
")",
"Receive",
"(",
"f",
"*",
"Frame",
",",
"fType",
"frameType",
")",
"(",
"sent",
"bool",
",",
"failureReason",
"string",
")",
"{",
"id",
":=",
"f",
".",
"Header",
".",
"ID",
"\n",
"items",
":=",
"r",
".",
"receiverItems",
"(",
"fType",
")",
"\n",
"item",
",",
"ok",
":=",
"items",
".",
"Get",
"(",
"id",
")",
"\n",
"if",
"!",
"ok",
"{",
"r",
".",
"logger",
".",
"WithFields",
"(",
"LogField",
"{",
"\"id\"",
",",
"id",
"}",
",",
")",
".",
"Warn",
"(",
"\"Received a frame without a RelayItem.\"",
")",
"\n",
"return",
"false",
",",
"_relayErrorNotFound",
"\n",
"}",
"\n",
"finished",
":=",
"finishesCall",
"(",
"f",
")",
"\n",
"if",
"item",
".",
"tomb",
"{",
"return",
"true",
",",
"\"\"",
"\n",
"}",
"\n",
"if",
"fType",
"==",
"responseFrame",
"{",
"if",
"succeeded",
",",
"failMsg",
":=",
"determinesCallSuccess",
"(",
"f",
")",
";",
"succeeded",
"{",
"item",
".",
"call",
".",
"Succeeded",
"(",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"failMsg",
")",
">",
"0",
"{",
"item",
".",
"call",
".",
"Failed",
"(",
"failMsg",
")",
"\n",
"}",
"\n",
"}",
"\n",
"select",
"{",
"case",
"r",
".",
"conn",
".",
"sendCh",
"<-",
"f",
":",
"default",
":",
"r",
".",
"logger",
".",
"WithFields",
"(",
"LogField",
"{",
"\"id\"",
",",
"id",
"}",
",",
")",
".",
"Warn",
"(",
"\"Dropping call due to slow connection.\"",
")",
"\n",
"items",
":=",
"r",
".",
"receiverItems",
"(",
"fType",
")",
"\n",
"err",
":=",
"_relayErrorDestConnSlow",
"\n",
"if",
"fType",
"==",
"responseFrame",
"{",
"err",
"=",
"_relayErrorSourceConnSlow",
"\n",
"}",
"\n",
"r",
".",
"failRelayItem",
"(",
"items",
",",
"id",
",",
"err",
")",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"finished",
"{",
"r",
".",
"finishRelayItem",
"(",
"items",
",",
"id",
")",
"\n",
"}",
"\n",
"return",
"true",
",",
"\"\"",
"\n",
"}"
] |
// Receive receives frames intended for this connection.
// It returns whether the frame was sent and a reason for failure if it failed.
|
[
"Receive",
"receives",
"frames",
"intended",
"for",
"this",
"connection",
".",
"It",
"returns",
"whether",
"the",
"frame",
"was",
"sent",
"and",
"a",
"reason",
"for",
"failure",
"if",
"it",
"failed",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L241-L299
|
test
|
uber/tchannel-go
|
relay.go
|
handleNonCallReq
|
func (r *Relayer) handleNonCallReq(f *Frame) error {
frameType := frameTypeFor(f)
finished := finishesCall(f)
// If we read a request frame, we need to use the outbound map to decide
// the destination. Otherwise, we use the inbound map.
items := r.outbound
if frameType == responseFrame {
items = r.inbound
}
item, ok := items.Get(f.Header.ID)
if !ok {
return errUnknownID
}
if item.tomb {
// Call timed out, ignore this frame. (We've already handled stats.)
// TODO: metrics for late-arriving frames.
return nil
}
originalID := f.Header.ID
f.Header.ID = item.remapID
sent, failure := item.destination.Receive(f, frameType)
if !sent {
r.failRelayItem(items, originalID, failure)
return nil
}
if finished {
r.finishRelayItem(items, originalID)
}
return nil
}
|
go
|
func (r *Relayer) handleNonCallReq(f *Frame) error {
frameType := frameTypeFor(f)
finished := finishesCall(f)
// If we read a request frame, we need to use the outbound map to decide
// the destination. Otherwise, we use the inbound map.
items := r.outbound
if frameType == responseFrame {
items = r.inbound
}
item, ok := items.Get(f.Header.ID)
if !ok {
return errUnknownID
}
if item.tomb {
// Call timed out, ignore this frame. (We've already handled stats.)
// TODO: metrics for late-arriving frames.
return nil
}
originalID := f.Header.ID
f.Header.ID = item.remapID
sent, failure := item.destination.Receive(f, frameType)
if !sent {
r.failRelayItem(items, originalID, failure)
return nil
}
if finished {
r.finishRelayItem(items, originalID)
}
return nil
}
|
[
"func",
"(",
"r",
"*",
"Relayer",
")",
"handleNonCallReq",
"(",
"f",
"*",
"Frame",
")",
"error",
"{",
"frameType",
":=",
"frameTypeFor",
"(",
"f",
")",
"\n",
"finished",
":=",
"finishesCall",
"(",
"f",
")",
"\n",
"items",
":=",
"r",
".",
"outbound",
"\n",
"if",
"frameType",
"==",
"responseFrame",
"{",
"items",
"=",
"r",
".",
"inbound",
"\n",
"}",
"\n",
"item",
",",
"ok",
":=",
"items",
".",
"Get",
"(",
"f",
".",
"Header",
".",
"ID",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errUnknownID",
"\n",
"}",
"\n",
"if",
"item",
".",
"tomb",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"originalID",
":=",
"f",
".",
"Header",
".",
"ID",
"\n",
"f",
".",
"Header",
".",
"ID",
"=",
"item",
".",
"remapID",
"\n",
"sent",
",",
"failure",
":=",
"item",
".",
"destination",
".",
"Receive",
"(",
"f",
",",
"frameType",
")",
"\n",
"if",
"!",
"sent",
"{",
"r",
".",
"failRelayItem",
"(",
"items",
",",
"originalID",
",",
"failure",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"finished",
"{",
"r",
".",
"finishRelayItem",
"(",
"items",
",",
"originalID",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Handle all frames except messageTypeCallReq.
|
[
"Handle",
"all",
"frames",
"except",
"messageTypeCallReq",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L439-L473
|
test
|
uber/tchannel-go
|
relay.go
|
addRelayItem
|
func (r *Relayer) addRelayItem(isOriginator bool, id, remapID uint32, destination *Relayer, ttl time.Duration, span Span, call RelayCall) relayItem {
item := relayItem{
call: call,
remapID: remapID,
destination: destination,
span: span,
}
items := r.inbound
if isOriginator {
items = r.outbound
}
item.timeout = r.timeouts.Get()
items.Add(id, item)
item.timeout.Start(ttl, items, id, isOriginator)
return item
}
|
go
|
func (r *Relayer) addRelayItem(isOriginator bool, id, remapID uint32, destination *Relayer, ttl time.Duration, span Span, call RelayCall) relayItem {
item := relayItem{
call: call,
remapID: remapID,
destination: destination,
span: span,
}
items := r.inbound
if isOriginator {
items = r.outbound
}
item.timeout = r.timeouts.Get()
items.Add(id, item)
item.timeout.Start(ttl, items, id, isOriginator)
return item
}
|
[
"func",
"(",
"r",
"*",
"Relayer",
")",
"addRelayItem",
"(",
"isOriginator",
"bool",
",",
"id",
",",
"remapID",
"uint32",
",",
"destination",
"*",
"Relayer",
",",
"ttl",
"time",
".",
"Duration",
",",
"span",
"Span",
",",
"call",
"RelayCall",
")",
"relayItem",
"{",
"item",
":=",
"relayItem",
"{",
"call",
":",
"call",
",",
"remapID",
":",
"remapID",
",",
"destination",
":",
"destination",
",",
"span",
":",
"span",
",",
"}",
"\n",
"items",
":=",
"r",
".",
"inbound",
"\n",
"if",
"isOriginator",
"{",
"items",
"=",
"r",
".",
"outbound",
"\n",
"}",
"\n",
"item",
".",
"timeout",
"=",
"r",
".",
"timeouts",
".",
"Get",
"(",
")",
"\n",
"items",
".",
"Add",
"(",
"id",
",",
"item",
")",
"\n",
"item",
".",
"timeout",
".",
"Start",
"(",
"ttl",
",",
"items",
",",
"id",
",",
"isOriginator",
")",
"\n",
"return",
"item",
"\n",
"}"
] |
// addRelayItem adds a relay item to either outbound or inbound.
|
[
"addRelayItem",
"adds",
"a",
"relay",
"item",
"to",
"either",
"outbound",
"or",
"inbound",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L476-L492
|
test
|
uber/tchannel-go
|
relay.go
|
failRelayItem
|
func (r *Relayer) failRelayItem(items *relayItems, id uint32, failure string) {
item, ok := items.Get(id)
if !ok {
items.logger.WithFields(LogField{"id", id}).Warn("Attempted to fail non-existent relay item.")
return
}
// The call could time-out right as we entomb it, which would cause spurious
// error logs, so ensure we can stop the timeout.
if !item.timeout.Stop() {
return
}
// Entomb it so that we don't get unknown exchange errors on further frames
// for this call.
item, ok = items.Entomb(id, _relayTombTTL)
if !ok {
return
}
if item.call != nil {
// If the client is too slow, then there's no point sending an error frame.
if failure != _relayErrorSourceConnSlow {
r.conn.SendSystemError(id, item.span, errFrameNotSent)
}
item.call.Failed(failure)
item.call.End()
}
r.decrementPending()
}
|
go
|
func (r *Relayer) failRelayItem(items *relayItems, id uint32, failure string) {
item, ok := items.Get(id)
if !ok {
items.logger.WithFields(LogField{"id", id}).Warn("Attempted to fail non-existent relay item.")
return
}
// The call could time-out right as we entomb it, which would cause spurious
// error logs, so ensure we can stop the timeout.
if !item.timeout.Stop() {
return
}
// Entomb it so that we don't get unknown exchange errors on further frames
// for this call.
item, ok = items.Entomb(id, _relayTombTTL)
if !ok {
return
}
if item.call != nil {
// If the client is too slow, then there's no point sending an error frame.
if failure != _relayErrorSourceConnSlow {
r.conn.SendSystemError(id, item.span, errFrameNotSent)
}
item.call.Failed(failure)
item.call.End()
}
r.decrementPending()
}
|
[
"func",
"(",
"r",
"*",
"Relayer",
")",
"failRelayItem",
"(",
"items",
"*",
"relayItems",
",",
"id",
"uint32",
",",
"failure",
"string",
")",
"{",
"item",
",",
"ok",
":=",
"items",
".",
"Get",
"(",
"id",
")",
"\n",
"if",
"!",
"ok",
"{",
"items",
".",
"logger",
".",
"WithFields",
"(",
"LogField",
"{",
"\"id\"",
",",
"id",
"}",
")",
".",
"Warn",
"(",
"\"Attempted to fail non-existent relay item.\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"!",
"item",
".",
"timeout",
".",
"Stop",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"item",
",",
"ok",
"=",
"items",
".",
"Entomb",
"(",
"id",
",",
"_relayTombTTL",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"if",
"item",
".",
"call",
"!=",
"nil",
"{",
"if",
"failure",
"!=",
"_relayErrorSourceConnSlow",
"{",
"r",
".",
"conn",
".",
"SendSystemError",
"(",
"id",
",",
"item",
".",
"span",
",",
"errFrameNotSent",
")",
"\n",
"}",
"\n",
"item",
".",
"call",
".",
"Failed",
"(",
"failure",
")",
"\n",
"item",
".",
"call",
".",
"End",
"(",
")",
"\n",
"}",
"\n",
"r",
".",
"decrementPending",
"(",
")",
"\n",
"}"
] |
// failRelayItem tombs the relay item so that future frames for this call are not
// forwarded. We keep the relay item tombed, rather than delete it to ensure that
// future frames do not cause error logs.
|
[
"failRelayItem",
"tombs",
"the",
"relay",
"item",
"so",
"that",
"future",
"frames",
"for",
"this",
"call",
"are",
"not",
"forwarded",
".",
"We",
"keep",
"the",
"relay",
"item",
"tombed",
"rather",
"than",
"delete",
"it",
"to",
"ensure",
"that",
"future",
"frames",
"do",
"not",
"cause",
"error",
"logs",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay.go#L511-L540
|
test
|
uber/tchannel-go
|
thrift/struct.go
|
WriteStruct
|
func WriteStruct(writer io.Writer, s thrift.TStruct) error {
wp := getProtocolWriter(writer)
err := s.Write(wp.protocol)
thriftProtocolPool.Put(wp)
return err
}
|
go
|
func WriteStruct(writer io.Writer, s thrift.TStruct) error {
wp := getProtocolWriter(writer)
err := s.Write(wp.protocol)
thriftProtocolPool.Put(wp)
return err
}
|
[
"func",
"WriteStruct",
"(",
"writer",
"io",
".",
"Writer",
",",
"s",
"thrift",
".",
"TStruct",
")",
"error",
"{",
"wp",
":=",
"getProtocolWriter",
"(",
"writer",
")",
"\n",
"err",
":=",
"s",
".",
"Write",
"(",
"wp",
".",
"protocol",
")",
"\n",
"thriftProtocolPool",
".",
"Put",
"(",
"wp",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// WriteStruct writes the given Thrift struct to a writer. It pools TProtocols.
|
[
"WriteStruct",
"writes",
"the",
"given",
"Thrift",
"struct",
"to",
"a",
"writer",
".",
"It",
"pools",
"TProtocols",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/struct.go#L30-L35
|
test
|
uber/tchannel-go
|
thrift/struct.go
|
ReadStruct
|
func ReadStruct(reader io.Reader, s thrift.TStruct) error {
wp := getProtocolReader(reader)
err := s.Read(wp.protocol)
thriftProtocolPool.Put(wp)
return err
}
|
go
|
func ReadStruct(reader io.Reader, s thrift.TStruct) error {
wp := getProtocolReader(reader)
err := s.Read(wp.protocol)
thriftProtocolPool.Put(wp)
return err
}
|
[
"func",
"ReadStruct",
"(",
"reader",
"io",
".",
"Reader",
",",
"s",
"thrift",
".",
"TStruct",
")",
"error",
"{",
"wp",
":=",
"getProtocolReader",
"(",
"reader",
")",
"\n",
"err",
":=",
"s",
".",
"Read",
"(",
"wp",
".",
"protocol",
")",
"\n",
"thriftProtocolPool",
".",
"Put",
"(",
"wp",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// ReadStruct reads the given Thrift struct. It pools TProtocols.
|
[
"ReadStruct",
"reads",
"the",
"given",
"Thrift",
"struct",
".",
"It",
"pools",
"TProtocols",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/struct.go#L38-L43
|
test
|
uber/tchannel-go
|
internal/argreader/empty.go
|
EnsureEmpty
|
func EnsureEmpty(r io.Reader, stage string) error {
buf := _bufPool.Get().(*[]byte)
defer _bufPool.Put(buf)
n, err := r.Read(*buf)
if n > 0 {
return fmt.Errorf("found unexpected bytes after %s, found (upto 128 bytes): %x", stage, (*buf)[:n])
}
if err == io.EOF {
return nil
}
return err
}
|
go
|
func EnsureEmpty(r io.Reader, stage string) error {
buf := _bufPool.Get().(*[]byte)
defer _bufPool.Put(buf)
n, err := r.Read(*buf)
if n > 0 {
return fmt.Errorf("found unexpected bytes after %s, found (upto 128 bytes): %x", stage, (*buf)[:n])
}
if err == io.EOF {
return nil
}
return err
}
|
[
"func",
"EnsureEmpty",
"(",
"r",
"io",
".",
"Reader",
",",
"stage",
"string",
")",
"error",
"{",
"buf",
":=",
"_bufPool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"[",
"]",
"byte",
")",
"\n",
"defer",
"_bufPool",
".",
"Put",
"(",
"buf",
")",
"\n",
"n",
",",
"err",
":=",
"r",
".",
"Read",
"(",
"*",
"buf",
")",
"\n",
"if",
"n",
">",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"found unexpected bytes after %s, found (upto 128 bytes): %x\"",
",",
"stage",
",",
"(",
"*",
"buf",
")",
"[",
":",
"n",
"]",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// EnsureEmpty ensures that the specified reader is empty. If the reader is
// not empty, it returns an error with the specified stage in the message.
|
[
"EnsureEmpty",
"ensures",
"that",
"the",
"specified",
"reader",
"is",
"empty",
".",
"If",
"the",
"reader",
"is",
"not",
"empty",
"it",
"returns",
"an",
"error",
"with",
"the",
"specified",
"stage",
"in",
"the",
"message",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/internal/argreader/empty.go#L38-L50
|
test
|
uber/tchannel-go
|
benchmark/internal_server.go
|
NewServer
|
func NewServer(optFns ...Option) Server {
opts := getOptions(optFns)
if opts.external {
return newExternalServer(opts)
}
ch, err := tchannel.NewChannel(opts.svcName, &tchannel.ChannelOptions{
Logger: tchannel.NewLevelLogger(tchannel.NewLogger(os.Stderr), tchannel.LogLevelWarn),
})
if err != nil {
panic("failed to create channel: " + err.Error())
}
if err := ch.ListenAndServe("127.0.0.1:0"); err != nil {
panic("failed to listen on port 0: " + err.Error())
}
s := &internalServer{
ch: ch,
opts: opts,
}
tServer := thrift.NewServer(ch)
tServer.Register(gen.NewTChanSecondServiceServer(handler{calls: &s.thriftCalls}))
ch.Register(raw.Wrap(rawHandler{calls: &s.rawCalls}), "echo")
if len(opts.advertiseHosts) > 0 {
if err := s.Advertise(opts.advertiseHosts); err != nil {
panic("failed to advertise: " + err.Error())
}
}
return s
}
|
go
|
func NewServer(optFns ...Option) Server {
opts := getOptions(optFns)
if opts.external {
return newExternalServer(opts)
}
ch, err := tchannel.NewChannel(opts.svcName, &tchannel.ChannelOptions{
Logger: tchannel.NewLevelLogger(tchannel.NewLogger(os.Stderr), tchannel.LogLevelWarn),
})
if err != nil {
panic("failed to create channel: " + err.Error())
}
if err := ch.ListenAndServe("127.0.0.1:0"); err != nil {
panic("failed to listen on port 0: " + err.Error())
}
s := &internalServer{
ch: ch,
opts: opts,
}
tServer := thrift.NewServer(ch)
tServer.Register(gen.NewTChanSecondServiceServer(handler{calls: &s.thriftCalls}))
ch.Register(raw.Wrap(rawHandler{calls: &s.rawCalls}), "echo")
if len(opts.advertiseHosts) > 0 {
if err := s.Advertise(opts.advertiseHosts); err != nil {
panic("failed to advertise: " + err.Error())
}
}
return s
}
|
[
"func",
"NewServer",
"(",
"optFns",
"...",
"Option",
")",
"Server",
"{",
"opts",
":=",
"getOptions",
"(",
"optFns",
")",
"\n",
"if",
"opts",
".",
"external",
"{",
"return",
"newExternalServer",
"(",
"opts",
")",
"\n",
"}",
"\n",
"ch",
",",
"err",
":=",
"tchannel",
".",
"NewChannel",
"(",
"opts",
".",
"svcName",
",",
"&",
"tchannel",
".",
"ChannelOptions",
"{",
"Logger",
":",
"tchannel",
".",
"NewLevelLogger",
"(",
"tchannel",
".",
"NewLogger",
"(",
"os",
".",
"Stderr",
")",
",",
"tchannel",
".",
"LogLevelWarn",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"failed to create channel: \"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ch",
".",
"ListenAndServe",
"(",
"\"127.0.0.1:0\"",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"failed to listen on port 0: \"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"s",
":=",
"&",
"internalServer",
"{",
"ch",
":",
"ch",
",",
"opts",
":",
"opts",
",",
"}",
"\n",
"tServer",
":=",
"thrift",
".",
"NewServer",
"(",
"ch",
")",
"\n",
"tServer",
".",
"Register",
"(",
"gen",
".",
"NewTChanSecondServiceServer",
"(",
"handler",
"{",
"calls",
":",
"&",
"s",
".",
"thriftCalls",
"}",
")",
")",
"\n",
"ch",
".",
"Register",
"(",
"raw",
".",
"Wrap",
"(",
"rawHandler",
"{",
"calls",
":",
"&",
"s",
".",
"rawCalls",
"}",
")",
",",
"\"echo\"",
")",
"\n",
"if",
"len",
"(",
"opts",
".",
"advertiseHosts",
")",
">",
"0",
"{",
"if",
"err",
":=",
"s",
".",
"Advertise",
"(",
"opts",
".",
"advertiseHosts",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"failed to advertise: \"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// NewServer returns a new Server that can recieve Thrift calls or raw calls.
|
[
"NewServer",
"returns",
"a",
"new",
"Server",
"that",
"can",
"recieve",
"Thrift",
"calls",
"or",
"raw",
"calls",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/benchmark/internal_server.go#L46-L78
|
test
|
uber/tchannel-go
|
benchmark/internal_server.go
|
Advertise
|
func (s *internalServer) Advertise(hyperbahnHosts []string) error {
config := hyperbahn.Configuration{InitialNodes: hyperbahnHosts}
hc, err := hyperbahn.NewClient(s.ch, config, nil)
if err != nil {
panic("failed to setup Hyperbahn client: " + err.Error())
}
return hc.Advertise()
}
|
go
|
func (s *internalServer) Advertise(hyperbahnHosts []string) error {
config := hyperbahn.Configuration{InitialNodes: hyperbahnHosts}
hc, err := hyperbahn.NewClient(s.ch, config, nil)
if err != nil {
panic("failed to setup Hyperbahn client: " + err.Error())
}
return hc.Advertise()
}
|
[
"func",
"(",
"s",
"*",
"internalServer",
")",
"Advertise",
"(",
"hyperbahnHosts",
"[",
"]",
"string",
")",
"error",
"{",
"config",
":=",
"hyperbahn",
".",
"Configuration",
"{",
"InitialNodes",
":",
"hyperbahnHosts",
"}",
"\n",
"hc",
",",
"err",
":=",
"hyperbahn",
".",
"NewClient",
"(",
"s",
".",
"ch",
",",
"config",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"failed to setup Hyperbahn client: \"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"hc",
".",
"Advertise",
"(",
")",
"\n",
"}"
] |
// Advertise advertises with Hyperbahn.
|
[
"Advertise",
"advertises",
"with",
"Hyperbahn",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/benchmark/internal_server.go#L86-L93
|
test
|
uber/tchannel-go
|
inbound.go
|
handleCallReqContinue
|
func (c *Connection) handleCallReqContinue(frame *Frame) bool {
if err := c.inbound.forwardPeerFrame(frame); err != nil {
// If forward fails, it's due to a timeout. We can free this frame.
return true
}
return false
}
|
go
|
func (c *Connection) handleCallReqContinue(frame *Frame) bool {
if err := c.inbound.forwardPeerFrame(frame); err != nil {
// If forward fails, it's due to a timeout. We can free this frame.
return true
}
return false
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"handleCallReqContinue",
"(",
"frame",
"*",
"Frame",
")",
"bool",
"{",
"if",
"err",
":=",
"c",
".",
"inbound",
".",
"forwardPeerFrame",
"(",
"frame",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// handleCallReqContinue handles the continuation of a call request, forwarding
// it to the request channel for that request, where it can be pulled during
// defragmentation
|
[
"handleCallReqContinue",
"handles",
"the",
"continuation",
"of",
"a",
"call",
"request",
"forwarding",
"it",
"to",
"the",
"request",
"channel",
"for",
"that",
"request",
"where",
"it",
"can",
"be",
"pulled",
"during",
"defragmentation"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/inbound.go#L132-L138
|
test
|
uber/tchannel-go
|
inbound.go
|
dispatchInbound
|
func (c *Connection) dispatchInbound(_ uint32, _ uint32, call *InboundCall, frame *Frame) {
if call.log.Enabled(LogLevelDebug) {
call.log.Debugf("Received incoming call for %s from %s", call.ServiceName(), c.remotePeerInfo)
}
if err := call.readMethod(); err != nil {
call.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
ErrField(err),
).Error("Couldn't read method.")
c.opts.FramePool.Release(frame)
return
}
call.commonStatsTags["endpoint"] = call.methodString
call.statsReporter.IncCounter("inbound.calls.recvd", call.commonStatsTags, 1)
if span := call.response.span; span != nil {
span.SetOperationName(call.methodString)
}
// TODO(prashant): This is an expensive way to check for cancellation. Use a heap for timeouts.
go func() {
select {
case <-call.mex.ctx.Done():
// checking if message exchange timedout or was cancelled
// only two possible errors at this step:
// context.DeadlineExceeded
// context.Canceled
if call.mex.ctx.Err() != nil {
call.mex.inboundExpired()
}
case <-call.mex.errCh.c:
if c.log.Enabled(LogLevelDebug) {
call.log.Debugf("Wait for timeout/cancellation interrupted by error: %v", call.mex.errCh.err)
}
// when an exchange errors out, mark the exchange as expired
// and call cancel so the server handler's context is canceled
// TODO: move the cancel to the parent context at connnection level
call.response.cancel()
call.mex.inboundExpired()
}
}()
c.handler.Handle(call.mex.ctx, call)
}
|
go
|
func (c *Connection) dispatchInbound(_ uint32, _ uint32, call *InboundCall, frame *Frame) {
if call.log.Enabled(LogLevelDebug) {
call.log.Debugf("Received incoming call for %s from %s", call.ServiceName(), c.remotePeerInfo)
}
if err := call.readMethod(); err != nil {
call.log.WithFields(
LogField{"remotePeer", c.remotePeerInfo},
ErrField(err),
).Error("Couldn't read method.")
c.opts.FramePool.Release(frame)
return
}
call.commonStatsTags["endpoint"] = call.methodString
call.statsReporter.IncCounter("inbound.calls.recvd", call.commonStatsTags, 1)
if span := call.response.span; span != nil {
span.SetOperationName(call.methodString)
}
// TODO(prashant): This is an expensive way to check for cancellation. Use a heap for timeouts.
go func() {
select {
case <-call.mex.ctx.Done():
// checking if message exchange timedout or was cancelled
// only two possible errors at this step:
// context.DeadlineExceeded
// context.Canceled
if call.mex.ctx.Err() != nil {
call.mex.inboundExpired()
}
case <-call.mex.errCh.c:
if c.log.Enabled(LogLevelDebug) {
call.log.Debugf("Wait for timeout/cancellation interrupted by error: %v", call.mex.errCh.err)
}
// when an exchange errors out, mark the exchange as expired
// and call cancel so the server handler's context is canceled
// TODO: move the cancel to the parent context at connnection level
call.response.cancel()
call.mex.inboundExpired()
}
}()
c.handler.Handle(call.mex.ctx, call)
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"dispatchInbound",
"(",
"_",
"uint32",
",",
"_",
"uint32",
",",
"call",
"*",
"InboundCall",
",",
"frame",
"*",
"Frame",
")",
"{",
"if",
"call",
".",
"log",
".",
"Enabled",
"(",
"LogLevelDebug",
")",
"{",
"call",
".",
"log",
".",
"Debugf",
"(",
"\"Received incoming call for %s from %s\"",
",",
"call",
".",
"ServiceName",
"(",
")",
",",
"c",
".",
"remotePeerInfo",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"call",
".",
"readMethod",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"call",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"remotePeer\"",
",",
"c",
".",
"remotePeerInfo",
"}",
",",
"ErrField",
"(",
"err",
")",
",",
")",
".",
"Error",
"(",
"\"Couldn't read method.\"",
")",
"\n",
"c",
".",
"opts",
".",
"FramePool",
".",
"Release",
"(",
"frame",
")",
"\n",
"return",
"\n",
"}",
"\n",
"call",
".",
"commonStatsTags",
"[",
"\"endpoint\"",
"]",
"=",
"call",
".",
"methodString",
"\n",
"call",
".",
"statsReporter",
".",
"IncCounter",
"(",
"\"inbound.calls.recvd\"",
",",
"call",
".",
"commonStatsTags",
",",
"1",
")",
"\n",
"if",
"span",
":=",
"call",
".",
"response",
".",
"span",
";",
"span",
"!=",
"nil",
"{",
"span",
".",
"SetOperationName",
"(",
"call",
".",
"methodString",
")",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"select",
"{",
"case",
"<-",
"call",
".",
"mex",
".",
"ctx",
".",
"Done",
"(",
")",
":",
"if",
"call",
".",
"mex",
".",
"ctx",
".",
"Err",
"(",
")",
"!=",
"nil",
"{",
"call",
".",
"mex",
".",
"inboundExpired",
"(",
")",
"\n",
"}",
"\n",
"case",
"<-",
"call",
".",
"mex",
".",
"errCh",
".",
"c",
":",
"if",
"c",
".",
"log",
".",
"Enabled",
"(",
"LogLevelDebug",
")",
"{",
"call",
".",
"log",
".",
"Debugf",
"(",
"\"Wait for timeout/cancellation interrupted by error: %v\"",
",",
"call",
".",
"mex",
".",
"errCh",
".",
"err",
")",
"\n",
"}",
"\n",
"call",
".",
"response",
".",
"cancel",
"(",
")",
"\n",
"call",
".",
"mex",
".",
"inboundExpired",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"c",
".",
"handler",
".",
"Handle",
"(",
"call",
".",
"mex",
".",
"ctx",
",",
"call",
")",
"\n",
"}"
] |
// dispatchInbound ispatches an inbound call to the appropriate handler
|
[
"dispatchInbound",
"ispatches",
"an",
"inbound",
"call",
"to",
"the",
"appropriate",
"handler"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/inbound.go#L151-L195
|
test
|
uber/tchannel-go
|
inbound.go
|
CallOptions
|
func (call *InboundCall) CallOptions() *CallOptions {
return &CallOptions{
callerName: call.CallerName(),
Format: call.Format(),
ShardKey: call.ShardKey(),
RoutingDelegate: call.RoutingDelegate(),
RoutingKey: call.RoutingKey(),
}
}
|
go
|
func (call *InboundCall) CallOptions() *CallOptions {
return &CallOptions{
callerName: call.CallerName(),
Format: call.Format(),
ShardKey: call.ShardKey(),
RoutingDelegate: call.RoutingDelegate(),
RoutingKey: call.RoutingKey(),
}
}
|
[
"func",
"(",
"call",
"*",
"InboundCall",
")",
"CallOptions",
"(",
")",
"*",
"CallOptions",
"{",
"return",
"&",
"CallOptions",
"{",
"callerName",
":",
"call",
".",
"CallerName",
"(",
")",
",",
"Format",
":",
"call",
".",
"Format",
"(",
")",
",",
"ShardKey",
":",
"call",
".",
"ShardKey",
"(",
")",
",",
"RoutingDelegate",
":",
"call",
".",
"RoutingDelegate",
"(",
")",
",",
"RoutingKey",
":",
"call",
".",
"RoutingKey",
"(",
")",
",",
"}",
"\n",
"}"
] |
// CallOptions returns a CallOptions struct suitable for forwarding a request.
|
[
"CallOptions",
"returns",
"a",
"CallOptions",
"struct",
"suitable",
"for",
"forwarding",
"a",
"request",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/inbound.go#L262-L270
|
test
|
uber/tchannel-go
|
inbound.go
|
Response
|
func (call *InboundCall) Response() *InboundCallResponse {
if call.err != nil {
// While reading Thrift, we cannot distinguish between malformed Thrift and other errors,
// and so we may try to respond with a bad request. We should ensure that the response
// is marked as failed if the request has failed so that we don't try to shutdown the exchange
// a second time.
call.response.err = call.err
}
return call.response
}
|
go
|
func (call *InboundCall) Response() *InboundCallResponse {
if call.err != nil {
// While reading Thrift, we cannot distinguish between malformed Thrift and other errors,
// and so we may try to respond with a bad request. We should ensure that the response
// is marked as failed if the request has failed so that we don't try to shutdown the exchange
// a second time.
call.response.err = call.err
}
return call.response
}
|
[
"func",
"(",
"call",
"*",
"InboundCall",
")",
"Response",
"(",
")",
"*",
"InboundCallResponse",
"{",
"if",
"call",
".",
"err",
"!=",
"nil",
"{",
"call",
".",
"response",
".",
"err",
"=",
"call",
".",
"err",
"\n",
"}",
"\n",
"return",
"call",
".",
"response",
"\n",
"}"
] |
// Response provides access to the InboundCallResponse object which can be used
// to write back to the calling peer
|
[
"Response",
"provides",
"access",
"to",
"the",
"InboundCallResponse",
"object",
"which",
"can",
"be",
"used",
"to",
"write",
"back",
"to",
"the",
"calling",
"peer"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/inbound.go#L298-L307
|
test
|
uber/tchannel-go
|
inbound.go
|
SendSystemError
|
func (response *InboundCallResponse) SendSystemError(err error) error {
if response.err != nil {
return response.err
}
// Fail all future attempts to read fragments
response.state = reqResWriterComplete
response.systemError = true
response.doneSending()
response.call.releasePreviousFragment()
span := CurrentSpan(response.mex.ctx)
return response.conn.SendSystemError(response.mex.msgID, *span, err)
}
|
go
|
func (response *InboundCallResponse) SendSystemError(err error) error {
if response.err != nil {
return response.err
}
// Fail all future attempts to read fragments
response.state = reqResWriterComplete
response.systemError = true
response.doneSending()
response.call.releasePreviousFragment()
span := CurrentSpan(response.mex.ctx)
return response.conn.SendSystemError(response.mex.msgID, *span, err)
}
|
[
"func",
"(",
"response",
"*",
"InboundCallResponse",
")",
"SendSystemError",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"response",
".",
"err",
"!=",
"nil",
"{",
"return",
"response",
".",
"err",
"\n",
"}",
"\n",
"response",
".",
"state",
"=",
"reqResWriterComplete",
"\n",
"response",
".",
"systemError",
"=",
"true",
"\n",
"response",
".",
"doneSending",
"(",
")",
"\n",
"response",
".",
"call",
".",
"releasePreviousFragment",
"(",
")",
"\n",
"span",
":=",
"CurrentSpan",
"(",
"response",
".",
"mex",
".",
"ctx",
")",
"\n",
"return",
"response",
".",
"conn",
".",
"SendSystemError",
"(",
"response",
".",
"mex",
".",
"msgID",
",",
"*",
"span",
",",
"err",
")",
"\n",
"}"
] |
// SendSystemError returns a system error response to the peer. The call is considered
// complete after this method is called, and no further data can be written.
|
[
"SendSystemError",
"returns",
"a",
"system",
"error",
"response",
"to",
"the",
"peer",
".",
"The",
"call",
"is",
"considered",
"complete",
"after",
"this",
"method",
"is",
"called",
"and",
"no",
"further",
"data",
"can",
"be",
"written",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/inbound.go#L330-L343
|
test
|
uber/tchannel-go
|
inbound.go
|
SetApplicationError
|
func (response *InboundCallResponse) SetApplicationError() error {
if response.state > reqResWriterPreArg2 {
return response.failed(errReqResWriterStateMismatch{
state: response.state,
expectedState: reqResWriterPreArg2,
})
}
response.applicationError = true
return nil
}
|
go
|
func (response *InboundCallResponse) SetApplicationError() error {
if response.state > reqResWriterPreArg2 {
return response.failed(errReqResWriterStateMismatch{
state: response.state,
expectedState: reqResWriterPreArg2,
})
}
response.applicationError = true
return nil
}
|
[
"func",
"(",
"response",
"*",
"InboundCallResponse",
")",
"SetApplicationError",
"(",
")",
"error",
"{",
"if",
"response",
".",
"state",
">",
"reqResWriterPreArg2",
"{",
"return",
"response",
".",
"failed",
"(",
"errReqResWriterStateMismatch",
"{",
"state",
":",
"response",
".",
"state",
",",
"expectedState",
":",
"reqResWriterPreArg2",
",",
"}",
")",
"\n",
"}",
"\n",
"response",
".",
"applicationError",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] |
// SetApplicationError marks the response as being an application error. This method can
// only be called before any arguments have been sent to the calling peer.
|
[
"SetApplicationError",
"marks",
"the",
"response",
"as",
"being",
"an",
"application",
"error",
".",
"This",
"method",
"can",
"only",
"be",
"called",
"before",
"any",
"arguments",
"have",
"been",
"sent",
"to",
"the",
"calling",
"peer",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/inbound.go#L347-L356
|
test
|
uber/tchannel-go
|
inbound.go
|
Arg2Writer
|
func (response *InboundCallResponse) Arg2Writer() (ArgWriter, error) {
if err := NewArgWriter(response.arg1Writer()).Write(nil); err != nil {
return nil, err
}
return response.arg2Writer()
}
|
go
|
func (response *InboundCallResponse) Arg2Writer() (ArgWriter, error) {
if err := NewArgWriter(response.arg1Writer()).Write(nil); err != nil {
return nil, err
}
return response.arg2Writer()
}
|
[
"func",
"(",
"response",
"*",
"InboundCallResponse",
")",
"Arg2Writer",
"(",
")",
"(",
"ArgWriter",
",",
"error",
")",
"{",
"if",
"err",
":=",
"NewArgWriter",
"(",
"response",
".",
"arg1Writer",
"(",
")",
")",
".",
"Write",
"(",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"response",
".",
"arg2Writer",
"(",
")",
"\n",
"}"
] |
// Arg2Writer returns a WriteCloser that can be used to write the second argument.
// The returned writer must be closed once the write is complete.
|
[
"Arg2Writer",
"returns",
"a",
"WriteCloser",
"that",
"can",
"be",
"used",
"to",
"write",
"the",
"second",
"argument",
".",
"The",
"returned",
"writer",
"must",
"be",
"closed",
"once",
"the",
"write",
"is",
"complete",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/inbound.go#L367-L372
|
test
|
uber/tchannel-go
|
inbound.go
|
doneSending
|
func (response *InboundCallResponse) doneSending() {
// TODO(prashant): Move this to when the message is actually being sent.
now := response.timeNow()
if span := response.span; span != nil {
if response.applicationError || response.systemError {
ext.Error.Set(span, true)
}
span.FinishWithOptions(opentracing.FinishOptions{FinishTime: now})
}
latency := now.Sub(response.calledAt)
response.statsReporter.RecordTimer("inbound.calls.latency", response.commonStatsTags, latency)
if response.systemError {
// TODO(prashant): Report the error code type as per metrics doc and enable.
// response.statsReporter.IncCounter("inbound.calls.system-errors", response.commonStatsTags, 1)
} else if response.applicationError {
response.statsReporter.IncCounter("inbound.calls.app-errors", response.commonStatsTags, 1)
} else {
response.statsReporter.IncCounter("inbound.calls.success", response.commonStatsTags, 1)
}
// Cancel the context since the response is complete.
response.cancel()
// The message exchange is still open if there are no errors, call shutdown.
if response.err == nil {
response.mex.shutdown()
}
}
|
go
|
func (response *InboundCallResponse) doneSending() {
// TODO(prashant): Move this to when the message is actually being sent.
now := response.timeNow()
if span := response.span; span != nil {
if response.applicationError || response.systemError {
ext.Error.Set(span, true)
}
span.FinishWithOptions(opentracing.FinishOptions{FinishTime: now})
}
latency := now.Sub(response.calledAt)
response.statsReporter.RecordTimer("inbound.calls.latency", response.commonStatsTags, latency)
if response.systemError {
// TODO(prashant): Report the error code type as per metrics doc and enable.
// response.statsReporter.IncCounter("inbound.calls.system-errors", response.commonStatsTags, 1)
} else if response.applicationError {
response.statsReporter.IncCounter("inbound.calls.app-errors", response.commonStatsTags, 1)
} else {
response.statsReporter.IncCounter("inbound.calls.success", response.commonStatsTags, 1)
}
// Cancel the context since the response is complete.
response.cancel()
// The message exchange is still open if there are no errors, call shutdown.
if response.err == nil {
response.mex.shutdown()
}
}
|
[
"func",
"(",
"response",
"*",
"InboundCallResponse",
")",
"doneSending",
"(",
")",
"{",
"now",
":=",
"response",
".",
"timeNow",
"(",
")",
"\n",
"if",
"span",
":=",
"response",
".",
"span",
";",
"span",
"!=",
"nil",
"{",
"if",
"response",
".",
"applicationError",
"||",
"response",
".",
"systemError",
"{",
"ext",
".",
"Error",
".",
"Set",
"(",
"span",
",",
"true",
")",
"\n",
"}",
"\n",
"span",
".",
"FinishWithOptions",
"(",
"opentracing",
".",
"FinishOptions",
"{",
"FinishTime",
":",
"now",
"}",
")",
"\n",
"}",
"\n",
"latency",
":=",
"now",
".",
"Sub",
"(",
"response",
".",
"calledAt",
")",
"\n",
"response",
".",
"statsReporter",
".",
"RecordTimer",
"(",
"\"inbound.calls.latency\"",
",",
"response",
".",
"commonStatsTags",
",",
"latency",
")",
"\n",
"if",
"response",
".",
"systemError",
"{",
"}",
"else",
"if",
"response",
".",
"applicationError",
"{",
"response",
".",
"statsReporter",
".",
"IncCounter",
"(",
"\"inbound.calls.app-errors\"",
",",
"response",
".",
"commonStatsTags",
",",
"1",
")",
"\n",
"}",
"else",
"{",
"response",
".",
"statsReporter",
".",
"IncCounter",
"(",
"\"inbound.calls.success\"",
",",
"response",
".",
"commonStatsTags",
",",
"1",
")",
"\n",
"}",
"\n",
"response",
".",
"cancel",
"(",
")",
"\n",
"if",
"response",
".",
"err",
"==",
"nil",
"{",
"response",
".",
"mex",
".",
"shutdown",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// doneSending shuts down the message exchange for this call.
// For incoming calls, the last message is sending the call response.
|
[
"doneSending",
"shuts",
"down",
"the",
"message",
"exchange",
"for",
"this",
"call",
".",
"For",
"incoming",
"calls",
"the",
"last",
"message",
"is",
"sending",
"the",
"call",
"response",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/inbound.go#L382-L412
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/typestate.go
|
newState
|
func newState(v *parser.Thrift, all map[string]parseState) *State {
typedefs := make(map[string]*parser.Type)
for k, v := range v.Typedefs {
typedefs[k] = v.Type
}
// Enums are typedefs to an int64.
i64Type := &parser.Type{Name: "i64"}
for k := range v.Enums {
typedefs[k] = i64Type
}
return &State{typedefs, nil, all}
}
|
go
|
func newState(v *parser.Thrift, all map[string]parseState) *State {
typedefs := make(map[string]*parser.Type)
for k, v := range v.Typedefs {
typedefs[k] = v.Type
}
// Enums are typedefs to an int64.
i64Type := &parser.Type{Name: "i64"}
for k := range v.Enums {
typedefs[k] = i64Type
}
return &State{typedefs, nil, all}
}
|
[
"func",
"newState",
"(",
"v",
"*",
"parser",
".",
"Thrift",
",",
"all",
"map",
"[",
"string",
"]",
"parseState",
")",
"*",
"State",
"{",
"typedefs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"parser",
".",
"Type",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"v",
".",
"Typedefs",
"{",
"typedefs",
"[",
"k",
"]",
"=",
"v",
".",
"Type",
"\n",
"}",
"\n",
"i64Type",
":=",
"&",
"parser",
".",
"Type",
"{",
"Name",
":",
"\"i64\"",
"}",
"\n",
"for",
"k",
":=",
"range",
"v",
".",
"Enums",
"{",
"typedefs",
"[",
"k",
"]",
"=",
"i64Type",
"\n",
"}",
"\n",
"return",
"&",
"State",
"{",
"typedefs",
",",
"nil",
",",
"all",
"}",
"\n",
"}"
] |
// newState parses the type information for a parsed Thrift file and returns the state.
|
[
"newState",
"parses",
"the",
"type",
"information",
"for",
"a",
"parsed",
"Thrift",
"file",
"and",
"returns",
"the",
"state",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/typestate.go#L42-L55
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/typestate.go
|
rootType
|
func (s *State) rootType(thriftType *parser.Type) *parser.Type {
if state, newType, include := s.checkInclude(thriftType); include != nil {
return state.rootType(newType)
}
if v, ok := s.typedefs[thriftType.Name]; ok {
return s.rootType(v)
}
return thriftType
}
|
go
|
func (s *State) rootType(thriftType *parser.Type) *parser.Type {
if state, newType, include := s.checkInclude(thriftType); include != nil {
return state.rootType(newType)
}
if v, ok := s.typedefs[thriftType.Name]; ok {
return s.rootType(v)
}
return thriftType
}
|
[
"func",
"(",
"s",
"*",
"State",
")",
"rootType",
"(",
"thriftType",
"*",
"parser",
".",
"Type",
")",
"*",
"parser",
".",
"Type",
"{",
"if",
"state",
",",
"newType",
",",
"include",
":=",
"s",
".",
"checkInclude",
"(",
"thriftType",
")",
";",
"include",
"!=",
"nil",
"{",
"return",
"state",
".",
"rootType",
"(",
"newType",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"s",
".",
"typedefs",
"[",
"thriftType",
".",
"Name",
"]",
";",
"ok",
"{",
"return",
"s",
".",
"rootType",
"(",
"v",
")",
"\n",
"}",
"\n",
"return",
"thriftType",
"\n",
"}"
] |
// rootType recurses through typedefs and returns the underlying type.
|
[
"rootType",
"recurses",
"through",
"typedefs",
"and",
"returns",
"the",
"underlying",
"type",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/typestate.go#L69-L78
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/typestate.go
|
checkInclude
|
func (s *State) checkInclude(thriftType *parser.Type) (*State, *parser.Type, *Include) {
parts := strings.SplitN(thriftType.Name, ".", 2)
if len(parts) < 2 {
return nil, nil, nil
}
newType := *thriftType
newType.Name = parts[1]
include := s.includes[parts[0]]
state := s.all[include.file]
return state.global, &newType, include
}
|
go
|
func (s *State) checkInclude(thriftType *parser.Type) (*State, *parser.Type, *Include) {
parts := strings.SplitN(thriftType.Name, ".", 2)
if len(parts) < 2 {
return nil, nil, nil
}
newType := *thriftType
newType.Name = parts[1]
include := s.includes[parts[0]]
state := s.all[include.file]
return state.global, &newType, include
}
|
[
"func",
"(",
"s",
"*",
"State",
")",
"checkInclude",
"(",
"thriftType",
"*",
"parser",
".",
"Type",
")",
"(",
"*",
"State",
",",
"*",
"parser",
".",
"Type",
",",
"*",
"Include",
")",
"{",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"thriftType",
".",
"Name",
",",
"\".\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"<",
"2",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"newType",
":=",
"*",
"thriftType",
"\n",
"newType",
".",
"Name",
"=",
"parts",
"[",
"1",
"]",
"\n",
"include",
":=",
"s",
".",
"includes",
"[",
"parts",
"[",
"0",
"]",
"]",
"\n",
"state",
":=",
"s",
".",
"all",
"[",
"include",
".",
"file",
"]",
"\n",
"return",
"state",
".",
"global",
",",
"&",
"newType",
",",
"include",
"\n",
"}"
] |
// checkInclude will check if the type is an included type, and if so, return the
// state and type from the state for that file.
|
[
"checkInclude",
"will",
"check",
"if",
"the",
"type",
"is",
"an",
"included",
"type",
"and",
"if",
"so",
"return",
"the",
"state",
"and",
"type",
"from",
"the",
"state",
"for",
"that",
"file",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/typestate.go#L82-L94
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/typestate.go
|
isResultPointer
|
func (s *State) isResultPointer(thriftType *parser.Type) bool {
_, basicGoType := thriftToGo[s.rootType(thriftType).Name]
return !basicGoType
}
|
go
|
func (s *State) isResultPointer(thriftType *parser.Type) bool {
_, basicGoType := thriftToGo[s.rootType(thriftType).Name]
return !basicGoType
}
|
[
"func",
"(",
"s",
"*",
"State",
")",
"isResultPointer",
"(",
"thriftType",
"*",
"parser",
".",
"Type",
")",
"bool",
"{",
"_",
",",
"basicGoType",
":=",
"thriftToGo",
"[",
"s",
".",
"rootType",
"(",
"thriftType",
")",
".",
"Name",
"]",
"\n",
"return",
"!",
"basicGoType",
"\n",
"}"
] |
// isResultPointer returns whether the result for this method is a pointer.
|
[
"isResultPointer",
"returns",
"whether",
"the",
"result",
"for",
"this",
"method",
"is",
"a",
"pointer",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/typestate.go#L97-L100
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/typestate.go
|
goType
|
func (s *State) goType(thriftType *parser.Type) string {
return s.goTypePrefix("", thriftType)
}
|
go
|
func (s *State) goType(thriftType *parser.Type) string {
return s.goTypePrefix("", thriftType)
}
|
[
"func",
"(",
"s",
"*",
"State",
")",
"goType",
"(",
"thriftType",
"*",
"parser",
".",
"Type",
")",
"string",
"{",
"return",
"s",
".",
"goTypePrefix",
"(",
"\"\"",
",",
"thriftType",
")",
"\n",
"}"
] |
// goType returns the Go type name for the given thrift type.
|
[
"goType",
"returns",
"the",
"Go",
"type",
"name",
"for",
"the",
"given",
"thrift",
"type",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/typestate.go#L103-L105
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/typestate.go
|
goTypePrefix
|
func (s *State) goTypePrefix(prefix string, thriftType *parser.Type) string {
switch thriftType.Name {
case "binary":
return "[]byte"
case "list":
return "[]" + s.goType(thriftType.ValueType)
case "set":
return "map[" + s.goType(thriftType.ValueType) + "]bool"
case "map":
return "map[" + s.goType(thriftType.KeyType) + "]" + s.goType(thriftType.ValueType)
}
// If the type is imported, then ignore the package.
if state, newType, include := s.checkInclude(thriftType); include != nil {
return state.goTypePrefix(include.Package()+".", newType)
}
// If the type is a direct Go type, use that.
if goType, ok := thriftToGo[thriftType.Name]; ok {
return goType
}
goThriftName := goPublicFieldName(thriftType.Name)
goThriftName = prefix + goThriftName
// Check if the type has a typedef to the direct Go type.
rootType := s.rootType(thriftType)
if _, ok := thriftToGo[rootType.Name]; ok {
return goThriftName
}
if rootType.Name == "list" ||
rootType.Name == "set" ||
rootType.Name == "map" {
return goThriftName
}
// If it's a typedef to another struct, then the typedef is defined as a pointer
// so we do not want the pointer type here.
if rootType != thriftType {
return goThriftName
}
// If it's not a typedef for a basic type, we use a pointer.
return "*" + goThriftName
}
|
go
|
func (s *State) goTypePrefix(prefix string, thriftType *parser.Type) string {
switch thriftType.Name {
case "binary":
return "[]byte"
case "list":
return "[]" + s.goType(thriftType.ValueType)
case "set":
return "map[" + s.goType(thriftType.ValueType) + "]bool"
case "map":
return "map[" + s.goType(thriftType.KeyType) + "]" + s.goType(thriftType.ValueType)
}
// If the type is imported, then ignore the package.
if state, newType, include := s.checkInclude(thriftType); include != nil {
return state.goTypePrefix(include.Package()+".", newType)
}
// If the type is a direct Go type, use that.
if goType, ok := thriftToGo[thriftType.Name]; ok {
return goType
}
goThriftName := goPublicFieldName(thriftType.Name)
goThriftName = prefix + goThriftName
// Check if the type has a typedef to the direct Go type.
rootType := s.rootType(thriftType)
if _, ok := thriftToGo[rootType.Name]; ok {
return goThriftName
}
if rootType.Name == "list" ||
rootType.Name == "set" ||
rootType.Name == "map" {
return goThriftName
}
// If it's a typedef to another struct, then the typedef is defined as a pointer
// so we do not want the pointer type here.
if rootType != thriftType {
return goThriftName
}
// If it's not a typedef for a basic type, we use a pointer.
return "*" + goThriftName
}
|
[
"func",
"(",
"s",
"*",
"State",
")",
"goTypePrefix",
"(",
"prefix",
"string",
",",
"thriftType",
"*",
"parser",
".",
"Type",
")",
"string",
"{",
"switch",
"thriftType",
".",
"Name",
"{",
"case",
"\"binary\"",
":",
"return",
"\"[]byte\"",
"\n",
"case",
"\"list\"",
":",
"return",
"\"[]\"",
"+",
"s",
".",
"goType",
"(",
"thriftType",
".",
"ValueType",
")",
"\n",
"case",
"\"set\"",
":",
"return",
"\"map[\"",
"+",
"s",
".",
"goType",
"(",
"thriftType",
".",
"ValueType",
")",
"+",
"\"]bool\"",
"\n",
"case",
"\"map\"",
":",
"return",
"\"map[\"",
"+",
"s",
".",
"goType",
"(",
"thriftType",
".",
"KeyType",
")",
"+",
"\"]\"",
"+",
"s",
".",
"goType",
"(",
"thriftType",
".",
"ValueType",
")",
"\n",
"}",
"\n",
"if",
"state",
",",
"newType",
",",
"include",
":=",
"s",
".",
"checkInclude",
"(",
"thriftType",
")",
";",
"include",
"!=",
"nil",
"{",
"return",
"state",
".",
"goTypePrefix",
"(",
"include",
".",
"Package",
"(",
")",
"+",
"\".\"",
",",
"newType",
")",
"\n",
"}",
"\n",
"if",
"goType",
",",
"ok",
":=",
"thriftToGo",
"[",
"thriftType",
".",
"Name",
"]",
";",
"ok",
"{",
"return",
"goType",
"\n",
"}",
"\n",
"goThriftName",
":=",
"goPublicFieldName",
"(",
"thriftType",
".",
"Name",
")",
"\n",
"goThriftName",
"=",
"prefix",
"+",
"goThriftName",
"\n",
"rootType",
":=",
"s",
".",
"rootType",
"(",
"thriftType",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"thriftToGo",
"[",
"rootType",
".",
"Name",
"]",
";",
"ok",
"{",
"return",
"goThriftName",
"\n",
"}",
"\n",
"if",
"rootType",
".",
"Name",
"==",
"\"list\"",
"||",
"rootType",
".",
"Name",
"==",
"\"set\"",
"||",
"rootType",
".",
"Name",
"==",
"\"map\"",
"{",
"return",
"goThriftName",
"\n",
"}",
"\n",
"if",
"rootType",
"!=",
"thriftType",
"{",
"return",
"goThriftName",
"\n",
"}",
"\n",
"return",
"\"*\"",
"+",
"goThriftName",
"\n",
"}"
] |
// goTypePrefix returns the Go type name for the given thrift type with the prefix.
|
[
"goTypePrefix",
"returns",
"the",
"Go",
"type",
"name",
"for",
"the",
"given",
"thrift",
"type",
"with",
"the",
"prefix",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/typestate.go#L108-L152
|
test
|
uber/tchannel-go
|
context.go
|
NewContext
|
func NewContext(timeout time.Duration) (context.Context, context.CancelFunc) {
return NewContextBuilder(timeout).Build()
}
|
go
|
func NewContext(timeout time.Duration) (context.Context, context.CancelFunc) {
return NewContextBuilder(timeout).Build()
}
|
[
"func",
"NewContext",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"context",
".",
"Context",
",",
"context",
".",
"CancelFunc",
")",
"{",
"return",
"NewContextBuilder",
"(",
"timeout",
")",
".",
"Build",
"(",
")",
"\n",
"}"
] |
// NewContext returns a new root context used to make TChannel requests.
|
[
"NewContext",
"returns",
"a",
"new",
"root",
"context",
"used",
"to",
"make",
"TChannel",
"requests",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context.go#L85-L87
|
test
|
uber/tchannel-go
|
context.go
|
newIncomingContext
|
func newIncomingContext(call IncomingCall, timeout time.Duration) (context.Context, context.CancelFunc) {
return NewContextBuilder(timeout).
setIncomingCall(call).
Build()
}
|
go
|
func newIncomingContext(call IncomingCall, timeout time.Duration) (context.Context, context.CancelFunc) {
return NewContextBuilder(timeout).
setIncomingCall(call).
Build()
}
|
[
"func",
"newIncomingContext",
"(",
"call",
"IncomingCall",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"context",
".",
"Context",
",",
"context",
".",
"CancelFunc",
")",
"{",
"return",
"NewContextBuilder",
"(",
"timeout",
")",
".",
"setIncomingCall",
"(",
"call",
")",
".",
"Build",
"(",
")",
"\n",
"}"
] |
// newIncomingContext creates a new context for an incoming call with the given span.
|
[
"newIncomingContext",
"creates",
"a",
"new",
"context",
"for",
"an",
"incoming",
"call",
"with",
"the",
"given",
"span",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context.go#L98-L102
|
test
|
uber/tchannel-go
|
context.go
|
CurrentCall
|
func CurrentCall(ctx context.Context) IncomingCall {
if params := getTChannelParams(ctx); params != nil {
return params.call
}
return nil
}
|
go
|
func CurrentCall(ctx context.Context) IncomingCall {
if params := getTChannelParams(ctx); params != nil {
return params.call
}
return nil
}
|
[
"func",
"CurrentCall",
"(",
"ctx",
"context",
".",
"Context",
")",
"IncomingCall",
"{",
"if",
"params",
":=",
"getTChannelParams",
"(",
"ctx",
")",
";",
"params",
"!=",
"nil",
"{",
"return",
"params",
".",
"call",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CurrentCall returns the current incoming call, or nil if this is not an incoming call context.
|
[
"CurrentCall",
"returns",
"the",
"current",
"incoming",
"call",
"or",
"nil",
"if",
"this",
"is",
"not",
"an",
"incoming",
"call",
"context",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context.go#L105-L110
|
test
|
uber/tchannel-go
|
trand/rand.go
|
New
|
func New(seed int64) *rand.Rand {
return rand.New(&lockedSource{src: rand.NewSource(seed)})
}
|
go
|
func New(seed int64) *rand.Rand {
return rand.New(&lockedSource{src: rand.NewSource(seed)})
}
|
[
"func",
"New",
"(",
"seed",
"int64",
")",
"*",
"rand",
".",
"Rand",
"{",
"return",
"rand",
".",
"New",
"(",
"&",
"lockedSource",
"{",
"src",
":",
"rand",
".",
"NewSource",
"(",
"seed",
")",
"}",
")",
"\n",
"}"
] |
// New returns a rand.Rand that is threadsafe.
|
[
"New",
"returns",
"a",
"rand",
".",
"Rand",
"that",
"is",
"threadsafe",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/trand/rand.go#L40-L42
|
test
|
uber/tchannel-go
|
thrift/meta.go
|
Health
|
func (h *metaHandler) Health(ctx Context, req *meta.HealthRequest) (*meta.HealthStatus, error) {
ok, message := h.healthFn(ctx, metaReqToReq(req))
if message == "" {
return &meta.HealthStatus{Ok: ok}, nil
}
return &meta.HealthStatus{Ok: ok, Message: &message}, nil
}
|
go
|
func (h *metaHandler) Health(ctx Context, req *meta.HealthRequest) (*meta.HealthStatus, error) {
ok, message := h.healthFn(ctx, metaReqToReq(req))
if message == "" {
return &meta.HealthStatus{Ok: ok}, nil
}
return &meta.HealthStatus{Ok: ok, Message: &message}, nil
}
|
[
"func",
"(",
"h",
"*",
"metaHandler",
")",
"Health",
"(",
"ctx",
"Context",
",",
"req",
"*",
"meta",
".",
"HealthRequest",
")",
"(",
"*",
"meta",
".",
"HealthStatus",
",",
"error",
")",
"{",
"ok",
",",
"message",
":=",
"h",
".",
"healthFn",
"(",
"ctx",
",",
"metaReqToReq",
"(",
"req",
")",
")",
"\n",
"if",
"message",
"==",
"\"\"",
"{",
"return",
"&",
"meta",
".",
"HealthStatus",
"{",
"Ok",
":",
"ok",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"meta",
".",
"HealthStatus",
"{",
"Ok",
":",
"ok",
",",
"Message",
":",
"&",
"message",
"}",
",",
"nil",
"\n",
"}"
] |
// Health returns true as default Health endpoint.
|
[
"Health",
"returns",
"true",
"as",
"default",
"Health",
"endpoint",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/meta.go#L71-L77
|
test
|
uber/tchannel-go
|
context_header.go
|
Headers
|
func (c headerCtx) Headers() map[string]string {
if h := c.headers(); h != nil {
return h.reqHeaders
}
return nil
}
|
go
|
func (c headerCtx) Headers() map[string]string {
if h := c.headers(); h != nil {
return h.reqHeaders
}
return nil
}
|
[
"func",
"(",
"c",
"headerCtx",
")",
"Headers",
"(",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"if",
"h",
":=",
"c",
".",
"headers",
"(",
")",
";",
"h",
"!=",
"nil",
"{",
"return",
"h",
".",
"reqHeaders",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Headers gets application headers out of the context.
|
[
"Headers",
"gets",
"application",
"headers",
"out",
"of",
"the",
"context",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_header.go#L61-L66
|
test
|
uber/tchannel-go
|
context_header.go
|
ResponseHeaders
|
func (c headerCtx) ResponseHeaders() map[string]string {
if h := c.headers(); h != nil {
return h.respHeaders
}
return nil
}
|
go
|
func (c headerCtx) ResponseHeaders() map[string]string {
if h := c.headers(); h != nil {
return h.respHeaders
}
return nil
}
|
[
"func",
"(",
"c",
"headerCtx",
")",
"ResponseHeaders",
"(",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"if",
"h",
":=",
"c",
".",
"headers",
"(",
")",
";",
"h",
"!=",
"nil",
"{",
"return",
"h",
".",
"respHeaders",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ResponseHeaders returns the response headers.
|
[
"ResponseHeaders",
"returns",
"the",
"response",
"headers",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_header.go#L69-L74
|
test
|
uber/tchannel-go
|
context_header.go
|
SetResponseHeaders
|
func (c headerCtx) SetResponseHeaders(headers map[string]string) {
if h := c.headers(); h != nil {
h.respHeaders = headers
return
}
panic("SetResponseHeaders called on ContextWithHeaders not created via WrapWithHeaders")
}
|
go
|
func (c headerCtx) SetResponseHeaders(headers map[string]string) {
if h := c.headers(); h != nil {
h.respHeaders = headers
return
}
panic("SetResponseHeaders called on ContextWithHeaders not created via WrapWithHeaders")
}
|
[
"func",
"(",
"c",
"headerCtx",
")",
"SetResponseHeaders",
"(",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"if",
"h",
":=",
"c",
".",
"headers",
"(",
")",
";",
"h",
"!=",
"nil",
"{",
"h",
".",
"respHeaders",
"=",
"headers",
"\n",
"return",
"\n",
"}",
"\n",
"panic",
"(",
"\"SetResponseHeaders called on ContextWithHeaders not created via WrapWithHeaders\"",
")",
"\n",
"}"
] |
// SetResponseHeaders sets the response headers.
|
[
"SetResponseHeaders",
"sets",
"the",
"response",
"headers",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_header.go#L77-L83
|
test
|
uber/tchannel-go
|
context_header.go
|
Child
|
func (c headerCtx) Child() ContextWithHeaders {
var headersCopy headersContainer
if h := c.headers(); h != nil {
headersCopy = *h
}
return Wrap(context.WithValue(c.Context, contextKeyHeaders, &headersCopy))
}
|
go
|
func (c headerCtx) Child() ContextWithHeaders {
var headersCopy headersContainer
if h := c.headers(); h != nil {
headersCopy = *h
}
return Wrap(context.WithValue(c.Context, contextKeyHeaders, &headersCopy))
}
|
[
"func",
"(",
"c",
"headerCtx",
")",
"Child",
"(",
")",
"ContextWithHeaders",
"{",
"var",
"headersCopy",
"headersContainer",
"\n",
"if",
"h",
":=",
"c",
".",
"headers",
"(",
")",
";",
"h",
"!=",
"nil",
"{",
"headersCopy",
"=",
"*",
"h",
"\n",
"}",
"\n",
"return",
"Wrap",
"(",
"context",
".",
"WithValue",
"(",
"c",
".",
"Context",
",",
"contextKeyHeaders",
",",
"&",
"headersCopy",
")",
")",
"\n",
"}"
] |
// Child creates a child context with a separate container for headers.
|
[
"Child",
"creates",
"a",
"child",
"context",
"with",
"a",
"separate",
"container",
"for",
"headers",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_header.go#L86-L93
|
test
|
uber/tchannel-go
|
context_header.go
|
Wrap
|
func Wrap(ctx context.Context) ContextWithHeaders {
hctx := headerCtx{Context: ctx}
if h := hctx.headers(); h != nil {
return hctx
}
// If there is no header container, we should create an empty one.
return WrapWithHeaders(ctx, nil)
}
|
go
|
func Wrap(ctx context.Context) ContextWithHeaders {
hctx := headerCtx{Context: ctx}
if h := hctx.headers(); h != nil {
return hctx
}
// If there is no header container, we should create an empty one.
return WrapWithHeaders(ctx, nil)
}
|
[
"func",
"Wrap",
"(",
"ctx",
"context",
".",
"Context",
")",
"ContextWithHeaders",
"{",
"hctx",
":=",
"headerCtx",
"{",
"Context",
":",
"ctx",
"}",
"\n",
"if",
"h",
":=",
"hctx",
".",
"headers",
"(",
")",
";",
"h",
"!=",
"nil",
"{",
"return",
"hctx",
"\n",
"}",
"\n",
"return",
"WrapWithHeaders",
"(",
"ctx",
",",
"nil",
")",
"\n",
"}"
] |
// Wrap wraps an existing context.Context into a ContextWithHeaders.
// If the underlying context has headers, they are preserved.
|
[
"Wrap",
"wraps",
"an",
"existing",
"context",
".",
"Context",
"into",
"a",
"ContextWithHeaders",
".",
"If",
"the",
"underlying",
"context",
"has",
"headers",
"they",
"are",
"preserved",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_header.go#L97-L105
|
test
|
uber/tchannel-go
|
context_header.go
|
WrapWithHeaders
|
func WrapWithHeaders(ctx context.Context, headers map[string]string) ContextWithHeaders {
h := &headersContainer{
reqHeaders: headers,
}
newCtx := context.WithValue(ctx, contextKeyHeaders, h)
return headerCtx{Context: newCtx}
}
|
go
|
func WrapWithHeaders(ctx context.Context, headers map[string]string) ContextWithHeaders {
h := &headersContainer{
reqHeaders: headers,
}
newCtx := context.WithValue(ctx, contextKeyHeaders, h)
return headerCtx{Context: newCtx}
}
|
[
"func",
"WrapWithHeaders",
"(",
"ctx",
"context",
".",
"Context",
",",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"ContextWithHeaders",
"{",
"h",
":=",
"&",
"headersContainer",
"{",
"reqHeaders",
":",
"headers",
",",
"}",
"\n",
"newCtx",
":=",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"contextKeyHeaders",
",",
"h",
")",
"\n",
"return",
"headerCtx",
"{",
"Context",
":",
"newCtx",
"}",
"\n",
"}"
] |
// WrapWithHeaders returns a Context that can be used to make a call with request headers.
// If the parent `ctx` is already an instance of ContextWithHeaders, its existing headers
// will be ignored. In order to merge new headers with parent headers, use ContextBuilder.
|
[
"WrapWithHeaders",
"returns",
"a",
"Context",
"that",
"can",
"be",
"used",
"to",
"make",
"a",
"call",
"with",
"request",
"headers",
".",
"If",
"the",
"parent",
"ctx",
"is",
"already",
"an",
"instance",
"of",
"ContextWithHeaders",
"its",
"existing",
"headers",
"will",
"be",
"ignored",
".",
"In",
"order",
"to",
"merge",
"new",
"headers",
"with",
"parent",
"headers",
"use",
"ContextBuilder",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_header.go#L110-L116
|
test
|
uber/tchannel-go
|
context_header.go
|
WithoutHeaders
|
func WithoutHeaders(ctx context.Context) context.Context {
return context.WithValue(context.WithValue(ctx, contextKeyTChannel, nil), contextKeyHeaders, nil)
}
|
go
|
func WithoutHeaders(ctx context.Context) context.Context {
return context.WithValue(context.WithValue(ctx, contextKeyTChannel, nil), contextKeyHeaders, nil)
}
|
[
"func",
"WithoutHeaders",
"(",
"ctx",
"context",
".",
"Context",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"contextKeyTChannel",
",",
"nil",
")",
",",
"contextKeyHeaders",
",",
"nil",
")",
"\n",
"}"
] |
// WithoutHeaders hides any TChannel headers from the given context.
|
[
"WithoutHeaders",
"hides",
"any",
"TChannel",
"headers",
"from",
"the",
"given",
"context",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/context_header.go#L119-L121
|
test
|
uber/tchannel-go
|
mex.go
|
Notify
|
func (e *errNotifier) Notify(err error) error {
// The code should never try to Notify(nil).
if err == nil {
panic("cannot Notify with no error")
}
// There may be some sort of race where we try to notify the mex twice.
if !e.notified.CAS(false, true) {
return fmt.Errorf("cannot broadcast error: %v, already have: %v", err, e.err)
}
e.err = err
close(e.c)
return nil
}
|
go
|
func (e *errNotifier) Notify(err error) error {
// The code should never try to Notify(nil).
if err == nil {
panic("cannot Notify with no error")
}
// There may be some sort of race where we try to notify the mex twice.
if !e.notified.CAS(false, true) {
return fmt.Errorf("cannot broadcast error: %v, already have: %v", err, e.err)
}
e.err = err
close(e.c)
return nil
}
|
[
"func",
"(",
"e",
"*",
"errNotifier",
")",
"Notify",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"==",
"nil",
"{",
"panic",
"(",
"\"cannot Notify with no error\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"e",
".",
"notified",
".",
"CAS",
"(",
"false",
",",
"true",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"cannot broadcast error: %v, already have: %v\"",
",",
"err",
",",
"e",
".",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"err",
"=",
"err",
"\n",
"close",
"(",
"e",
".",
"c",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Notify will store the error and notify all waiters on c that there's an error.
|
[
"Notify",
"will",
"store",
"the",
"error",
"and",
"notify",
"all",
"waiters",
"on",
"c",
"that",
"there",
"s",
"an",
"error",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L61-L75
|
test
|
uber/tchannel-go
|
mex.go
|
forwardPeerFrame
|
func (mex *messageExchange) forwardPeerFrame(frame *Frame) error {
// We want a very specific priority here:
// 1. Timeouts/cancellation (mex.ctx errors)
// 2. Whether recvCh has buffer space (non-blocking select over mex.recvCh)
// 3. Other mex errors (mex.errCh)
// Which is why we check the context error only (instead of mex.checkError).
// In the mex.errCh case, we do a non-blocking write to recvCh to prioritize it.
if err := mex.ctx.Err(); err != nil {
return GetContextError(err)
}
select {
case mex.recvCh <- frame:
return nil
case <-mex.ctx.Done():
// Note: One slow reader processing a large request could stall the connection.
// If we see this, we need to increase the recvCh buffer size.
return GetContextError(mex.ctx.Err())
case <-mex.errCh.c:
// Select will randomly choose a case, but we want to prioritize
// sending a frame over the errCh. Try a non-blocking write.
select {
case mex.recvCh <- frame:
return nil
default:
}
return mex.errCh.err
}
}
|
go
|
func (mex *messageExchange) forwardPeerFrame(frame *Frame) error {
// We want a very specific priority here:
// 1. Timeouts/cancellation (mex.ctx errors)
// 2. Whether recvCh has buffer space (non-blocking select over mex.recvCh)
// 3. Other mex errors (mex.errCh)
// Which is why we check the context error only (instead of mex.checkError).
// In the mex.errCh case, we do a non-blocking write to recvCh to prioritize it.
if err := mex.ctx.Err(); err != nil {
return GetContextError(err)
}
select {
case mex.recvCh <- frame:
return nil
case <-mex.ctx.Done():
// Note: One slow reader processing a large request could stall the connection.
// If we see this, we need to increase the recvCh buffer size.
return GetContextError(mex.ctx.Err())
case <-mex.errCh.c:
// Select will randomly choose a case, but we want to prioritize
// sending a frame over the errCh. Try a non-blocking write.
select {
case mex.recvCh <- frame:
return nil
default:
}
return mex.errCh.err
}
}
|
[
"func",
"(",
"mex",
"*",
"messageExchange",
")",
"forwardPeerFrame",
"(",
"frame",
"*",
"Frame",
")",
"error",
"{",
"if",
"err",
":=",
"mex",
".",
"ctx",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"GetContextError",
"(",
"err",
")",
"\n",
"}",
"\n",
"select",
"{",
"case",
"mex",
".",
"recvCh",
"<-",
"frame",
":",
"return",
"nil",
"\n",
"case",
"<-",
"mex",
".",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"GetContextError",
"(",
"mex",
".",
"ctx",
".",
"Err",
"(",
")",
")",
"\n",
"case",
"<-",
"mex",
".",
"errCh",
".",
"c",
":",
"select",
"{",
"case",
"mex",
".",
"recvCh",
"<-",
"frame",
":",
"return",
"nil",
"\n",
"default",
":",
"}",
"\n",
"return",
"mex",
".",
"errCh",
".",
"err",
"\n",
"}",
"\n",
"}"
] |
// forwardPeerFrame forwards a frame from a peer to the message exchange, where
// it can be pulled by whatever application thread is handling the exchange
|
[
"forwardPeerFrame",
"forwards",
"a",
"frame",
"from",
"a",
"peer",
"to",
"the",
"message",
"exchange",
"where",
"it",
"can",
"be",
"pulled",
"by",
"whatever",
"application",
"thread",
"is",
"handling",
"the",
"exchange"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L116-L144
|
test
|
uber/tchannel-go
|
mex.go
|
recvPeerFrame
|
func (mex *messageExchange) recvPeerFrame() (*Frame, error) {
// We have to check frames/errors in a very specific order here:
// 1. Timeouts/cancellation (mex.ctx errors)
// 2. Any pending frames (non-blocking select over mex.recvCh)
// 3. Other mex errors (mex.errCh)
// Which is why we check the context error only (instead of mex.checkError)e
// In the mex.errCh case, we do a non-blocking read from recvCh to prioritize it.
if err := mex.ctx.Err(); err != nil {
return nil, GetContextError(err)
}
select {
case frame := <-mex.recvCh:
if err := mex.checkFrame(frame); err != nil {
return nil, err
}
return frame, nil
case <-mex.ctx.Done():
return nil, GetContextError(mex.ctx.Err())
case <-mex.errCh.c:
// Select will randomly choose a case, but we want to prioritize
// receiving a frame over errCh. Try a non-blocking read.
select {
case frame := <-mex.recvCh:
if err := mex.checkFrame(frame); err != nil {
return nil, err
}
return frame, nil
default:
}
return nil, mex.errCh.err
}
}
|
go
|
func (mex *messageExchange) recvPeerFrame() (*Frame, error) {
// We have to check frames/errors in a very specific order here:
// 1. Timeouts/cancellation (mex.ctx errors)
// 2. Any pending frames (non-blocking select over mex.recvCh)
// 3. Other mex errors (mex.errCh)
// Which is why we check the context error only (instead of mex.checkError)e
// In the mex.errCh case, we do a non-blocking read from recvCh to prioritize it.
if err := mex.ctx.Err(); err != nil {
return nil, GetContextError(err)
}
select {
case frame := <-mex.recvCh:
if err := mex.checkFrame(frame); err != nil {
return nil, err
}
return frame, nil
case <-mex.ctx.Done():
return nil, GetContextError(mex.ctx.Err())
case <-mex.errCh.c:
// Select will randomly choose a case, but we want to prioritize
// receiving a frame over errCh. Try a non-blocking read.
select {
case frame := <-mex.recvCh:
if err := mex.checkFrame(frame); err != nil {
return nil, err
}
return frame, nil
default:
}
return nil, mex.errCh.err
}
}
|
[
"func",
"(",
"mex",
"*",
"messageExchange",
")",
"recvPeerFrame",
"(",
")",
"(",
"*",
"Frame",
",",
"error",
")",
"{",
"if",
"err",
":=",
"mex",
".",
"ctx",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"GetContextError",
"(",
"err",
")",
"\n",
"}",
"\n",
"select",
"{",
"case",
"frame",
":=",
"<-",
"mex",
".",
"recvCh",
":",
"if",
"err",
":=",
"mex",
".",
"checkFrame",
"(",
"frame",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"frame",
",",
"nil",
"\n",
"case",
"<-",
"mex",
".",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"nil",
",",
"GetContextError",
"(",
"mex",
".",
"ctx",
".",
"Err",
"(",
")",
")",
"\n",
"case",
"<-",
"mex",
".",
"errCh",
".",
"c",
":",
"select",
"{",
"case",
"frame",
":=",
"<-",
"mex",
".",
"recvCh",
":",
"if",
"err",
":=",
"mex",
".",
"checkFrame",
"(",
"frame",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"frame",
",",
"nil",
"\n",
"default",
":",
"}",
"\n",
"return",
"nil",
",",
"mex",
".",
"errCh",
".",
"err",
"\n",
"}",
"\n",
"}"
] |
// recvPeerFrame waits for a new frame from the peer, or until the context
// expires or is cancelled
|
[
"recvPeerFrame",
"waits",
"for",
"a",
"new",
"frame",
"from",
"the",
"peer",
"or",
"until",
"the",
"context",
"expires",
"or",
"is",
"cancelled"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L159-L191
|
test
|
uber/tchannel-go
|
mex.go
|
recvPeerFrameOfType
|
func (mex *messageExchange) recvPeerFrameOfType(msgType messageType) (*Frame, error) {
frame, err := mex.recvPeerFrame()
if err != nil {
return nil, err
}
switch frame.Header.messageType {
case msgType:
return frame, nil
case messageTypeError:
// If we read an error frame, we can release it once we deserialize it.
defer mex.framePool.Release(frame)
errMsg := errorMessage{
id: frame.Header.ID,
}
var rbuf typed.ReadBuffer
rbuf.Wrap(frame.SizedPayload())
if err := errMsg.read(&rbuf); err != nil {
return nil, err
}
return nil, errMsg
default:
// TODO(mmihic): Should be treated as a protocol error
mex.mexset.log.WithFields(
LogField{"header", frame.Header},
LogField{"expectedType", msgType},
LogField{"expectedID", mex.msgID},
).Warn("Received unexpected frame.")
return nil, errUnexpectedFrameType
}
}
|
go
|
func (mex *messageExchange) recvPeerFrameOfType(msgType messageType) (*Frame, error) {
frame, err := mex.recvPeerFrame()
if err != nil {
return nil, err
}
switch frame.Header.messageType {
case msgType:
return frame, nil
case messageTypeError:
// If we read an error frame, we can release it once we deserialize it.
defer mex.framePool.Release(frame)
errMsg := errorMessage{
id: frame.Header.ID,
}
var rbuf typed.ReadBuffer
rbuf.Wrap(frame.SizedPayload())
if err := errMsg.read(&rbuf); err != nil {
return nil, err
}
return nil, errMsg
default:
// TODO(mmihic): Should be treated as a protocol error
mex.mexset.log.WithFields(
LogField{"header", frame.Header},
LogField{"expectedType", msgType},
LogField{"expectedID", mex.msgID},
).Warn("Received unexpected frame.")
return nil, errUnexpectedFrameType
}
}
|
[
"func",
"(",
"mex",
"*",
"messageExchange",
")",
"recvPeerFrameOfType",
"(",
"msgType",
"messageType",
")",
"(",
"*",
"Frame",
",",
"error",
")",
"{",
"frame",
",",
"err",
":=",
"mex",
".",
"recvPeerFrame",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"switch",
"frame",
".",
"Header",
".",
"messageType",
"{",
"case",
"msgType",
":",
"return",
"frame",
",",
"nil",
"\n",
"case",
"messageTypeError",
":",
"defer",
"mex",
".",
"framePool",
".",
"Release",
"(",
"frame",
")",
"\n",
"errMsg",
":=",
"errorMessage",
"{",
"id",
":",
"frame",
".",
"Header",
".",
"ID",
",",
"}",
"\n",
"var",
"rbuf",
"typed",
".",
"ReadBuffer",
"\n",
"rbuf",
".",
"Wrap",
"(",
"frame",
".",
"SizedPayload",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"errMsg",
".",
"read",
"(",
"&",
"rbuf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errMsg",
"\n",
"default",
":",
"mex",
".",
"mexset",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"header\"",
",",
"frame",
".",
"Header",
"}",
",",
"LogField",
"{",
"\"expectedType\"",
",",
"msgType",
"}",
",",
"LogField",
"{",
"\"expectedID\"",
",",
"mex",
".",
"msgID",
"}",
",",
")",
".",
"Warn",
"(",
"\"Received unexpected frame.\"",
")",
"\n",
"return",
"nil",
",",
"errUnexpectedFrameType",
"\n",
"}",
"\n",
"}"
] |
// recvPeerFrameOfType waits for a new frame of a given type from the peer, failing
// if the next frame received is not of that type.
// If an error frame is returned, then the errorMessage is returned as the error.
|
[
"recvPeerFrameOfType",
"waits",
"for",
"a",
"new",
"frame",
"of",
"a",
"given",
"type",
"from",
"the",
"peer",
"failing",
"if",
"the",
"next",
"frame",
"received",
"is",
"not",
"of",
"that",
"type",
".",
"If",
"an",
"error",
"frame",
"is",
"returned",
"then",
"the",
"errorMessage",
"is",
"returned",
"as",
"the",
"error",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L196-L229
|
test
|
uber/tchannel-go
|
mex.go
|
shutdown
|
func (mex *messageExchange) shutdown() {
// The reader and writer side can both hit errors and try to shutdown the mex,
// so we ensure that it's only shut down once.
if !mex.shutdownAtomic.CAS(false, true) {
return
}
if mex.errChNotified.CAS(false, true) {
mex.errCh.Notify(errMexShutdown)
}
mex.mexset.removeExchange(mex.msgID)
}
|
go
|
func (mex *messageExchange) shutdown() {
// The reader and writer side can both hit errors and try to shutdown the mex,
// so we ensure that it's only shut down once.
if !mex.shutdownAtomic.CAS(false, true) {
return
}
if mex.errChNotified.CAS(false, true) {
mex.errCh.Notify(errMexShutdown)
}
mex.mexset.removeExchange(mex.msgID)
}
|
[
"func",
"(",
"mex",
"*",
"messageExchange",
")",
"shutdown",
"(",
")",
"{",
"if",
"!",
"mex",
".",
"shutdownAtomic",
".",
"CAS",
"(",
"false",
",",
"true",
")",
"{",
"return",
"\n",
"}",
"\n",
"if",
"mex",
".",
"errChNotified",
".",
"CAS",
"(",
"false",
",",
"true",
")",
"{",
"mex",
".",
"errCh",
".",
"Notify",
"(",
"errMexShutdown",
")",
"\n",
"}",
"\n",
"mex",
".",
"mexset",
".",
"removeExchange",
"(",
"mex",
".",
"msgID",
")",
"\n",
"}"
] |
// shutdown shuts down the message exchange, removing it from the message
// exchange set so that it cannot receive more messages from the peer. The
// receive channel remains open, however, in case there are concurrent
// goroutines sending to it.
|
[
"shutdown",
"shuts",
"down",
"the",
"message",
"exchange",
"removing",
"it",
"from",
"the",
"message",
"exchange",
"set",
"so",
"that",
"it",
"cannot",
"receive",
"more",
"messages",
"from",
"the",
"peer",
".",
"The",
"receive",
"channel",
"remains",
"open",
"however",
"in",
"case",
"there",
"are",
"concurrent",
"goroutines",
"sending",
"to",
"it",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L235-L247
|
test
|
uber/tchannel-go
|
mex.go
|
newMessageExchangeSet
|
func newMessageExchangeSet(log Logger, name string) *messageExchangeSet {
return &messageExchangeSet{
name: name,
log: log.WithFields(LogField{"exchange", name}),
exchanges: make(map[uint32]*messageExchange),
expiredExchanges: make(map[uint32]struct{}),
}
}
|
go
|
func newMessageExchangeSet(log Logger, name string) *messageExchangeSet {
return &messageExchangeSet{
name: name,
log: log.WithFields(LogField{"exchange", name}),
exchanges: make(map[uint32]*messageExchange),
expiredExchanges: make(map[uint32]struct{}),
}
}
|
[
"func",
"newMessageExchangeSet",
"(",
"log",
"Logger",
",",
"name",
"string",
")",
"*",
"messageExchangeSet",
"{",
"return",
"&",
"messageExchangeSet",
"{",
"name",
":",
"name",
",",
"log",
":",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"exchange\"",
",",
"name",
"}",
")",
",",
"exchanges",
":",
"make",
"(",
"map",
"[",
"uint32",
"]",
"*",
"messageExchange",
")",
",",
"expiredExchanges",
":",
"make",
"(",
"map",
"[",
"uint32",
"]",
"struct",
"{",
"}",
")",
",",
"}",
"\n",
"}"
] |
// newMessageExchangeSet creates a new messageExchangeSet with a given name.
|
[
"newMessageExchangeSet",
"creates",
"a",
"new",
"messageExchangeSet",
"with",
"a",
"given",
"name",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L280-L287
|
test
|
uber/tchannel-go
|
mex.go
|
addExchange
|
func (mexset *messageExchangeSet) addExchange(mex *messageExchange) error {
if mexset.shutdown {
return errMexSetShutdown
}
if _, ok := mexset.exchanges[mex.msgID]; ok {
return errDuplicateMex
}
mexset.exchanges[mex.msgID] = mex
return nil
}
|
go
|
func (mexset *messageExchangeSet) addExchange(mex *messageExchange) error {
if mexset.shutdown {
return errMexSetShutdown
}
if _, ok := mexset.exchanges[mex.msgID]; ok {
return errDuplicateMex
}
mexset.exchanges[mex.msgID] = mex
return nil
}
|
[
"func",
"(",
"mexset",
"*",
"messageExchangeSet",
")",
"addExchange",
"(",
"mex",
"*",
"messageExchange",
")",
"error",
"{",
"if",
"mexset",
".",
"shutdown",
"{",
"return",
"errMexSetShutdown",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"mexset",
".",
"exchanges",
"[",
"mex",
".",
"msgID",
"]",
";",
"ok",
"{",
"return",
"errDuplicateMex",
"\n",
"}",
"\n",
"mexset",
".",
"exchanges",
"[",
"mex",
".",
"msgID",
"]",
"=",
"mex",
"\n",
"return",
"nil",
"\n",
"}"
] |
// addExchange adds an exchange, it must be called with the mexset locked.
|
[
"addExchange",
"adds",
"an",
"exchange",
"it",
"must",
"be",
"called",
"with",
"the",
"mexset",
"locked",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L290-L301
|
test
|
uber/tchannel-go
|
mex.go
|
newExchange
|
func (mexset *messageExchangeSet) newExchange(ctx context.Context, framePool FramePool,
msgType messageType, msgID uint32, bufferSize int) (*messageExchange, error) {
if mexset.log.Enabled(LogLevelDebug) {
mexset.log.Debugf("Creating new %s message exchange for [%v:%d]", mexset.name, msgType, msgID)
}
mex := &messageExchange{
msgType: msgType,
msgID: msgID,
ctx: ctx,
recvCh: make(chan *Frame, bufferSize),
errCh: newErrNotifier(),
mexset: mexset,
framePool: framePool,
}
mexset.Lock()
addErr := mexset.addExchange(mex)
mexset.Unlock()
if addErr != nil {
logger := mexset.log.WithFields(
LogField{"msgID", mex.msgID},
LogField{"msgType", mex.msgType},
LogField{"exchange", mexset.name},
)
if addErr == errMexSetShutdown {
logger.Warn("Attempted to create new mex after mexset shutdown.")
} else if addErr == errDuplicateMex {
logger.Warn("Duplicate msg ID for active and new mex.")
}
return nil, addErr
}
mexset.onAdded()
// TODO(mmihic): Put into a deadline ordered heap so we can garbage collected expired exchanges
return mex, nil
}
|
go
|
func (mexset *messageExchangeSet) newExchange(ctx context.Context, framePool FramePool,
msgType messageType, msgID uint32, bufferSize int) (*messageExchange, error) {
if mexset.log.Enabled(LogLevelDebug) {
mexset.log.Debugf("Creating new %s message exchange for [%v:%d]", mexset.name, msgType, msgID)
}
mex := &messageExchange{
msgType: msgType,
msgID: msgID,
ctx: ctx,
recvCh: make(chan *Frame, bufferSize),
errCh: newErrNotifier(),
mexset: mexset,
framePool: framePool,
}
mexset.Lock()
addErr := mexset.addExchange(mex)
mexset.Unlock()
if addErr != nil {
logger := mexset.log.WithFields(
LogField{"msgID", mex.msgID},
LogField{"msgType", mex.msgType},
LogField{"exchange", mexset.name},
)
if addErr == errMexSetShutdown {
logger.Warn("Attempted to create new mex after mexset shutdown.")
} else if addErr == errDuplicateMex {
logger.Warn("Duplicate msg ID for active and new mex.")
}
return nil, addErr
}
mexset.onAdded()
// TODO(mmihic): Put into a deadline ordered heap so we can garbage collected expired exchanges
return mex, nil
}
|
[
"func",
"(",
"mexset",
"*",
"messageExchangeSet",
")",
"newExchange",
"(",
"ctx",
"context",
".",
"Context",
",",
"framePool",
"FramePool",
",",
"msgType",
"messageType",
",",
"msgID",
"uint32",
",",
"bufferSize",
"int",
")",
"(",
"*",
"messageExchange",
",",
"error",
")",
"{",
"if",
"mexset",
".",
"log",
".",
"Enabled",
"(",
"LogLevelDebug",
")",
"{",
"mexset",
".",
"log",
".",
"Debugf",
"(",
"\"Creating new %s message exchange for [%v:%d]\"",
",",
"mexset",
".",
"name",
",",
"msgType",
",",
"msgID",
")",
"\n",
"}",
"\n",
"mex",
":=",
"&",
"messageExchange",
"{",
"msgType",
":",
"msgType",
",",
"msgID",
":",
"msgID",
",",
"ctx",
":",
"ctx",
",",
"recvCh",
":",
"make",
"(",
"chan",
"*",
"Frame",
",",
"bufferSize",
")",
",",
"errCh",
":",
"newErrNotifier",
"(",
")",
",",
"mexset",
":",
"mexset",
",",
"framePool",
":",
"framePool",
",",
"}",
"\n",
"mexset",
".",
"Lock",
"(",
")",
"\n",
"addErr",
":=",
"mexset",
".",
"addExchange",
"(",
"mex",
")",
"\n",
"mexset",
".",
"Unlock",
"(",
")",
"\n",
"if",
"addErr",
"!=",
"nil",
"{",
"logger",
":=",
"mexset",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"msgID\"",
",",
"mex",
".",
"msgID",
"}",
",",
"LogField",
"{",
"\"msgType\"",
",",
"mex",
".",
"msgType",
"}",
",",
"LogField",
"{",
"\"exchange\"",
",",
"mexset",
".",
"name",
"}",
",",
")",
"\n",
"if",
"addErr",
"==",
"errMexSetShutdown",
"{",
"logger",
".",
"Warn",
"(",
"\"Attempted to create new mex after mexset shutdown.\"",
")",
"\n",
"}",
"else",
"if",
"addErr",
"==",
"errDuplicateMex",
"{",
"logger",
".",
"Warn",
"(",
"\"Duplicate msg ID for active and new mex.\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"addErr",
"\n",
"}",
"\n",
"mexset",
".",
"onAdded",
"(",
")",
"\n",
"return",
"mex",
",",
"nil",
"\n",
"}"
] |
// newExchange creates and adds a new message exchange to this set
|
[
"newExchange",
"creates",
"and",
"adds",
"a",
"new",
"message",
"exchange",
"to",
"this",
"set"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L304-L343
|
test
|
uber/tchannel-go
|
mex.go
|
deleteExchange
|
func (mexset *messageExchangeSet) deleteExchange(msgID uint32) (found, timedOut bool) {
if _, found := mexset.exchanges[msgID]; found {
delete(mexset.exchanges, msgID)
return true, false
}
if _, expired := mexset.expiredExchanges[msgID]; expired {
delete(mexset.expiredExchanges, msgID)
return false, true
}
return false, false
}
|
go
|
func (mexset *messageExchangeSet) deleteExchange(msgID uint32) (found, timedOut bool) {
if _, found := mexset.exchanges[msgID]; found {
delete(mexset.exchanges, msgID)
return true, false
}
if _, expired := mexset.expiredExchanges[msgID]; expired {
delete(mexset.expiredExchanges, msgID)
return false, true
}
return false, false
}
|
[
"func",
"(",
"mexset",
"*",
"messageExchangeSet",
")",
"deleteExchange",
"(",
"msgID",
"uint32",
")",
"(",
"found",
",",
"timedOut",
"bool",
")",
"{",
"if",
"_",
",",
"found",
":=",
"mexset",
".",
"exchanges",
"[",
"msgID",
"]",
";",
"found",
"{",
"delete",
"(",
"mexset",
".",
"exchanges",
",",
"msgID",
")",
"\n",
"return",
"true",
",",
"false",
"\n",
"}",
"\n",
"if",
"_",
",",
"expired",
":=",
"mexset",
".",
"expiredExchanges",
"[",
"msgID",
"]",
";",
"expired",
"{",
"delete",
"(",
"mexset",
".",
"expiredExchanges",
",",
"msgID",
")",
"\n",
"return",
"false",
",",
"true",
"\n",
"}",
"\n",
"return",
"false",
",",
"false",
"\n",
"}"
] |
// deleteExchange will delete msgID, and return whether it was found or whether it was
// timed out. This method must be called with the lock.
|
[
"deleteExchange",
"will",
"delete",
"msgID",
"and",
"return",
"whether",
"it",
"was",
"found",
"or",
"whether",
"it",
"was",
"timed",
"out",
".",
"This",
"method",
"must",
"be",
"called",
"with",
"the",
"lock",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L347-L359
|
test
|
uber/tchannel-go
|
mex.go
|
removeExchange
|
func (mexset *messageExchangeSet) removeExchange(msgID uint32) {
if mexset.log.Enabled(LogLevelDebug) {
mexset.log.Debugf("Removing %s message exchange %d", mexset.name, msgID)
}
mexset.Lock()
found, expired := mexset.deleteExchange(msgID)
mexset.Unlock()
if !found && !expired {
mexset.log.WithFields(
LogField{"msgID", msgID},
).Error("Tried to remove exchange multiple times")
return
}
// If the message exchange was found, then we perform clean up actions.
// These clean up actions can only be run once per exchange.
mexset.onRemoved()
}
|
go
|
func (mexset *messageExchangeSet) removeExchange(msgID uint32) {
if mexset.log.Enabled(LogLevelDebug) {
mexset.log.Debugf("Removing %s message exchange %d", mexset.name, msgID)
}
mexset.Lock()
found, expired := mexset.deleteExchange(msgID)
mexset.Unlock()
if !found && !expired {
mexset.log.WithFields(
LogField{"msgID", msgID},
).Error("Tried to remove exchange multiple times")
return
}
// If the message exchange was found, then we perform clean up actions.
// These clean up actions can only be run once per exchange.
mexset.onRemoved()
}
|
[
"func",
"(",
"mexset",
"*",
"messageExchangeSet",
")",
"removeExchange",
"(",
"msgID",
"uint32",
")",
"{",
"if",
"mexset",
".",
"log",
".",
"Enabled",
"(",
"LogLevelDebug",
")",
"{",
"mexset",
".",
"log",
".",
"Debugf",
"(",
"\"Removing %s message exchange %d\"",
",",
"mexset",
".",
"name",
",",
"msgID",
")",
"\n",
"}",
"\n",
"mexset",
".",
"Lock",
"(",
")",
"\n",
"found",
",",
"expired",
":=",
"mexset",
".",
"deleteExchange",
"(",
"msgID",
")",
"\n",
"mexset",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"found",
"&&",
"!",
"expired",
"{",
"mexset",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"msgID\"",
",",
"msgID",
"}",
",",
")",
".",
"Error",
"(",
"\"Tried to remove exchange multiple times\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"mexset",
".",
"onRemoved",
"(",
")",
"\n",
"}"
] |
// removeExchange removes a message exchange from the set, if it exists.
|
[
"removeExchange",
"removes",
"a",
"message",
"exchange",
"from",
"the",
"set",
"if",
"it",
"exists",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L362-L381
|
test
|
uber/tchannel-go
|
mex.go
|
expireExchange
|
func (mexset *messageExchangeSet) expireExchange(msgID uint32) {
mexset.log.Debugf(
"Removing %s message exchange %d due to timeout, cancellation or blackhole",
mexset.name,
msgID,
)
mexset.Lock()
// TODO(aniketp): explore if cancel can be called everytime we expire an exchange
found, expired := mexset.deleteExchange(msgID)
if found || expired {
// Record in expiredExchanges if we deleted the exchange.
mexset.expiredExchanges[msgID] = struct{}{}
}
mexset.Unlock()
if expired {
mexset.log.WithFields(LogField{"msgID", msgID}).Info("Exchange expired already")
}
mexset.onRemoved()
}
|
go
|
func (mexset *messageExchangeSet) expireExchange(msgID uint32) {
mexset.log.Debugf(
"Removing %s message exchange %d due to timeout, cancellation or blackhole",
mexset.name,
msgID,
)
mexset.Lock()
// TODO(aniketp): explore if cancel can be called everytime we expire an exchange
found, expired := mexset.deleteExchange(msgID)
if found || expired {
// Record in expiredExchanges if we deleted the exchange.
mexset.expiredExchanges[msgID] = struct{}{}
}
mexset.Unlock()
if expired {
mexset.log.WithFields(LogField{"msgID", msgID}).Info("Exchange expired already")
}
mexset.onRemoved()
}
|
[
"func",
"(",
"mexset",
"*",
"messageExchangeSet",
")",
"expireExchange",
"(",
"msgID",
"uint32",
")",
"{",
"mexset",
".",
"log",
".",
"Debugf",
"(",
"\"Removing %s message exchange %d due to timeout, cancellation or blackhole\"",
",",
"mexset",
".",
"name",
",",
"msgID",
",",
")",
"\n",
"mexset",
".",
"Lock",
"(",
")",
"\n",
"found",
",",
"expired",
":=",
"mexset",
".",
"deleteExchange",
"(",
"msgID",
")",
"\n",
"if",
"found",
"||",
"expired",
"{",
"mexset",
".",
"expiredExchanges",
"[",
"msgID",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"mexset",
".",
"Unlock",
"(",
")",
"\n",
"if",
"expired",
"{",
"mexset",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"msgID\"",
",",
"msgID",
"}",
")",
".",
"Info",
"(",
"\"Exchange expired already\"",
")",
"\n",
"}",
"\n",
"mexset",
".",
"onRemoved",
"(",
")",
"\n",
"}"
] |
// expireExchange is similar to removeExchange, but it marks the exchange as
// expired.
|
[
"expireExchange",
"is",
"similar",
"to",
"removeExchange",
"but",
"it",
"marks",
"the",
"exchange",
"as",
"expired",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L385-L406
|
test
|
uber/tchannel-go
|
mex.go
|
forwardPeerFrame
|
func (mexset *messageExchangeSet) forwardPeerFrame(frame *Frame) error {
if mexset.log.Enabled(LogLevelDebug) {
mexset.log.Debugf("forwarding %s %s", mexset.name, frame.Header)
}
mexset.RLock()
mex := mexset.exchanges[frame.Header.ID]
mexset.RUnlock()
if mex == nil {
// This is ok since the exchange might have expired or been cancelled
mexset.log.WithFields(
LogField{"frameHeader", frame.Header.String()},
LogField{"exchange", mexset.name},
).Info("Received frame for unknown message exchange.")
return nil
}
if err := mex.forwardPeerFrame(frame); err != nil {
mexset.log.WithFields(
LogField{"frameHeader", frame.Header.String()},
LogField{"frameSize", frame.Header.FrameSize()},
LogField{"exchange", mexset.name},
ErrField(err),
).Info("Failed to forward frame.")
return err
}
return nil
}
|
go
|
func (mexset *messageExchangeSet) forwardPeerFrame(frame *Frame) error {
if mexset.log.Enabled(LogLevelDebug) {
mexset.log.Debugf("forwarding %s %s", mexset.name, frame.Header)
}
mexset.RLock()
mex := mexset.exchanges[frame.Header.ID]
mexset.RUnlock()
if mex == nil {
// This is ok since the exchange might have expired or been cancelled
mexset.log.WithFields(
LogField{"frameHeader", frame.Header.String()},
LogField{"exchange", mexset.name},
).Info("Received frame for unknown message exchange.")
return nil
}
if err := mex.forwardPeerFrame(frame); err != nil {
mexset.log.WithFields(
LogField{"frameHeader", frame.Header.String()},
LogField{"frameSize", frame.Header.FrameSize()},
LogField{"exchange", mexset.name},
ErrField(err),
).Info("Failed to forward frame.")
return err
}
return nil
}
|
[
"func",
"(",
"mexset",
"*",
"messageExchangeSet",
")",
"forwardPeerFrame",
"(",
"frame",
"*",
"Frame",
")",
"error",
"{",
"if",
"mexset",
".",
"log",
".",
"Enabled",
"(",
"LogLevelDebug",
")",
"{",
"mexset",
".",
"log",
".",
"Debugf",
"(",
"\"forwarding %s %s\"",
",",
"mexset",
".",
"name",
",",
"frame",
".",
"Header",
")",
"\n",
"}",
"\n",
"mexset",
".",
"RLock",
"(",
")",
"\n",
"mex",
":=",
"mexset",
".",
"exchanges",
"[",
"frame",
".",
"Header",
".",
"ID",
"]",
"\n",
"mexset",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"mex",
"==",
"nil",
"{",
"mexset",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"frameHeader\"",
",",
"frame",
".",
"Header",
".",
"String",
"(",
")",
"}",
",",
"LogField",
"{",
"\"exchange\"",
",",
"mexset",
".",
"name",
"}",
",",
")",
".",
"Info",
"(",
"\"Received frame for unknown message exchange.\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"mex",
".",
"forwardPeerFrame",
"(",
"frame",
")",
";",
"err",
"!=",
"nil",
"{",
"mexset",
".",
"log",
".",
"WithFields",
"(",
"LogField",
"{",
"\"frameHeader\"",
",",
"frame",
".",
"Header",
".",
"String",
"(",
")",
"}",
",",
"LogField",
"{",
"\"frameSize\"",
",",
"frame",
".",
"Header",
".",
"FrameSize",
"(",
")",
"}",
",",
"LogField",
"{",
"\"exchange\"",
",",
"mexset",
".",
"name",
"}",
",",
"ErrField",
"(",
"err",
")",
",",
")",
".",
"Info",
"(",
"\"Failed to forward frame.\"",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// forwardPeerFrame forwards a frame from the peer to the appropriate message
// exchange
|
[
"forwardPeerFrame",
"forwards",
"a",
"frame",
"from",
"the",
"peer",
"to",
"the",
"appropriate",
"message",
"exchange"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L418-L447
|
test
|
uber/tchannel-go
|
mex.go
|
copyExchanges
|
func (mexset *messageExchangeSet) copyExchanges() (shutdown bool, exchanges map[uint32]*messageExchange) {
if mexset.shutdown {
return true, nil
}
exchangesCopy := make(map[uint32]*messageExchange, len(mexset.exchanges))
for k, mex := range mexset.exchanges {
exchangesCopy[k] = mex
}
return false, exchangesCopy
}
|
go
|
func (mexset *messageExchangeSet) copyExchanges() (shutdown bool, exchanges map[uint32]*messageExchange) {
if mexset.shutdown {
return true, nil
}
exchangesCopy := make(map[uint32]*messageExchange, len(mexset.exchanges))
for k, mex := range mexset.exchanges {
exchangesCopy[k] = mex
}
return false, exchangesCopy
}
|
[
"func",
"(",
"mexset",
"*",
"messageExchangeSet",
")",
"copyExchanges",
"(",
")",
"(",
"shutdown",
"bool",
",",
"exchanges",
"map",
"[",
"uint32",
"]",
"*",
"messageExchange",
")",
"{",
"if",
"mexset",
".",
"shutdown",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"exchangesCopy",
":=",
"make",
"(",
"map",
"[",
"uint32",
"]",
"*",
"messageExchange",
",",
"len",
"(",
"mexset",
".",
"exchanges",
")",
")",
"\n",
"for",
"k",
",",
"mex",
":=",
"range",
"mexset",
".",
"exchanges",
"{",
"exchangesCopy",
"[",
"k",
"]",
"=",
"mex",
"\n",
"}",
"\n",
"return",
"false",
",",
"exchangesCopy",
"\n",
"}"
] |
// copyExchanges returns a copy of the exchanges if the exchange is active.
// The caller must lock the mexset.
|
[
"copyExchanges",
"returns",
"a",
"copy",
"of",
"the",
"exchanges",
"if",
"the",
"exchange",
"is",
"active",
".",
"The",
"caller",
"must",
"lock",
"the",
"mexset",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L451-L462
|
test
|
uber/tchannel-go
|
mex.go
|
stopExchanges
|
func (mexset *messageExchangeSet) stopExchanges(err error) {
if mexset.log.Enabled(LogLevelDebug) {
mexset.log.Debugf("stopping %v exchanges due to error: %v", mexset.count(), err)
}
mexset.Lock()
shutdown, exchanges := mexset.copyExchanges()
mexset.shutdown = true
mexset.Unlock()
if shutdown {
mexset.log.Debugf("mexset has already been shutdown")
return
}
for _, mex := range exchanges {
// When there's a connection failure, we want to notify blocked callers that the
// call will fail, but we don't want to shutdown the exchange as only the
// arg reader/writer should shutdown the exchange. Otherwise, our guarantee
// on sendChRefs that there's no references to sendCh is violated since
// readers/writers could still have a reference to sendCh even though
// we shutdown the exchange and called Done on sendChRefs.
if mex.errChNotified.CAS(false, true) {
mex.errCh.Notify(err)
}
}
}
|
go
|
func (mexset *messageExchangeSet) stopExchanges(err error) {
if mexset.log.Enabled(LogLevelDebug) {
mexset.log.Debugf("stopping %v exchanges due to error: %v", mexset.count(), err)
}
mexset.Lock()
shutdown, exchanges := mexset.copyExchanges()
mexset.shutdown = true
mexset.Unlock()
if shutdown {
mexset.log.Debugf("mexset has already been shutdown")
return
}
for _, mex := range exchanges {
// When there's a connection failure, we want to notify blocked callers that the
// call will fail, but we don't want to shutdown the exchange as only the
// arg reader/writer should shutdown the exchange. Otherwise, our guarantee
// on sendChRefs that there's no references to sendCh is violated since
// readers/writers could still have a reference to sendCh even though
// we shutdown the exchange and called Done on sendChRefs.
if mex.errChNotified.CAS(false, true) {
mex.errCh.Notify(err)
}
}
}
|
[
"func",
"(",
"mexset",
"*",
"messageExchangeSet",
")",
"stopExchanges",
"(",
"err",
"error",
")",
"{",
"if",
"mexset",
".",
"log",
".",
"Enabled",
"(",
"LogLevelDebug",
")",
"{",
"mexset",
".",
"log",
".",
"Debugf",
"(",
"\"stopping %v exchanges due to error: %v\"",
",",
"mexset",
".",
"count",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"mexset",
".",
"Lock",
"(",
")",
"\n",
"shutdown",
",",
"exchanges",
":=",
"mexset",
".",
"copyExchanges",
"(",
")",
"\n",
"mexset",
".",
"shutdown",
"=",
"true",
"\n",
"mexset",
".",
"Unlock",
"(",
")",
"\n",
"if",
"shutdown",
"{",
"mexset",
".",
"log",
".",
"Debugf",
"(",
"\"mexset has already been shutdown\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"mex",
":=",
"range",
"exchanges",
"{",
"if",
"mex",
".",
"errChNotified",
".",
"CAS",
"(",
"false",
",",
"true",
")",
"{",
"mex",
".",
"errCh",
".",
"Notify",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// stopExchanges stops all message exchanges to unblock all waiters on the mex.
// This should only be called on connection failures.
|
[
"stopExchanges",
"stops",
"all",
"message",
"exchanges",
"to",
"unblock",
"all",
"waiters",
"on",
"the",
"mex",
".",
"This",
"should",
"only",
"be",
"called",
"on",
"connection",
"failures",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/mex.go#L466-L492
|
test
|
uber/tchannel-go
|
frame.go
|
NewFrame
|
func NewFrame(payloadCapacity int) *Frame {
f := &Frame{}
f.buffer = make([]byte, payloadCapacity+FrameHeaderSize)
f.Payload = f.buffer[FrameHeaderSize:]
f.headerBuffer = f.buffer[:FrameHeaderSize]
return f
}
|
go
|
func NewFrame(payloadCapacity int) *Frame {
f := &Frame{}
f.buffer = make([]byte, payloadCapacity+FrameHeaderSize)
f.Payload = f.buffer[FrameHeaderSize:]
f.headerBuffer = f.buffer[:FrameHeaderSize]
return f
}
|
[
"func",
"NewFrame",
"(",
"payloadCapacity",
"int",
")",
"*",
"Frame",
"{",
"f",
":=",
"&",
"Frame",
"{",
"}",
"\n",
"f",
".",
"buffer",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"payloadCapacity",
"+",
"FrameHeaderSize",
")",
"\n",
"f",
".",
"Payload",
"=",
"f",
".",
"buffer",
"[",
"FrameHeaderSize",
":",
"]",
"\n",
"f",
".",
"headerBuffer",
"=",
"f",
".",
"buffer",
"[",
":",
"FrameHeaderSize",
"]",
"\n",
"return",
"f",
"\n",
"}"
] |
// NewFrame allocates a new frame with the given payload capacity
|
[
"NewFrame",
"allocates",
"a",
"new",
"frame",
"with",
"the",
"given",
"payload",
"capacity"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/frame.go#L119-L125
|
test
|
uber/tchannel-go
|
frame.go
|
ReadBody
|
func (f *Frame) ReadBody(header []byte, r io.Reader) error {
// Copy the header into the underlying buffer so we have an assembled frame
// that can be directly forwarded.
copy(f.buffer, header)
// Parse the header into our typed struct.
if err := f.Header.read(typed.NewReadBuffer(header)); err != nil {
return err
}
switch payloadSize := f.Header.PayloadSize(); {
case payloadSize > MaxFramePayloadSize:
return fmt.Errorf("invalid frame size %v", f.Header.size)
case payloadSize > 0:
_, err := io.ReadFull(r, f.SizedPayload())
return err
default:
// No payload to read
return nil
}
}
|
go
|
func (f *Frame) ReadBody(header []byte, r io.Reader) error {
// Copy the header into the underlying buffer so we have an assembled frame
// that can be directly forwarded.
copy(f.buffer, header)
// Parse the header into our typed struct.
if err := f.Header.read(typed.NewReadBuffer(header)); err != nil {
return err
}
switch payloadSize := f.Header.PayloadSize(); {
case payloadSize > MaxFramePayloadSize:
return fmt.Errorf("invalid frame size %v", f.Header.size)
case payloadSize > 0:
_, err := io.ReadFull(r, f.SizedPayload())
return err
default:
// No payload to read
return nil
}
}
|
[
"func",
"(",
"f",
"*",
"Frame",
")",
"ReadBody",
"(",
"header",
"[",
"]",
"byte",
",",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"copy",
"(",
"f",
".",
"buffer",
",",
"header",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"Header",
".",
"read",
"(",
"typed",
".",
"NewReadBuffer",
"(",
"header",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"switch",
"payloadSize",
":=",
"f",
".",
"Header",
".",
"PayloadSize",
"(",
")",
";",
"{",
"case",
"payloadSize",
">",
"MaxFramePayloadSize",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"invalid frame size %v\"",
",",
"f",
".",
"Header",
".",
"size",
")",
"\n",
"case",
"payloadSize",
">",
"0",
":",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"r",
",",
"f",
".",
"SizedPayload",
"(",
")",
")",
"\n",
"return",
"err",
"\n",
"default",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] |
// ReadBody takes in a previously read frame header, and only reads in the body
// based on the size specified in the header. This allows callers to defer
// the frame allocation till the body needs to be read.
|
[
"ReadBody",
"takes",
"in",
"a",
"previously",
"read",
"frame",
"header",
"and",
"only",
"reads",
"in",
"the",
"body",
"based",
"on",
"the",
"size",
"specified",
"in",
"the",
"header",
".",
"This",
"allows",
"callers",
"to",
"defer",
"the",
"frame",
"allocation",
"till",
"the",
"body",
"needs",
"to",
"be",
"read",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/frame.go#L130-L150
|
test
|
uber/tchannel-go
|
frame.go
|
WriteOut
|
func (f *Frame) WriteOut(w io.Writer) error {
var wbuf typed.WriteBuffer
wbuf.Wrap(f.headerBuffer)
if err := f.Header.write(&wbuf); err != nil {
return err
}
fullFrame := f.buffer[:f.Header.FrameSize()]
if _, err := w.Write(fullFrame); err != nil {
return err
}
return nil
}
|
go
|
func (f *Frame) WriteOut(w io.Writer) error {
var wbuf typed.WriteBuffer
wbuf.Wrap(f.headerBuffer)
if err := f.Header.write(&wbuf); err != nil {
return err
}
fullFrame := f.buffer[:f.Header.FrameSize()]
if _, err := w.Write(fullFrame); err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Frame",
")",
"WriteOut",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"var",
"wbuf",
"typed",
".",
"WriteBuffer",
"\n",
"wbuf",
".",
"Wrap",
"(",
"f",
".",
"headerBuffer",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"Header",
".",
"write",
"(",
"&",
"wbuf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fullFrame",
":=",
"f",
".",
"buffer",
"[",
":",
"f",
".",
"Header",
".",
"FrameSize",
"(",
")",
"]",
"\n",
"if",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"fullFrame",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// WriteOut writes the frame to the given io.Writer
|
[
"WriteOut",
"writes",
"the",
"frame",
"to",
"the",
"given",
"io",
".",
"Writer"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/frame.go#L165-L179
|
test
|
uber/tchannel-go
|
retry.go
|
CanRetry
|
func (r RetryOn) CanRetry(err error) bool {
if r == RetryNever {
return false
}
if r == RetryDefault {
r = RetryConnectionError
}
code := getErrCode(err)
if code == ErrCodeBusy || code == ErrCodeDeclined {
return true
}
// Never retry bad requests, since it will probably cause another bad request.
if code == ErrCodeBadRequest {
return false
}
switch r {
case RetryConnectionError:
return code == ErrCodeNetwork
case RetryUnexpected:
return code == ErrCodeUnexpected
case RetryIdempotent:
return true
}
return false
}
|
go
|
func (r RetryOn) CanRetry(err error) bool {
if r == RetryNever {
return false
}
if r == RetryDefault {
r = RetryConnectionError
}
code := getErrCode(err)
if code == ErrCodeBusy || code == ErrCodeDeclined {
return true
}
// Never retry bad requests, since it will probably cause another bad request.
if code == ErrCodeBadRequest {
return false
}
switch r {
case RetryConnectionError:
return code == ErrCodeNetwork
case RetryUnexpected:
return code == ErrCodeUnexpected
case RetryIdempotent:
return true
}
return false
}
|
[
"func",
"(",
"r",
"RetryOn",
")",
"CanRetry",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"r",
"==",
"RetryNever",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"r",
"==",
"RetryDefault",
"{",
"r",
"=",
"RetryConnectionError",
"\n",
"}",
"\n",
"code",
":=",
"getErrCode",
"(",
"err",
")",
"\n",
"if",
"code",
"==",
"ErrCodeBusy",
"||",
"code",
"==",
"ErrCodeDeclined",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"code",
"==",
"ErrCodeBadRequest",
"{",
"return",
"false",
"\n",
"}",
"\n",
"switch",
"r",
"{",
"case",
"RetryConnectionError",
":",
"return",
"code",
"==",
"ErrCodeNetwork",
"\n",
"case",
"RetryUnexpected",
":",
"return",
"code",
"==",
"ErrCodeUnexpected",
"\n",
"case",
"RetryIdempotent",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// CanRetry returns whether an error can be retried for the given retry option.
|
[
"CanRetry",
"returns",
"whether",
"an",
"error",
"can",
"be",
"retried",
"for",
"the",
"given",
"retry",
"option",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/retry.go#L89-L117
|
test
|
uber/tchannel-go
|
retry.go
|
HasRetries
|
func (rs *RequestState) HasRetries(err error) bool {
if rs == nil {
return false
}
rOpts := rs.retryOpts
return rs.Attempt < rOpts.MaxAttempts && rOpts.RetryOn.CanRetry(err)
}
|
go
|
func (rs *RequestState) HasRetries(err error) bool {
if rs == nil {
return false
}
rOpts := rs.retryOpts
return rs.Attempt < rOpts.MaxAttempts && rOpts.RetryOn.CanRetry(err)
}
|
[
"func",
"(",
"rs",
"*",
"RequestState",
")",
"HasRetries",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"rs",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"rOpts",
":=",
"rs",
".",
"retryOpts",
"\n",
"return",
"rs",
".",
"Attempt",
"<",
"rOpts",
".",
"MaxAttempts",
"&&",
"rOpts",
".",
"RetryOn",
".",
"CanRetry",
"(",
"err",
")",
"\n",
"}"
] |
// HasRetries will return true if there are more retries left.
|
[
"HasRetries",
"will",
"return",
"true",
"if",
"there",
"are",
"more",
"retries",
"left",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/retry.go#L159-L165
|
test
|
uber/tchannel-go
|
retry.go
|
SinceStart
|
func (rs *RequestState) SinceStart(now time.Time, fallback time.Duration) time.Duration {
if rs == nil {
return fallback
}
return now.Sub(rs.Start)
}
|
go
|
func (rs *RequestState) SinceStart(now time.Time, fallback time.Duration) time.Duration {
if rs == nil {
return fallback
}
return now.Sub(rs.Start)
}
|
[
"func",
"(",
"rs",
"*",
"RequestState",
")",
"SinceStart",
"(",
"now",
"time",
".",
"Time",
",",
"fallback",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"if",
"rs",
"==",
"nil",
"{",
"return",
"fallback",
"\n",
"}",
"\n",
"return",
"now",
".",
"Sub",
"(",
"rs",
".",
"Start",
")",
"\n",
"}"
] |
// SinceStart returns the time since the start of the request. If there is no request state,
// then the fallback is returned.
|
[
"SinceStart",
"returns",
"the",
"time",
"since",
"the",
"start",
"of",
"the",
"request",
".",
"If",
"there",
"is",
"no",
"request",
"state",
"then",
"the",
"fallback",
"is",
"returned",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/retry.go#L169-L174
|
test
|
uber/tchannel-go
|
retry.go
|
AddSelectedPeer
|
func (rs *RequestState) AddSelectedPeer(hostPort string) {
if rs == nil {
return
}
host := getHost(hostPort)
if rs.SelectedPeers == nil {
rs.SelectedPeers = map[string]struct{}{
hostPort: {},
host: {},
}
} else {
rs.SelectedPeers[hostPort] = struct{}{}
rs.SelectedPeers[host] = struct{}{}
}
}
|
go
|
func (rs *RequestState) AddSelectedPeer(hostPort string) {
if rs == nil {
return
}
host := getHost(hostPort)
if rs.SelectedPeers == nil {
rs.SelectedPeers = map[string]struct{}{
hostPort: {},
host: {},
}
} else {
rs.SelectedPeers[hostPort] = struct{}{}
rs.SelectedPeers[host] = struct{}{}
}
}
|
[
"func",
"(",
"rs",
"*",
"RequestState",
")",
"AddSelectedPeer",
"(",
"hostPort",
"string",
")",
"{",
"if",
"rs",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"host",
":=",
"getHost",
"(",
"hostPort",
")",
"\n",
"if",
"rs",
".",
"SelectedPeers",
"==",
"nil",
"{",
"rs",
".",
"SelectedPeers",
"=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"hostPort",
":",
"{",
"}",
",",
"host",
":",
"{",
"}",
",",
"}",
"\n",
"}",
"else",
"{",
"rs",
".",
"SelectedPeers",
"[",
"hostPort",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"rs",
".",
"SelectedPeers",
"[",
"host",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"}"
] |
// AddSelectedPeer adds a given peer to the set of selected peers.
|
[
"AddSelectedPeer",
"adds",
"a",
"given",
"peer",
"to",
"the",
"set",
"of",
"selected",
"peers",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/retry.go#L185-L200
|
test
|
uber/tchannel-go
|
retry.go
|
RunWithRetry
|
func (ch *Channel) RunWithRetry(runCtx context.Context, f RetriableFunc) error {
var err error
opts := getRetryOptions(runCtx)
rs := ch.getRequestState(opts)
defer requestStatePool.Put(rs)
for i := 0; i < opts.MaxAttempts; i++ {
rs.Attempt++
if opts.TimeoutPerAttempt == 0 {
err = f(runCtx, rs)
} else {
attemptCtx, cancel := context.WithTimeout(runCtx, opts.TimeoutPerAttempt)
err = f(attemptCtx, rs)
cancel()
}
if err == nil {
return nil
}
if !opts.RetryOn.CanRetry(err) {
if ch.log.Enabled(LogLevelInfo) {
ch.log.WithFields(ErrField(err)).Info("Failed after non-retriable error.")
}
return err
}
ch.log.WithFields(
ErrField(err),
LogField{"attempt", rs.Attempt},
LogField{"maxAttempts", opts.MaxAttempts},
).Info("Retrying request after retryable error.")
}
// Too many retries, return the last error
return err
}
|
go
|
func (ch *Channel) RunWithRetry(runCtx context.Context, f RetriableFunc) error {
var err error
opts := getRetryOptions(runCtx)
rs := ch.getRequestState(opts)
defer requestStatePool.Put(rs)
for i := 0; i < opts.MaxAttempts; i++ {
rs.Attempt++
if opts.TimeoutPerAttempt == 0 {
err = f(runCtx, rs)
} else {
attemptCtx, cancel := context.WithTimeout(runCtx, opts.TimeoutPerAttempt)
err = f(attemptCtx, rs)
cancel()
}
if err == nil {
return nil
}
if !opts.RetryOn.CanRetry(err) {
if ch.log.Enabled(LogLevelInfo) {
ch.log.WithFields(ErrField(err)).Info("Failed after non-retriable error.")
}
return err
}
ch.log.WithFields(
ErrField(err),
LogField{"attempt", rs.Attempt},
LogField{"maxAttempts", opts.MaxAttempts},
).Info("Retrying request after retryable error.")
}
// Too many retries, return the last error
return err
}
|
[
"func",
"(",
"ch",
"*",
"Channel",
")",
"RunWithRetry",
"(",
"runCtx",
"context",
".",
"Context",
",",
"f",
"RetriableFunc",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"opts",
":=",
"getRetryOptions",
"(",
"runCtx",
")",
"\n",
"rs",
":=",
"ch",
".",
"getRequestState",
"(",
"opts",
")",
"\n",
"defer",
"requestStatePool",
".",
"Put",
"(",
"rs",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"opts",
".",
"MaxAttempts",
";",
"i",
"++",
"{",
"rs",
".",
"Attempt",
"++",
"\n",
"if",
"opts",
".",
"TimeoutPerAttempt",
"==",
"0",
"{",
"err",
"=",
"f",
"(",
"runCtx",
",",
"rs",
")",
"\n",
"}",
"else",
"{",
"attemptCtx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"runCtx",
",",
"opts",
".",
"TimeoutPerAttempt",
")",
"\n",
"err",
"=",
"f",
"(",
"attemptCtx",
",",
"rs",
")",
"\n",
"cancel",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"opts",
".",
"RetryOn",
".",
"CanRetry",
"(",
"err",
")",
"{",
"if",
"ch",
".",
"log",
".",
"Enabled",
"(",
"LogLevelInfo",
")",
"{",
"ch",
".",
"log",
".",
"WithFields",
"(",
"ErrField",
"(",
"err",
")",
")",
".",
"Info",
"(",
"\"Failed after non-retriable error.\"",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"ch",
".",
"log",
".",
"WithFields",
"(",
"ErrField",
"(",
"err",
")",
",",
"LogField",
"{",
"\"attempt\"",
",",
"rs",
".",
"Attempt",
"}",
",",
"LogField",
"{",
"\"maxAttempts\"",
",",
"opts",
".",
"MaxAttempts",
"}",
",",
")",
".",
"Info",
"(",
"\"Retrying request after retryable error.\"",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// RunWithRetry will take a function that makes the TChannel call, and will
// rerun it as specifed in the RetryOptions in the Context.
|
[
"RunWithRetry",
"will",
"take",
"a",
"function",
"that",
"makes",
"the",
"TChannel",
"call",
"and",
"will",
"rerun",
"it",
"as",
"specifed",
"in",
"the",
"RetryOptions",
"in",
"the",
"Context",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/retry.go#L212-L249
|
test
|
uber/tchannel-go
|
checksum.go
|
ChecksumSize
|
func (t ChecksumType) ChecksumSize() int {
switch t {
case ChecksumTypeNone:
return 0
case ChecksumTypeCrc32, ChecksumTypeCrc32C:
return crc32.Size
case ChecksumTypeFarmhash:
return 4
default:
return 0
}
}
|
go
|
func (t ChecksumType) ChecksumSize() int {
switch t {
case ChecksumTypeNone:
return 0
case ChecksumTypeCrc32, ChecksumTypeCrc32C:
return crc32.Size
case ChecksumTypeFarmhash:
return 4
default:
return 0
}
}
|
[
"func",
"(",
"t",
"ChecksumType",
")",
"ChecksumSize",
"(",
")",
"int",
"{",
"switch",
"t",
"{",
"case",
"ChecksumTypeNone",
":",
"return",
"0",
"\n",
"case",
"ChecksumTypeCrc32",
",",
"ChecksumTypeCrc32C",
":",
"return",
"crc32",
".",
"Size",
"\n",
"case",
"ChecksumTypeFarmhash",
":",
"return",
"4",
"\n",
"default",
":",
"return",
"0",
"\n",
"}",
"\n",
"}"
] |
// ChecksumSize returns the size in bytes of the checksum calculation
|
[
"ChecksumSize",
"returns",
"the",
"size",
"in",
"bytes",
"of",
"the",
"checksum",
"calculation"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/checksum.go#L70-L81
|
test
|
uber/tchannel-go
|
checksum.go
|
New
|
func (t ChecksumType) New() Checksum {
s := t.pool().Get().(Checksum)
s.Reset()
return s
}
|
go
|
func (t ChecksumType) New() Checksum {
s := t.pool().Get().(Checksum)
s.Reset()
return s
}
|
[
"func",
"(",
"t",
"ChecksumType",
")",
"New",
"(",
")",
"Checksum",
"{",
"s",
":=",
"t",
".",
"pool",
"(",
")",
".",
"Get",
"(",
")",
".",
"(",
"Checksum",
")",
"\n",
"s",
".",
"Reset",
"(",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// New creates a new Checksum of the given type
|
[
"New",
"creates",
"a",
"new",
"Checksum",
"of",
"the",
"given",
"type"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/checksum.go#L89-L93
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/main.go
|
parseTemplates
|
func parseTemplates(skipTChannel bool, templateFiles []string) ([]*Template, error) {
var templates []*Template
if !skipTChannel {
templates = append(templates, &Template{
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
}
|
go
|
func parseTemplates(skipTChannel bool, templateFiles []string) ([]*Template, error) {
var templates []*Template
if !skipTChannel {
templates = append(templates, &Template{
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
}
|
[
"func",
"parseTemplates",
"(",
"skipTChannel",
"bool",
",",
"templateFiles",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"Template",
",",
"error",
")",
"{",
"var",
"templates",
"[",
"]",
"*",
"Template",
"\n",
"if",
"!",
"skipTChannel",
"{",
"templates",
"=",
"append",
"(",
"templates",
",",
"&",
"Template",
"{",
"name",
":",
"\"tchan\"",
",",
"template",
":",
"template",
".",
"Must",
"(",
"parseTemplate",
"(",
"tchannelTmpl",
")",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"templateFiles",
"{",
"t",
",",
"err",
":=",
"parseTemplateFile",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"templates",
"=",
"append",
"(",
"templates",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"templates",
",",
"nil",
"\n",
"}"
] |
// parseTemplates returns a list of Templates that must be rendered given the template files.
|
[
"parseTemplates",
"returns",
"a",
"list",
"of",
"Templates",
"that",
"must",
"be",
"rendered",
"given",
"the",
"template",
"files",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/main.go#L139-L159
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/main.go
|
NewStringSliceFlag
|
func NewStringSliceFlag(name string, usage string) *[]string {
var ss stringSliceFlag
flag.Var(&ss, name, usage)
return (*[]string)(&ss)
}
|
go
|
func NewStringSliceFlag(name string, usage string) *[]string {
var ss stringSliceFlag
flag.Var(&ss, name, usage)
return (*[]string)(&ss)
}
|
[
"func",
"NewStringSliceFlag",
"(",
"name",
"string",
",",
"usage",
"string",
")",
"*",
"[",
"]",
"string",
"{",
"var",
"ss",
"stringSliceFlag",
"\n",
"flag",
".",
"Var",
"(",
"&",
"ss",
",",
"name",
",",
"usage",
")",
"\n",
"return",
"(",
"*",
"[",
"]",
"string",
")",
"(",
"&",
"ss",
")",
"\n",
"}"
] |
// NewStringSliceFlag creates a new string slice flag. The default value is always nil.
|
[
"NewStringSliceFlag",
"creates",
"a",
"new",
"string",
"slice",
"flag",
".",
"The",
"default",
"value",
"is",
"always",
"nil",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/main.go#L232-L236
|
test
|
uber/tchannel-go
|
thrift/thrift-gen/template.go
|
withStateFuncs
|
func (t *Template) withStateFuncs(td TemplateData) *template.Template {
return t.template.Funcs(map[string]interface{}{
"goType": td.global.goType,
})
}
|
go
|
func (t *Template) withStateFuncs(td TemplateData) *template.Template {
return t.template.Funcs(map[string]interface{}{
"goType": td.global.goType,
})
}
|
[
"func",
"(",
"t",
"*",
"Template",
")",
"withStateFuncs",
"(",
"td",
"TemplateData",
")",
"*",
"template",
".",
"Template",
"{",
"return",
"t",
".",
"template",
".",
"Funcs",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"goType\"",
":",
"td",
".",
"global",
".",
"goType",
",",
"}",
")",
"\n",
"}"
] |
// withStateFuncs adds functions to the template that are dependent upon state.
|
[
"withStateFuncs",
"adds",
"functions",
"to",
"the",
"template",
"that",
"are",
"dependent",
"upon",
"state",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/thrift/thrift-gen/template.go#L87-L91
|
test
|
uber/tchannel-go
|
introspection.go
|
IntrospectOthers
|
func (ch *Channel) IntrospectOthers(opts *IntrospectionOptions) map[string][]ChannelInfo {
if !opts.IncludeOtherChannels {
return nil
}
channelMap.Lock()
defer channelMap.Unlock()
states := make(map[string][]ChannelInfo)
for svc, channels := range channelMap.existing {
channelInfos := make([]ChannelInfo, 0, len(channels))
for _, otherChan := range channels {
if ch == otherChan {
continue
}
channelInfos = append(channelInfos, otherChan.ReportInfo(opts))
}
states[svc] = channelInfos
}
return states
}
|
go
|
func (ch *Channel) IntrospectOthers(opts *IntrospectionOptions) map[string][]ChannelInfo {
if !opts.IncludeOtherChannels {
return nil
}
channelMap.Lock()
defer channelMap.Unlock()
states := make(map[string][]ChannelInfo)
for svc, channels := range channelMap.existing {
channelInfos := make([]ChannelInfo, 0, len(channels))
for _, otherChan := range channels {
if ch == otherChan {
continue
}
channelInfos = append(channelInfos, otherChan.ReportInfo(opts))
}
states[svc] = channelInfos
}
return states
}
|
[
"func",
"(",
"ch",
"*",
"Channel",
")",
"IntrospectOthers",
"(",
"opts",
"*",
"IntrospectionOptions",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"ChannelInfo",
"{",
"if",
"!",
"opts",
".",
"IncludeOtherChannels",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"channelMap",
".",
"Lock",
"(",
")",
"\n",
"defer",
"channelMap",
".",
"Unlock",
"(",
")",
"\n",
"states",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"ChannelInfo",
")",
"\n",
"for",
"svc",
",",
"channels",
":=",
"range",
"channelMap",
".",
"existing",
"{",
"channelInfos",
":=",
"make",
"(",
"[",
"]",
"ChannelInfo",
",",
"0",
",",
"len",
"(",
"channels",
")",
")",
"\n",
"for",
"_",
",",
"otherChan",
":=",
"range",
"channels",
"{",
"if",
"ch",
"==",
"otherChan",
"{",
"continue",
"\n",
"}",
"\n",
"channelInfos",
"=",
"append",
"(",
"channelInfos",
",",
"otherChan",
".",
"ReportInfo",
"(",
"opts",
")",
")",
"\n",
"}",
"\n",
"states",
"[",
"svc",
"]",
"=",
"channelInfos",
"\n",
"}",
"\n",
"return",
"states",
"\n",
"}"
] |
// IntrospectOthers returns the ChannelInfo for all other channels in this process.
|
[
"IntrospectOthers",
"returns",
"the",
"ChannelInfo",
"for",
"all",
"other",
"channels",
"in",
"this",
"process",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/introspection.go#L244-L265
|
test
|
uber/tchannel-go
|
introspection.go
|
ReportInfo
|
func (ch *Channel) ReportInfo(opts *IntrospectionOptions) ChannelInfo {
return ChannelInfo{
ID: ch.chID,
CreatedStack: ch.createdStack,
LocalPeer: ch.PeerInfo(),
}
}
|
go
|
func (ch *Channel) ReportInfo(opts *IntrospectionOptions) ChannelInfo {
return ChannelInfo{
ID: ch.chID,
CreatedStack: ch.createdStack,
LocalPeer: ch.PeerInfo(),
}
}
|
[
"func",
"(",
"ch",
"*",
"Channel",
")",
"ReportInfo",
"(",
"opts",
"*",
"IntrospectionOptions",
")",
"ChannelInfo",
"{",
"return",
"ChannelInfo",
"{",
"ID",
":",
"ch",
".",
"chID",
",",
"CreatedStack",
":",
"ch",
".",
"createdStack",
",",
"LocalPeer",
":",
"ch",
".",
"PeerInfo",
"(",
")",
",",
"}",
"\n",
"}"
] |
// ReportInfo returns ChannelInfo for a channel.
|
[
"ReportInfo",
"returns",
"ChannelInfo",
"for",
"a",
"channel",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/introspection.go#L268-L274
|
test
|
uber/tchannel-go
|
introspection.go
|
IntrospectState
|
func (l *RootPeerList) IntrospectState(opts *IntrospectionOptions) map[string]PeerRuntimeState {
return fromPeerList(l, opts)
}
|
go
|
func (l *RootPeerList) IntrospectState(opts *IntrospectionOptions) map[string]PeerRuntimeState {
return fromPeerList(l, opts)
}
|
[
"func",
"(",
"l",
"*",
"RootPeerList",
")",
"IntrospectState",
"(",
"opts",
"*",
"IntrospectionOptions",
")",
"map",
"[",
"string",
"]",
"PeerRuntimeState",
"{",
"return",
"fromPeerList",
"(",
"l",
",",
"opts",
")",
"\n",
"}"
] |
// IntrospectState returns the runtime state of the
|
[
"IntrospectState",
"returns",
"the",
"runtime",
"state",
"of",
"the"
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/introspection.go#L292-L294
|
test
|
uber/tchannel-go
|
introspection.go
|
IntrospectState
|
func (subChMap *subChannelMap) IntrospectState(opts *IntrospectionOptions) map[string]SubChannelRuntimeState {
m := make(map[string]SubChannelRuntimeState)
subChMap.RLock()
for k, sc := range subChMap.subchannels {
state := SubChannelRuntimeState{
Service: k,
Isolated: sc.Isolated(),
}
if state.Isolated {
state.IsolatedPeers = sc.Peers().IntrospectList(opts)
}
if hmap, ok := sc.handler.(*handlerMap); ok {
state.Handler.Type = methodHandler
methods := make([]string, 0, len(hmap.handlers))
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
}
|
go
|
func (subChMap *subChannelMap) IntrospectState(opts *IntrospectionOptions) map[string]SubChannelRuntimeState {
m := make(map[string]SubChannelRuntimeState)
subChMap.RLock()
for k, sc := range subChMap.subchannels {
state := SubChannelRuntimeState{
Service: k,
Isolated: sc.Isolated(),
}
if state.Isolated {
state.IsolatedPeers = sc.Peers().IntrospectList(opts)
}
if hmap, ok := sc.handler.(*handlerMap); ok {
state.Handler.Type = methodHandler
methods := make([]string, 0, len(hmap.handlers))
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
}
|
[
"func",
"(",
"subChMap",
"*",
"subChannelMap",
")",
"IntrospectState",
"(",
"opts",
"*",
"IntrospectionOptions",
")",
"map",
"[",
"string",
"]",
"SubChannelRuntimeState",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"SubChannelRuntimeState",
")",
"\n",
"subChMap",
".",
"RLock",
"(",
")",
"\n",
"for",
"k",
",",
"sc",
":=",
"range",
"subChMap",
".",
"subchannels",
"{",
"state",
":=",
"SubChannelRuntimeState",
"{",
"Service",
":",
"k",
",",
"Isolated",
":",
"sc",
".",
"Isolated",
"(",
")",
",",
"}",
"\n",
"if",
"state",
".",
"Isolated",
"{",
"state",
".",
"IsolatedPeers",
"=",
"sc",
".",
"Peers",
"(",
")",
".",
"IntrospectList",
"(",
"opts",
")",
"\n",
"}",
"\n",
"if",
"hmap",
",",
"ok",
":=",
"sc",
".",
"handler",
".",
"(",
"*",
"handlerMap",
")",
";",
"ok",
"{",
"state",
".",
"Handler",
".",
"Type",
"=",
"methodHandler",
"\n",
"methods",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"hmap",
".",
"handlers",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"hmap",
".",
"handlers",
"{",
"methods",
"=",
"append",
"(",
"methods",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"methods",
")",
"\n",
"state",
".",
"Handler",
".",
"Methods",
"=",
"methods",
"\n",
"}",
"else",
"{",
"state",
".",
"Handler",
".",
"Type",
"=",
"overrideHandler",
"\n",
"}",
"\n",
"m",
"[",
"k",
"]",
"=",
"state",
"\n",
"}",
"\n",
"subChMap",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"m",
"\n",
"}"
] |
// IntrospectState returns the runtime state of the subchannels.
|
[
"IntrospectState",
"returns",
"the",
"runtime",
"state",
"of",
"the",
"subchannels",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/introspection.go#L297-L323
|
test
|
uber/tchannel-go
|
introspection.go
|
IntrospectState
|
func (p *Peer) IntrospectState(opts *IntrospectionOptions) PeerRuntimeState {
p.RLock()
defer p.RUnlock()
return PeerRuntimeState{
HostPort: p.hostPort,
InboundConnections: getConnectionRuntimeState(p.inboundConnections, opts),
OutboundConnections: getConnectionRuntimeState(p.outboundConnections, opts),
ChosenCount: p.chosenCount.Load(),
SCCount: p.scCount,
}
}
|
go
|
func (p *Peer) IntrospectState(opts *IntrospectionOptions) PeerRuntimeState {
p.RLock()
defer p.RUnlock()
return PeerRuntimeState{
HostPort: p.hostPort,
InboundConnections: getConnectionRuntimeState(p.inboundConnections, opts),
OutboundConnections: getConnectionRuntimeState(p.outboundConnections, opts),
ChosenCount: p.chosenCount.Load(),
SCCount: p.scCount,
}
}
|
[
"func",
"(",
"p",
"*",
"Peer",
")",
"IntrospectState",
"(",
"opts",
"*",
"IntrospectionOptions",
")",
"PeerRuntimeState",
"{",
"p",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"PeerRuntimeState",
"{",
"HostPort",
":",
"p",
".",
"hostPort",
",",
"InboundConnections",
":",
"getConnectionRuntimeState",
"(",
"p",
".",
"inboundConnections",
",",
"opts",
")",
",",
"OutboundConnections",
":",
"getConnectionRuntimeState",
"(",
"p",
".",
"outboundConnections",
",",
"opts",
")",
",",
"ChosenCount",
":",
"p",
".",
"chosenCount",
".",
"Load",
"(",
")",
",",
"SCCount",
":",
"p",
".",
"scCount",
",",
"}",
"\n",
"}"
] |
// IntrospectState returns the runtime state for this peer.
|
[
"IntrospectState",
"returns",
"the",
"runtime",
"state",
"for",
"this",
"peer",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/introspection.go#L336-L347
|
test
|
uber/tchannel-go
|
introspection.go
|
IntrospectState
|
func (c *Connection) IntrospectState(opts *IntrospectionOptions) ConnectionRuntimeState {
c.stateMut.RLock()
defer c.stateMut.RUnlock()
// TODO(prashantv): Add total number of health checks, and health check options.
state := ConnectionRuntimeState{
ID: c.connID,
ConnectionState: c.state.String(),
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
}
|
go
|
func (c *Connection) IntrospectState(opts *IntrospectionOptions) ConnectionRuntimeState {
c.stateMut.RLock()
defer c.stateMut.RUnlock()
// TODO(prashantv): Add total number of health checks, and health check options.
state := ConnectionRuntimeState{
ID: c.connID,
ConnectionState: c.state.String(),
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
}
|
[
"func",
"(",
"c",
"*",
"Connection",
")",
"IntrospectState",
"(",
"opts",
"*",
"IntrospectionOptions",
")",
"ConnectionRuntimeState",
"{",
"c",
".",
"stateMut",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"stateMut",
".",
"RUnlock",
"(",
")",
"\n",
"state",
":=",
"ConnectionRuntimeState",
"{",
"ID",
":",
"c",
".",
"connID",
",",
"ConnectionState",
":",
"c",
".",
"state",
".",
"String",
"(",
")",
",",
"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",
"(",
")",
",",
"}",
"\n",
"if",
"c",
".",
"relay",
"!=",
"nil",
"{",
"state",
".",
"Relayer",
"=",
"c",
".",
"relay",
".",
"IntrospectState",
"(",
"opts",
")",
"\n",
"}",
"\n",
"return",
"state",
"\n",
"}"
] |
// IntrospectState returns the runtime state for this connection.
|
[
"IntrospectState",
"returns",
"the",
"runtime",
"state",
"for",
"this",
"connection",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/introspection.go#L350-L371
|
test
|
uber/tchannel-go
|
introspection.go
|
IntrospectState
|
func (r *Relayer) IntrospectState(opts *IntrospectionOptions) RelayerRuntimeState {
count := r.inbound.Count() + r.outbound.Count()
return RelayerRuntimeState{
Count: count,
InboundItems: r.inbound.IntrospectState(opts, "inbound"),
OutboundItems: r.outbound.IntrospectState(opts, "outbound"),
MaxTimeout: r.maxTimeout,
}
}
|
go
|
func (r *Relayer) IntrospectState(opts *IntrospectionOptions) RelayerRuntimeState {
count := r.inbound.Count() + r.outbound.Count()
return RelayerRuntimeState{
Count: count,
InboundItems: r.inbound.IntrospectState(opts, "inbound"),
OutboundItems: r.outbound.IntrospectState(opts, "outbound"),
MaxTimeout: r.maxTimeout,
}
}
|
[
"func",
"(",
"r",
"*",
"Relayer",
")",
"IntrospectState",
"(",
"opts",
"*",
"IntrospectionOptions",
")",
"RelayerRuntimeState",
"{",
"count",
":=",
"r",
".",
"inbound",
".",
"Count",
"(",
")",
"+",
"r",
".",
"outbound",
".",
"Count",
"(",
")",
"\n",
"return",
"RelayerRuntimeState",
"{",
"Count",
":",
"count",
",",
"InboundItems",
":",
"r",
".",
"inbound",
".",
"IntrospectState",
"(",
"opts",
",",
"\"inbound\"",
")",
",",
"OutboundItems",
":",
"r",
".",
"outbound",
".",
"IntrospectState",
"(",
"opts",
",",
"\"outbound\"",
")",
",",
"MaxTimeout",
":",
"r",
".",
"maxTimeout",
",",
"}",
"\n",
"}"
] |
// IntrospectState returns the runtime state for this relayer.
|
[
"IntrospectState",
"returns",
"the",
"runtime",
"state",
"for",
"this",
"relayer",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/introspection.go#L374-L382
|
test
|
uber/tchannel-go
|
introspection.go
|
IntrospectState
|
func (ri *relayItems) IntrospectState(opts *IntrospectionOptions, name string) RelayItemSetState {
ri.RLock()
defer ri.RUnlock()
setState := RelayItemSetState{
Name: name,
Count: ri.Count(),
}
if opts.IncludeExchanges {
setState.Items = make(map[string]RelayItemState, len(ri.items))
for 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
}
|
go
|
func (ri *relayItems) IntrospectState(opts *IntrospectionOptions, name string) RelayItemSetState {
ri.RLock()
defer ri.RUnlock()
setState := RelayItemSetState{
Name: name,
Count: ri.Count(),
}
if opts.IncludeExchanges {
setState.Items = make(map[string]RelayItemState, len(ri.items))
for 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
}
|
[
"func",
"(",
"ri",
"*",
"relayItems",
")",
"IntrospectState",
"(",
"opts",
"*",
"IntrospectionOptions",
",",
"name",
"string",
")",
"RelayItemSetState",
"{",
"ri",
".",
"RLock",
"(",
")",
"\n",
"defer",
"ri",
".",
"RUnlock",
"(",
")",
"\n",
"setState",
":=",
"RelayItemSetState",
"{",
"Name",
":",
"name",
",",
"Count",
":",
"ri",
".",
"Count",
"(",
")",
",",
"}",
"\n",
"if",
"opts",
".",
"IncludeExchanges",
"{",
"setState",
".",
"Items",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"RelayItemState",
",",
"len",
"(",
"ri",
".",
"items",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"ri",
".",
"items",
"{",
"if",
"!",
"opts",
".",
"IncludeTombstones",
"&&",
"v",
".",
"tomb",
"{",
"continue",
"\n",
"}",
"\n",
"state",
":=",
"RelayItemState",
"{",
"ID",
":",
"k",
",",
"RemapID",
":",
"v",
".",
"remapID",
",",
"DestinationConnectionID",
":",
"v",
".",
"destination",
".",
"conn",
".",
"connID",
",",
"Tomb",
":",
"v",
".",
"tomb",
",",
"}",
"\n",
"setState",
".",
"Items",
"[",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"k",
")",
")",
"]",
"=",
"state",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"setState",
"\n",
"}"
] |
// IntrospectState returns the runtime state for this relayItems.
|
[
"IntrospectState",
"returns",
"the",
"runtime",
"state",
"for",
"this",
"relayItems",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/introspection.go#L385-L410
|
test
|
uber/tchannel-go
|
introspection.go
|
IntrospectState
|
func (mexset *messageExchangeSet) IntrospectState(opts *IntrospectionOptions) ExchangeSetRuntimeState {
mexset.RLock()
setState := ExchangeSetRuntimeState{
Name: mexset.name,
Count: len(mexset.exchanges),
}
if opts.IncludeExchanges {
setState.Exchanges = make(map[string]ExchangeRuntimeState, len(mexset.exchanges))
for k, v := range mexset.exchanges {
state := ExchangeRuntimeState{
ID: k,
MessageType: v.msgType,
}
setState.Exchanges[strconv.Itoa(int(k))] = state
}
}
mexset.RUnlock()
return setState
}
|
go
|
func (mexset *messageExchangeSet) IntrospectState(opts *IntrospectionOptions) ExchangeSetRuntimeState {
mexset.RLock()
setState := ExchangeSetRuntimeState{
Name: mexset.name,
Count: len(mexset.exchanges),
}
if opts.IncludeExchanges {
setState.Exchanges = make(map[string]ExchangeRuntimeState, len(mexset.exchanges))
for k, v := range mexset.exchanges {
state := ExchangeRuntimeState{
ID: k,
MessageType: v.msgType,
}
setState.Exchanges[strconv.Itoa(int(k))] = state
}
}
mexset.RUnlock()
return setState
}
|
[
"func",
"(",
"mexset",
"*",
"messageExchangeSet",
")",
"IntrospectState",
"(",
"opts",
"*",
"IntrospectionOptions",
")",
"ExchangeSetRuntimeState",
"{",
"mexset",
".",
"RLock",
"(",
")",
"\n",
"setState",
":=",
"ExchangeSetRuntimeState",
"{",
"Name",
":",
"mexset",
".",
"name",
",",
"Count",
":",
"len",
"(",
"mexset",
".",
"exchanges",
")",
",",
"}",
"\n",
"if",
"opts",
".",
"IncludeExchanges",
"{",
"setState",
".",
"Exchanges",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"ExchangeRuntimeState",
",",
"len",
"(",
"mexset",
".",
"exchanges",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"mexset",
".",
"exchanges",
"{",
"state",
":=",
"ExchangeRuntimeState",
"{",
"ID",
":",
"k",
",",
"MessageType",
":",
"v",
".",
"msgType",
",",
"}",
"\n",
"setState",
".",
"Exchanges",
"[",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"k",
")",
")",
"]",
"=",
"state",
"\n",
"}",
"\n",
"}",
"\n",
"mexset",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"setState",
"\n",
"}"
] |
// IntrospectState returns the runtime state for this messsage exchange set.
|
[
"IntrospectState",
"returns",
"the",
"runtime",
"state",
"for",
"this",
"messsage",
"exchange",
"set",
"."
] |
3c9ced6d946fe2fec6c915703a533e966c09e07a
|
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/introspection.go#L413-L433
|
test
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.