mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
log
This commit is contained in:
parent
b2a9867297
commit
15aabb3859
@ -67,16 +67,16 @@ func RegisterEtcd(schema, etcdAddr, myHost string, myPort int, serviceName strin
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("keepalive failed, errmsg:%v, lease id:%d", err, resp.ID)
|
return fmt.Errorf("keepalive failed, errmsg:%v, lease id:%d", err, resp.ID)
|
||||||
}
|
}
|
||||||
log.Info("", "RegisterEtcd ok ")
|
//log.Info("", "RegisterEtcd ok ")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case v, ok := <-kresp:
|
case _, ok := <-kresp:
|
||||||
if ok == true {
|
if ok == true {
|
||||||
log.Debug("", "KeepAlive kresp ok", v, schema, etcdAddr, myHost, myPort, serviceName, ttl)
|
//log.Debug("", "KeepAlive kresp ok", v, schema, etcdAddr, myHost, myPort, serviceName, ttl)
|
||||||
} else {
|
} else {
|
||||||
log.Error("", "KeepAlive kresp failed", schema, etcdAddr, myHost, myPort, serviceName, ttl)
|
//log.Error("", "KeepAlive kresp failed", schema, etcdAddr, myHost, myPort, serviceName, ttl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package getcdv3
|
package getcdv3
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go.etcd.io/etcd/clientv3"
|
"go.etcd.io/etcd/clientv3"
|
||||||
@ -103,7 +102,7 @@ func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts re
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
var addrList []resolver.Address
|
var addrList []resolver.Address
|
||||||
for i := range resp.Kvs {
|
for i := range resp.Kvs {
|
||||||
log.Debug("", "init addr: ", string(resp.Kvs[i].Value))
|
//log.Debug("", "init addr: ", string(resp.Kvs[i].Value))
|
||||||
addrList = append(addrList, resolver.Address{Addr: string(resp.Kvs[i].Value)})
|
addrList = append(addrList, resolver.Address{Addr: string(resp.Kvs[i].Value)})
|
||||||
}
|
}
|
||||||
r.cc.UpdateState(resolver.State{Addresses: addrList})
|
r.cc.UpdateState(resolver.State{Addresses: addrList})
|
||||||
@ -149,27 +148,27 @@ func (r *Resolver) watch(prefix string, addrList []resolver.Address) {
|
|||||||
if !exists(addrList, string(ev.Kv.Value)) {
|
if !exists(addrList, string(ev.Kv.Value)) {
|
||||||
flag = 1
|
flag = 1
|
||||||
addrList = append(addrList, resolver.Address{Addr: string(ev.Kv.Value)})
|
addrList = append(addrList, resolver.Address{Addr: string(ev.Kv.Value)})
|
||||||
log.Debug("", "after add, new list: ", addrList)
|
//log.Debug("", "after add, new list: ", addrList)
|
||||||
}
|
}
|
||||||
case mvccpb.DELETE:
|
case mvccpb.DELETE:
|
||||||
log.Debug("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value))
|
//log.Debug("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value))
|
||||||
i := strings.LastIndexAny(string(ev.Kv.Key), "/")
|
i := strings.LastIndexAny(string(ev.Kv.Key), "/")
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t := string(ev.Kv.Key)[i+1:]
|
t := string(ev.Kv.Key)[i+1:]
|
||||||
log.Debug("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value), "addr:", t)
|
//log.Debug("remove addr key: ", string(ev.Kv.Key), "value:", string(ev.Kv.Value), "addr:", t)
|
||||||
if s, ok := remove(addrList, t); ok {
|
if s, ok := remove(addrList, t); ok {
|
||||||
flag = 1
|
flag = 1
|
||||||
addrList = s
|
addrList = s
|
||||||
log.Debug("after remove, new list: ", addrList)
|
//log.Debug("after remove, new list: ", addrList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag == 1 {
|
if flag == 1 {
|
||||||
r.cc.UpdateState(resolver.State{Addresses: addrList})
|
r.cc.UpdateState(resolver.State{Addresses: addrList})
|
||||||
log.Debug("update: ", addrList)
|
//log.Debug("update: ", addrList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +176,7 @@ func (r *Resolver) watch(prefix string, addrList []resolver.Address) {
|
|||||||
func GetConn4Unique(schema, etcdaddr, servicename string) []*grpc.ClientConn {
|
func GetConn4Unique(schema, etcdaddr, servicename string) []*grpc.ClientConn {
|
||||||
gEtcdCli, err := clientv3.New(clientv3.Config{Endpoints: strings.Split(etcdaddr, ",")})
|
gEtcdCli, err := clientv3.New(clientv3.Config{Endpoints: strings.Split(etcdaddr, ",")})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("clientv3.New failed", err.Error())
|
//log.Error("clientv3.New failed", err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +200,7 @@ func GetConn4Unique(schema, etcdaddr, servicename string) []*grpc.ClientConn {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
gEtcdCli.Close()
|
gEtcdCli.Close()
|
||||||
log.Error("gEtcdCli.Get failed", err.Error())
|
//log.Error("gEtcdCli.Get failed", err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
gEtcdCli.Close()
|
gEtcdCli.Close()
|
||||||
@ -237,7 +236,7 @@ func GetConnPool(schema, etcdaddr, servicename string) (*ClientConn, error) {
|
|||||||
ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(1000*time.Millisecond))
|
ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(1000*time.Millisecond))
|
||||||
|
|
||||||
c, err := p.Get(ctx)
|
c, err := p.Get(ctx)
|
||||||
log.Info("", "Get ", err)
|
//log.Info("", "Get ", err)
|
||||||
return c, err
|
return c, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user