fix: zk add close to avoid zk block. (#1284)

* fix: zk add close to avoid zk block.

* fix: zk add close to avoid zk block.

* fix: zk add close to avoid zk block.

* fix: zk add close to avoid zk block.
pull/1274/head
Gordon 1 year ago committed by GitHub
parent cb0394392b
commit 38ab3e0ed7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,7 +38,7 @@ require github.com/google/uuid v1.3.1
require ( require (
github.com/IBM/sarama v1.41.3 github.com/IBM/sarama v1.41.3
github.com/OpenIMSDK/protocol v0.0.30 github.com/OpenIMSDK/protocol v0.0.30
github.com/OpenIMSDK/tools v0.0.14 github.com/OpenIMSDK/tools v0.0.15
github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible
github.com/go-redis/redis v6.15.9+incompatible github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.7.1 github.com/go-sql-driver/mysql v1.7.1

@ -62,6 +62,11 @@ func (m *msgServer) PullMessageBySeqs(
case sdkws.PullOrder_PullOrderDesc: case sdkws.PullOrder_PullOrderDesc:
isEnd = seq.Begin <= minSeq isEnd = seq.Begin <= minSeq
} }
if len(msgs) == 0 {
log.ZWarn(ctx, "not have msgs", nil, "conversationID", seq.ConversationID, "seq", seq)
continue
}
resp.Msgs[seq.ConversationID] = &sdkws.PullMsgs{Msgs: msgs, IsEnd: isEnd} resp.Msgs[seq.ConversationID] = &sdkws.PullMsgs{Msgs: msgs, IsEnd: isEnd}
} else { } else {
var seqs []int64 var seqs []int64
@ -71,6 +76,7 @@ func (m *msgServer) PullMessageBySeqs(
minSeq, maxSeq, notificationMsgs, err := m.MsgDatabase.GetMsgBySeqs(ctx, req.UserID, seq.ConversationID, seqs) minSeq, maxSeq, notificationMsgs, err := m.MsgDatabase.GetMsgBySeqs(ctx, req.UserID, seq.ConversationID, seqs)
if err != nil { if err != nil {
log.ZWarn(ctx, "GetMsgBySeqs error", err, "conversationID", seq.ConversationID, "seq", seq) log.ZWarn(ctx, "GetMsgBySeqs error", err, "conversationID", seq.ConversationID, "seq", seq)
continue continue
} }
var isEnd bool var isEnd bool
@ -80,6 +86,11 @@ func (m *msgServer) PullMessageBySeqs(
case sdkws.PullOrder_PullOrderDesc: case sdkws.PullOrder_PullOrderDesc:
isEnd = seq.Begin <= minSeq isEnd = seq.Begin <= minSeq
} }
if len(notificationMsgs) == 0 {
log.ZWarn(ctx, "not have notificationMsgs", nil, "conversationID", seq.ConversationID, "seq", seq)
continue
}
resp.NotificationMsgs[seq.ConversationID] = &sdkws.PullMsgs{Msgs: notificationMsgs, IsEnd: isEnd} resp.NotificationMsgs[seq.ConversationID] = &sdkws.PullMsgs{Msgs: notificationMsgs, IsEnd: isEnd}
} }
} }

@ -86,3 +86,6 @@ func (cli *K8sDR) GetClientLocalConns() map[string][]*grpc.ClientConn {
fmt.Println("should not call this function!!!!!!!!!!!!!!!!!!!!!!!!!") fmt.Println("should not call this function!!!!!!!!!!!!!!!!!!!!!!!!!")
return nil return nil
} }
func (cli *K8sDR) Close() {
return
}

@ -51,17 +51,12 @@ func Start(
return err return err
} }
defer listener.Close() defer listener.Close()
zkClient, err := discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery) client, err := discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
/* if err != nil {
zkClient, err := zookeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
zookeeper.WithFreq(time.Hour), zookeeper.WithUserNameAndPassword(
config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password,
), zookeeper.WithRoundRobin(), zookeeper.WithTimeout(10), zookeeper.WithLogger(log.NewZkLogger()))*/if err != nil {
return utils.Wrap1(err) return utils.Wrap1(err)
} }
// defer zkClient.CloseZK() defer client.Close()
zkClient.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()))
registerIP, err := network.GetRpcRegisterIP(config.Config.Rpc.RegisterIP) registerIP, err := network.GetRpcRegisterIP(config.Config.Rpc.RegisterIP)
if err != nil { if err != nil {
return err return err
@ -81,11 +76,11 @@ func Start(
} }
srv := grpc.NewServer(options...) srv := grpc.NewServer(options...)
defer srv.GracefulStop() defer srv.GracefulStop()
err = rpcFn(zkClient, srv) err = rpcFn(client, srv)
if err != nil { if err != nil {
return utils.Wrap1(err) return utils.Wrap1(err)
} }
err = zkClient.Register( err = client.Register(
rpcRegisterName, rpcRegisterName,
registerIP, registerIP,
rpcPort, rpcPort,

Loading…
Cancel
Save