Source File
types.go
Belonging Package
google.golang.org/grpc/internal/channelz
package channelz
import (
)
getParentID() int64
}
type dummyEntry struct {
idNotFound int64
}
logger.Infof("attempt to add child of type %T with id %d to a parent (id=%d) that doesn't currently exist", , , .idNotFound)
}
logger.Infof("attempt to delete child with id %d from a parent (id=%d) that doesn't currently exist", , .idNotFound)
}
func ( *dummyEntry) () {
logger.Warningf("attempt to delete an entry (id=%d) that doesn't currently exist", .idNotFound)
}
}
func (*dummyEntry) () int64 {
return 0
}
Events []*TraceEvent
}
type Channel interface {
ChannelzMetric() *ChannelInternalMetric
}
type dummyChannel struct{}
func ( *dummyChannel) () *ChannelInternalMetric {
return &ChannelInternalMetric{}
}
type channel struct {
refName string
c Channel
closeCalled bool
nestedChans map[int64]string
subChans map[int64]string
id int64
pid int64
cm *channelMap
traceRefCount int32
}
func ( *channel) ( int64, entry) {
switch v := .(type) {
case *subChannel:
.subChans[] = .refName
case *channel:
.nestedChans[] = .refName
default:
logger.Errorf("cannot add a child (id = %d) of type %T to a channel", , )
}
}
func ( *channel) ( int64) {
delete(.subChans, )
delete(.nestedChans, )
.deleteSelfIfReady()
}
func ( *channel) () {
.closeCalled = true
.deleteSelfIfReady()
}
func ( *channel) () int64 {
return .pid
}
func ( *channel) () ( bool) {
if !.closeCalled || len(.subChans)+len(.nestedChans) != 0 {
return false
func ( *channel) () ( bool) {
if .getTraceRefCount() != 0 {
.c = &dummyChannel{}
return false
}
return true
}
func ( *channel) () {
if !.deleteSelfFromTree() {
return
}
if !.deleteSelfFromMap() {
return
}
.cm.deleteEntry(.id)
.trace.clear()
}
func ( *channel) () *channelTrace {
return .trace
}
func ( *channel) () {
atomic.AddInt32(&.traceRefCount, 1)
}
func ( *channel) () {
atomic.AddInt32(&.traceRefCount, -1)
}
func ( *channel) () int {
:= atomic.LoadInt32(&.traceRefCount)
return int()
}
func ( *channel) () string {
return .refName
}
type subChannel struct {
refName string
c Channel
closeCalled bool
sockets map[int64]string
id int64
pid int64
cm *channelMap
trace *channelTrace
traceRefCount int32
}
func ( *subChannel) ( int64, entry) {
if , := .(*normalSocket); {
.sockets[] = .refName
} else {
logger.Errorf("cannot add a child (id = %d) of type %T to a subChannel", , )
}
}
func ( *subChannel) ( int64) {
delete(.sockets, )
.deleteSelfIfReady()
}
func ( *subChannel) () {
.closeCalled = true
.deleteSelfIfReady()
}
func ( *subChannel) () int64 {
return .pid
}
func ( *subChannel) () ( bool) {
if !.closeCalled || len(.sockets) != 0 {
return false
}
.cm.findEntry(.pid).deleteChild(.id)
return true
}
func ( *subChannel) () ( bool) {
.c = &dummyChannel{}
return false
}
return true
}
func ( *subChannel) () {
if !.deleteSelfFromTree() {
return
}
if !.deleteSelfFromMap() {
return
}
.cm.deleteEntry(.id)
.trace.clear()
}
func ( *subChannel) () *channelTrace {
return .trace
}
func ( *subChannel) () {
atomic.AddInt32(&.traceRefCount, 1)
}
func ( *subChannel) () {
atomic.AddInt32(&.traceRefCount, -1)
}
func ( *subChannel) () int {
:= atomic.LoadInt32(&.traceRefCount)
return int()
}
func ( *subChannel) () string {
return .refName
}
type Socket interface {
ChannelzMetric() *SocketInternalMetric
}
type listenSocket struct {
refName string
s Socket
id int64
pid int64
cm *channelMap
}
func ( *listenSocket) ( int64, entry) {
logger.Errorf("cannot add a child (id = %d) of type %T to a listen socket", , )
}
func ( *listenSocket) ( int64) {
logger.Errorf("cannot delete a child (id = %d) from a listen socket", )
}
func ( *listenSocket) () {
.cm.deleteEntry(.id)
.cm.findEntry(.pid).deleteChild(.id)
}
func ( *listenSocket) () {
logger.Errorf("cannot call deleteSelfIfReady on a listen socket")
}
func ( *listenSocket) () int64 {
return .pid
}
type normalSocket struct {
refName string
s Socket
id int64
pid int64
cm *channelMap
}
func ( *normalSocket) ( int64, entry) {
logger.Errorf("cannot add a child (id = %d) of type %T to a normal socket", , )
}
func ( *normalSocket) ( int64) {
logger.Errorf("cannot delete a child (id = %d) from a normal socket", )
}
func ( *normalSocket) () {
.cm.deleteEntry(.id)
.cm.findEntry(.pid).deleteChild(.id)
}
func ( *normalSocket) () {
logger.Errorf("cannot call deleteSelfIfReady on a normal socket")
}
func ( *normalSocket) () int64 {
return .pid
}
ListenSockets map[int64]string
}
type Server interface {
ChannelzMetric() *ServerInternalMetric
}
type server struct {
refName string
s Server
closeCalled bool
sockets map[int64]string
listenSockets map[int64]string
id int64
cm *channelMap
}
func ( *server) ( int64, entry) {
switch v := .(type) {
case *normalSocket:
.sockets[] = .refName
case *listenSocket:
.listenSockets[] = .refName
default:
logger.Errorf("cannot add a child (id = %d) of type %T to a server", , )
}
}
func ( *server) ( int64) {
delete(.sockets, )
delete(.listenSockets, )
.deleteSelfIfReady()
}
func ( *server) () {
.closeCalled = true
.deleteSelfIfReady()
}
func ( *server) () {
if !.closeCalled || len(.sockets)+len(.listenSockets) != 0 {
return
}
.cm.deleteEntry(.id)
}
func ( *server) () int64 {
return 0
}
type tracedChannel interface {
getChannelTrace() *channelTrace
incrTraceRefCount()
decrTraceRefCount()
getRefName() string
}
type channelTrace struct {
cm *channelMap
createdTime time.Time
eventCount int64
mu sync.Mutex
events []*TraceEvent
}
func ( *channelTrace) ( *TraceEvent) {
.mu.Lock()
if len(.events) == getMaxTraceEntry() {
:= .events[0]
.events = .events[1:]
.cm.decrTraceRefCount(.RefID)
}
}
.mu.Unlock()
}
CtError
)
type RefChannelType int
RefSubChannel
)
func ( *channelTrace) () *ChannelTrace {
.mu.Lock()
:= &ChannelTrace{EventNum: .eventCount, CreationTime: .createdTime}
.Events = .events[:len(.events)]
.mu.Unlock()
return
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |