Skip to content

Commit

Permalink
Revert "aaa"
Browse files Browse the repository at this point in the history
This reverts commit f098e05.
  • Loading branch information
menghanl committed Apr 24, 2019
1 parent f098e05 commit 302f2af
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proto:
go generate google.golang.org/grpc/...

test: testdeps
go test -cpu 1,4 -timeout 7m google.golang.org/grpc/test -run Test/CZSocketMetricsSocketOption -count 100
go test -cpu 1,4 -timeout 7m google.golang.org/grpc/...

testappengine: testappenginedeps
goapp test -cpu 1,4 -timeout 7m google.golang.org/grpc/...
Expand Down
11 changes: 0 additions & 11 deletions internal/channelz/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
package channelz

import (
"fmt"
"runtime/debug"
"sort"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -226,16 +224,13 @@ func RegisterServer(s Server, ref string) int64 {
// (identified by pid). It returns the unique channelz tracking id assigned to
// this listen socket.
func RegisterListenSocket(s Socket, pid int64, ref string) int64 {
fmt.Println("channelz. registering listen socket, pid: ", pid)
if pid == 0 {
grpclog.Error("a ListenSocket's parent id cannot be 0")
return 0
}
id := idGen.genID()
fmt.Println("channelz. registering listen socket, generated id: ", id)
ls := &listenSocket{refName: ref, s: s, id: id, pid: pid}
db.get().addListenSocket(id, ls, pid, ref)
fmt.Println("channelz. registering listen socket, after addListenSocket")
return id
}

Expand Down Expand Up @@ -323,13 +318,11 @@ func (c *channelMap) addSubChannel(id int64, sc *subChannel, pid int64, ref stri
}

func (c *channelMap) addListenSocket(id int64, ls *listenSocket, pid int64, ref string) {
fmt.Println("channelz. add listen socket, id ", id, ", pid: ", pid)
c.mu.Lock()
ls.cm = c
c.listenSockets[id] = ls
c.findEntry(pid).addChild(id, ls)
c.mu.Unlock()
fmt.Println("channelz. add listen socket, done")
}

func (c *channelMap) addNormalSocket(id int64, ns *normalSocket, pid int64, ref string) {
Expand Down Expand Up @@ -361,7 +354,6 @@ func (c *channelMap) decrTraceRefCount(id int64) {

// c.mu must be held by the caller.
func (c *channelMap) findEntry(id int64) entry {
fmt.Println("channelz findEntry, id: ", id)
var v entry
var ok bool
if v, ok = c.channels[id]; ok {
Expand All @@ -371,7 +363,6 @@ func (c *channelMap) findEntry(id int64) entry {
return v
}
if v, ok = c.servers[id]; ok {
fmt.Println("channelz findEntry, found server")
return v
}
if v, ok = c.listenSockets[id]; ok {
Expand All @@ -380,8 +371,6 @@ func (c *channelMap) findEntry(id int64) entry {
if v, ok = c.normalSockets[id]; ok {
return v
}
fmt.Println("channelz findEntry, before returning dummy, wtf???")
debug.PrintStack()
return &dummyEntry{idNotFound: id}
}

Expand Down
3 changes: 0 additions & 3 deletions internal/channelz/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package channelz

import (
"fmt"
"net"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -589,12 +588,10 @@ type server struct {
}

func (s *server) addChild(id int64, e entry) {
fmt.Println("channelz.server.addChild, child id: ", id)
switch v := e.(type) {
case *normalSocket:
s.sockets[id] = v.refName
case *listenSocket:
fmt.Println("channelz.server.addChild, child is listensocket, refname: ", v.refName)
s.listenSockets[id] = v.refName
default:
grpclog.Errorf("cannot add a child (id = %d) of type %T to a server", id, e)
Expand Down
8 changes: 1 addition & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import (
"fmt"
"io"
"math"
"math/rand"
"net"
"net/http"
"reflect"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -375,8 +373,7 @@ func NewServer(opt ...ServerOption) *Server {
}

if channelz.IsOn() {
s.channelzID = channelz.RegisterServer(&channelzServer{s}, strconv.Itoa(rand.Intn(100)))
fmt.Println("register server", s.channelzID)
s.channelzID = channelz.RegisterServer(&channelzServer{s}, "")
}
return s
}
Expand Down Expand Up @@ -509,7 +506,6 @@ func (l *listenSocket) Close() error {
err := l.Listener.Close()
if channelz.IsOn() {
channelz.RemoveEntry(l.channelzID)
fmt.Println("remove listen socket", l.channelzID)
}
return err
}
Expand Down Expand Up @@ -547,7 +543,6 @@ func (s *Server) Serve(lis net.Listener) error {

if channelz.IsOn() {
ls.channelzID = channelz.RegisterListenSocket(ls, s.channelzID, lis.Addr().String())
fmt.Println("register listen socket", ls.channelzID, ", parent", s.channelzID)
}
s.mu.Unlock()

Expand Down Expand Up @@ -1345,7 +1340,6 @@ func (s *Server) Stop() {
s.channelzRemoveOnce.Do(func() {
if channelz.IsOn() {
channelz.RemoveEntry(s.channelzID)
fmt.Println("remove server", s.channelzID)
}
})

Expand Down
16 changes: 3 additions & 13 deletions test/channelz_linux_go110_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package test

import (
"fmt"
"testing"
"time"

Expand All @@ -36,7 +35,6 @@ import (
func (s) TestCZSocketMetricsSocketOption(t *testing.T) {
envs := []env{tcpClearRREnv, tcpTLSRREnv}
for _, e := range envs {
fmt.Printf("\n%+v\n\n", e)
testCZSocketMetricsSocketOption(t, e)
}
}
Expand All @@ -50,21 +48,13 @@ func testCZSocketMetricsSocketOption(t *testing.T, e env) {
tc := testpb.NewTestServiceClient(cc)
doSuccessfulUnaryCall(tc, t)

var ss []*channelz.ServerMetric
for i := 0; i < 100; i++ {
time.Sleep(10 * time.Millisecond)
ss, _ = channelz.GetServers(0, 0)
if len(ss) == 1 && len(ss[0].ListenSockets) == 1 {
break
}
}
time.Sleep(10 * time.Millisecond)
ss, _ := channelz.GetServers(0, 0)
if len(ss) != 1 {
t.Fatalf("There should be one server, not %d", len(ss))
}
t.Logf("ss[0] :%+v", ss[0])
if len(ss[0].ListenSockets) != 1 {
fmt.Printf("There should be one listen socket, not %d, %+v", len(ss[0].ListenSockets), ss[0])
t.Fatalf("There should be one listen socket, not %d, %+v", len(ss[0].ListenSockets), ss[0])
t.Fatalf("There should be one listen socket, not %d", len(ss[0].ListenSockets))
}
for id := range ss[0].ListenSockets {
sm := channelz.GetSocket(id)
Expand Down

0 comments on commit 302f2af

Please sign in to comment.