Merge remote-tracking branch 'origin/errcode' into errcode

This commit is contained in:
withchao 2023-06-07 16:41:22 +08:00
commit 383334efbe
10 changed files with 47 additions and 52 deletions

View File

@ -12,11 +12,11 @@ import (
) )
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth { func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName) // conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
if err != nil { // if err != nil {
// panic(err) // panic(err)
} // }
return &Auth{conn: conn, discov: discov} return &Auth{discov: discov}
} }
type Auth struct { type Auth struct {

View File

@ -12,11 +12,11 @@ import (
) )
func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation { func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName) // conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
if err != nil { // if err != nil {
// panic(err) // panic(err)
} // }
return &Conversation{conn: conn, discov: discov} return &Conversation{discov: discov}
} }
type Conversation struct { type Conversation struct {

View File

@ -13,11 +13,11 @@ import (
) )
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend { func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName) // conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
if err != nil { // if err != nil {
// panic(err) // panic(err)
} // }
return &Friend{conn: conn, discov: discov} return &Friend{discov: discov}
} }
type Friend struct { type Friend struct {

View File

@ -13,11 +13,11 @@ import (
) )
func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group { func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName) // conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName)
if err != nil { // if err != nil {
// panic(err) // panic(err)
} // }
return &Group{conn: conn, discov: discov} return &Group{discov: discov}
} }
type Group struct { type Group struct {

View File

@ -22,11 +22,11 @@ import (
) )
func NewMsg(discov discoveryregistry.SvcDiscoveryRegistry) *Message { func NewMsg(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName) // conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
if err != nil { // if err != nil {
// panic(err) // panic(err)
} // }
return &Message{conn: conn, validate: validator.New(), discov: discov} return &Message{validate: validator.New(), discov: discov}
} }
type Message struct { type Message struct {

View File

@ -18,11 +18,11 @@ import (
) )
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third { func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName) // conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName)
if err != nil { // if err != nil {
// panic(err) // panic(err)
} // }
return &Third{conn: conn, discov: discov} return &Third{discov: discov}
} }
type Third struct { type Third struct {

View File

@ -5,7 +5,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp" "github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp"
"github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct" "github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -18,12 +17,11 @@ import (
) )
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User { func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName) // conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
if err != nil { // if err != nil {
// panic(err) // panic(err)
} // }
log.ZInfo(context.Background(), "user rpc conn", "conn", conn) return &User{discov: discov}
return &User{conn: conn, discov: discov}
} }
type User struct { type User struct {

View File

@ -77,7 +77,7 @@ func (c *MsgTool) ClearConversationsMsg(ctx context.Context, conversationIDs []s
if err := c.msgDatabase.DeleteConversationMsgsAndSetMinSeq(ctx, conversationID, int64(config.Config.Mongo.DBRetainChatRecords*24*60*60)); err != nil { if err := c.msgDatabase.DeleteConversationMsgsAndSetMinSeq(ctx, conversationID, int64(config.Config.Mongo.DBRetainChatRecords*24*60*60)); err != nil {
log.ZError(ctx, "DeleteUserSuperGroupMsgsAndSetMinSeq failed", err, "conversationID", conversationID, "DBRetainChatRecords", config.Config.Mongo.DBRetainChatRecords) log.ZError(ctx, "DeleteUserSuperGroupMsgsAndSetMinSeq failed", err, "conversationID", conversationID, "DBRetainChatRecords", config.Config.Mongo.DBRetainChatRecords)
} }
if err := c.fixAndCheckSeq(ctx, conversationID); err != nil { if err := c.checkMaxSeq(ctx, conversationID); err != nil {
log.ZError(ctx, "fixSeq failed", err, "conversationID", conversationID) log.ZError(ctx, "fixSeq failed", err, "conversationID", conversationID)
} }
@ -95,20 +95,11 @@ func (c *MsgTool) checkMaxSeqWithMongo(ctx context.Context, conversationID strin
return nil return nil
} }
func (c *MsgTool) fixAndCheckSeq(ctx context.Context, conversationID string) error { func (c *MsgTool) checkMaxSeq(ctx context.Context, conversationID string) error {
maxSeq, err := c.msgDatabase.GetMaxSeq(ctx, conversationID) maxSeq, err := c.msgDatabase.GetMaxSeq(ctx, conversationID)
if err != nil { if err != nil {
return err return err
} }
minSeq, err := c.msgDatabase.GetMinSeq(ctx, conversationID)
if err != nil {
return err
}
if minSeq > maxSeq {
if err = c.msgDatabase.SetMinSeq(ctx, conversationID, maxSeq); err != nil {
return err
}
}
if err := c.checkMaxSeqWithMongo(ctx, conversationID, maxSeq); err != nil { if err := c.checkMaxSeqWithMongo(ctx, conversationID, maxSeq); err != nil {
return err return err
} }
@ -125,8 +116,8 @@ func (c *MsgTool) FixAllSeq(ctx context.Context) error {
conversationIDs = append(conversationIDs, utils.GetNotificationConversationIDByConversationID(conversationID)) conversationIDs = append(conversationIDs, utils.GetNotificationConversationIDByConversationID(conversationID))
} }
for _, conversationID := range conversationIDs { for _, conversationID := range conversationIDs {
if err := c.fixAndCheckSeq(ctx, conversationID); err != nil { if err := c.checkMaxSeq(ctx, conversationID); err != nil {
log.ZError(ctx, "fixSeq failed", err, "conversationID", conversationID) log.ZWarn(ctx, "fixSeq failed", err, "conversationID", conversationID)
} }
} }
fmt.Println("fix all seq finished") fmt.Println("fix all seq finished")

View File

@ -543,6 +543,7 @@ func (db *commonMsgDatabase) DeleteConversationMsgsAndSetMinSeq(ctx context.Cont
if err != nil { if err != nil {
return err return err
} }
log.ZInfo(ctx, "DeleteConversationMsgsAndSetMinSeq", "conversationID", conversationID, "minSeq", minSeq)
if minSeq == 0 { if minSeq == 0 {
return nil return nil
} }
@ -591,7 +592,8 @@ func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversatio
if int64(len(msgDocModel.Msg)) > db.msg.GetSingleGocMsgNum() { if int64(len(msgDocModel.Msg)) > db.msg.GetSingleGocMsgNum() {
log.ZWarn(ctx, "msgs too large", nil, "lenth", len(msgDocModel.Msg), "docID:", msgDocModel.DocID) log.ZWarn(ctx, "msgs too large", nil, "lenth", len(msgDocModel.Msg), "docID:", msgDocModel.DocID)
} }
if msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.SendTime+(remainTime*1000) < utils.GetCurrentTimestampByMill() && msgDocModel.IsFull() { if msgDocModel.IsFull() && msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.SendTime+(remainTime*1000) < utils.GetCurrentTimestampByMill() {
log.ZDebug(ctx, "doc is full and all msg is expired", "docID", msgDocModel.DocID)
delStruct.delDocIDs = append(delStruct.delDocIDs, msgDocModel.DocID) delStruct.delDocIDs = append(delStruct.delDocIDs, msgDocModel.DocID)
delStruct.minSeq = msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.Seq delStruct.minSeq = msgDocModel.Msg[len(msgDocModel.Msg)-1].Msg.Seq
} else { } else {
@ -604,10 +606,14 @@ func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversatio
hasMarkDelFlag = true hasMarkDelFlag = true
} else { } else {
// 到本条消息不需要删除, minSeq置为这条消息的seq // 到本条消息不需要删除, minSeq置为这条消息的seq
if len(delStruct.delDocIDs) > 0 {
log.ZDebug(ctx, "delete docs", "delDocIDs", delStruct.delDocIDs)
}
if err := db.msgDocDatabase.DeleteDocs(ctx, delStruct.delDocIDs); err != nil { if err := db.msgDocDatabase.DeleteDocs(ctx, delStruct.delDocIDs); err != nil {
return 0, err return 0, err
} }
if hasMarkDelFlag { if hasMarkDelFlag {
log.ZDebug(ctx, "delete msg by index", "delMsgIndexs", delMsgIndexs, "docID", msgDocModel.DocID)
// mark del all delMsgIndexs // mark del all delMsgIndexs
if err := db.msgDocDatabase.DeleteMsgsInOneDocByIndex(ctx, msgDocModel.DocID, delMsgIndexs); err != nil { if err := db.msgDocDatabase.DeleteMsgsInOneDocByIndex(ctx, msgDocModel.DocID, delMsgIndexs); err != nil {
return delStruct.getSetMinSeq(), err return delStruct.getSetMinSeq(), err