diff --git a/config/config.yaml b/config/config.yaml index 680747d01..30e0b8b4f 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -119,6 +119,7 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申 accessKeyID: user12345 secretAccessKey: key12345 storageTime: 50 #文件在minio中保存的时间 + isDistributedMod: false # 是否分布式多硬盘部署 默认docker-compose中为false ali: # ali oss regionID: "oss-cn-beijing" accessKeyID: "" diff --git a/internal/api/third/minio_init.go b/internal/api/third/minio_init.go index 393122858..b1088df50 100644 --- a/internal/api/third/minio_init.go +++ b/internal/api/third/minio_init.go @@ -32,6 +32,7 @@ func MinioInit() { } opts := &minio.Options{ Creds: credentials.NewStaticV4(config.Config.Credential.Minio.AccessKeyID, config.Config.Credential.Minio.SecretAccessKey, ""), + //Region: config.Config.Credential.Minio.Location, } if minioUrl.Scheme == "http" { opts.Secure = false @@ -46,8 +47,10 @@ func MinioInit() { return } opt := minio.MakeBucketOptions{ - Region: config.Config.Credential.Minio.Location, - ObjectLocking: false, + Region: config.Config.Credential.Minio.Location, + } + if config.Config.Credential.Minio.IsDistributedMod == true { + opt.ObjectLocking = true } err = MinioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt) if err != nil { @@ -78,6 +81,9 @@ func MinioInit() { return } } + policy, err := MinioClient.GetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket) + log.NewInfo("", utils.GetSelfFuncName(), policy) + // 自动化桶public的代码 policyJsonString := fmt.Sprintf(`{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject","s3:PutObject"], "Effect": "Allow","Principal": {"AWS": ["*"]},"Resource": ["arn:aws:s3:::%s/*"],"Sid": ""}]}`, config.Config.Credential.Minio.Bucket) diff --git a/internal/api/third/minio_storage_credential.go b/internal/api/third/minio_storage_credential.go index 7f6c81638..4c6fad1f2 100644 --- a/internal/api/third/minio_storage_credential.go +++ b/internal/api/third/minio_storage_credential.go @@ -161,6 +161,7 @@ func MinioStorageCredential(c *gin.Context) { resp.BucketName = config.Config.Credential.Minio.Bucket resp.StsEndpointURL = config.Config.Credential.Minio.Endpoint resp.StorageTime = config.Config.Credential.Minio.StorageTime + resp.IsDistributedMod = config.Config.Credential.Minio.IsDistributedMod c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp}) } diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 1f728d6d7..a36da065b 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -61,7 +61,13 @@ func (s *groupServer) Run() { log.NewInfo("", "listen network success, ", address, listener) defer listener.Close() //grpc server - srv := grpc.NewServer() + recvSize := 1024 * 1024 * 30 + sendSize := 1024 * 1024 * 30 + var options = []grpc.ServerOption{ + grpc.MaxRecvMsgSize(recvSize), + grpc.MaxSendMsgSize(sendSize), + } + srv := grpc.NewServer(options...) defer srv.GracefulStop() //Service registers with etcd pbGroup.RegisterGroupServer(srv, s) diff --git a/internal/rpc/group/super_group.go b/internal/rpc/group/super_group.go index 9b50c7955..b667abe76 100644 --- a/internal/rpc/group/super_group.go +++ b/internal/rpc/group/super_group.go @@ -1,7 +1,6 @@ package group import ( - "Open_IM/pkg/common/constant" rocksCache "Open_IM/pkg/common/db/rocks_cache" "Open_IM/pkg/common/log" cp "Open_IM/pkg/common/utils" @@ -15,7 +14,6 @@ import ( func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp := &pbGroup.GetJoinedSuperGroupListResp{CommonResp: &pbGroup.CommonResp{}} - //userToSuperGroup, err := db.DB.GetSuperGroupByUserID(req.UserID) groupIDList, err := rocksCache.GetJoinedSuperGroupListFromCache(req.UserID) if err != nil { if err == redis.Nil { @@ -23,8 +21,8 @@ func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup. return resp, nil } log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID failed ", err.Error(), req.UserID) - resp.CommonResp.ErrCode = constant.ErrDB.ErrCode - resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + //resp.CommonResp.ErrCode = constant.ErrDB.ErrCode + //resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg return resp, nil } for _, groupID := range groupIDList { diff --git a/pkg/base_info/third_api_struct.go b/pkg/base_info/third_api_struct.go index 8785ecd37..ddf9291ec 100644 --- a/pkg/base_info/third_api_struct.go +++ b/pkg/base_info/third_api_struct.go @@ -7,12 +7,13 @@ type MinioStorageCredentialReq struct { } type MiniostorageCredentialResp struct { - SecretAccessKey string `json:"secretAccessKey"` - AccessKeyID string `json:"accessKeyID"` - SessionToken string `json:"sessionToken"` - BucketName string `json:"bucketName"` - StsEndpointURL string `json:"stsEndpointURL"` - StorageTime int `json:"storageTime"` + SecretAccessKey string `json:"secretAccessKey"` + AccessKeyID string `json:"accessKeyID"` + SessionToken string `json:"sessionToken"` + BucketName string `json:"bucketName"` + StsEndpointURL string `json:"stsEndpointURL"` + StorageTime int `json:"storageTime"` + IsDistributedMod bool `json:"isDistributedMod"` } type MinioUploadFileReq struct { diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index e773fc79b..2825b816c 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -72,6 +72,7 @@ type config struct { EndpointInner string `yaml:"endpointInner"` EndpointInnerEnable bool `yaml:"endpointInnerEnable"` StorageTime int `yaml:"storageTime"` + IsDistributedMod bool `yaml:"isDistributedMod"` } `yaml:"minio"` } diff --git a/pkg/common/db/rocks_cache/rocks_cache.go b/pkg/common/db/rocks_cache/rocks_cache.go index 86ce3dea6..033731e8d 100644 --- a/pkg/common/db/rocks_cache/rocks_cache.go +++ b/pkg/common/db/rocks_cache/rocks_cache.go @@ -8,6 +8,7 @@ import ( "Open_IM/pkg/utils" "context" "encoding/json" + "errors" "fmt" "time" ) @@ -323,6 +324,9 @@ func GetJoinedSuperGroupListFromCache(userID string) ([]string, error) { if err != nil { return "", utils.Wrap(err, "") } + if len(userToSuperGroup.GroupIDList) == 0 { + return "", errors.New("GroupIDList == 0") + } bytes, err := json.Marshal(userToSuperGroup.GroupIDList) return string(bytes), utils.Wrap(err, "") }