Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dbm-services): 删除dbpriv 无用代码 #8539 #8540

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 62 additions & 60 deletions dbm-services/mysql/db-priv/service/v2/query_priv/get_priv.go
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
// Package query_priv TODO
package query_priv

import (
"context"
"dbm-services/common/go-pubpkg/errno"
"dbm-services/mysql/priv-service/service"
v2 "dbm-services/mysql/priv-service/service/v2/internal"
"fmt"
"slices"
"strings"
"sync"
)

func (m *GetPrivPara) GetPriv() error {
err := m.validate()
if err != nil {
return err
}
"dbm-services/mysql/priv-service/service"
v2 "dbm-services/mysql/priv-service/service/v2/internal"
)

if len(m.Users) == 0 {
return errno.ErrUserIsEmpty
}
userStr := strings.Join(m.Users, `','`)

var errChan = make(chan error)
var retChan = make(chan []string)

go func() {
wg := sync.WaitGroup{}

for _, item := range m.ImmuteDomains {
wg.Add(1)

err := m.limiter.Wait(context.Background())
if err != nil {
errChan <- err
wg.Done()
return
}

go func(item string) {
defer func() {
wg.Done()
}()

domainInfo, err := service.GetCluster(*m.ClusterType, service.Domain{EntryName: item})
if err != nil {
errChan <- err
return
}

switch domainInfo.ClusterType {
case v2.ClusterTypeTenDBSingle:
privsFromTenDBSingle(&domainInfo, m.Users, m.Ips, m.Dbs)
case v2.ClusterTypeTenDBHA:
privsFromTenDBHA(&domainInfo, m.Users, m.Ips, m.Dbs)
case v2.ClusterTypeTenDBCluster:
default:
errChan <- fmt.Errorf("unknown cluster type: %s", domainInfo.ClusterType)
return
}
}(item)
}
}()
}
// GetPriv TODO
// func (m *GetPrivPara) GetPriv() error {
// err := m.validate()
// if err != nil {
// return err
// }

// if len(m.Users) == 0 {
// return errno.ErrUserIsEmpty
// }
// userStr := strings.Join(m.Users, `','`)

// var errChan = make(chan error)
// var retChan = make(chan []string)

// go func() {
// wg := sync.WaitGroup{}

// for _, item := range m.ImmuteDomains {
// wg.Add(1)

// err := m.limiter.Wait(context.Background())
// if err != nil {
// errChan <- err
// wg.Done()
// return
// }

// go func(item string) {
// defer func() {
// wg.Done()
// }()

// domainInfo, err := service.GetCluster(*m.ClusterType, service.Domain{EntryName: item})
// if err != nil {
// errChan <- err
// return
// }

// switch domainInfo.ClusterType {
// case v2.ClusterTypeTenDBSingle:
// privsFromTenDBSingle(&domainInfo, m.Users, m.Ips, m.Dbs)
// case v2.ClusterTypeTenDBHA:
// privsFromTenDBHA(&domainInfo, m.Users, m.Ips, m.Dbs)
// case v2.ClusterTypeTenDBCluster:
// default:
// errChan <- fmt.Errorf("unknown cluster type: %s", domainInfo.ClusterType)
// return
// }
// }(item)
// }
// }()
// }

func privsFromTenDBSingle(domainInfo *service.Instance, users, clientIps, dbs []string) ([]service.GrantInfo, error) {
backendAddr := fmt.Sprintf("%s:%d", domainInfo.Storages[0].IP, domainInfo.Storages[0].Port)
Expand Down Expand Up @@ -143,7 +143,8 @@ func privsFromTenDBHAMaster(domainInfo *service.Instance, users, clientIps, dbs
return service.CombineUserWithGrant(whiteList, splitUserGrants, true), nil
}

func privsFromTenDBHASlave(domainInfo *service.Instance, users []string, clientIps []string, dbs []string) ([]service.GrantInfo, error) {
func privsFromTenDBHASlave(domainInfo *service.Instance, users []string, clientIps []string,
dbs []string) ([]service.GrantInfo, error) {
idx := slices.IndexFunc(domainInfo.Storages, func(s service.Storage) bool {
// ToDo 这里其实有点问题, 如果有多个 slave, 应该返回哪一个?
return s.InstanceRole == v2.InstanceRoleBackendSlave
Expand Down Expand Up @@ -188,6 +189,7 @@ func privsFromTenDBCluster() {

}

func privsFromMySQL(addr string, isMasterDomain bool, domainInfo *service.Instance, users, clientIps, dbs []string) ([]service.GrantInfo, error) {
// func privsFromMySQL(addr string, isMasterDomain bool, domainInfo *service.Instance, users, clientIps,
// dbs []string) ([]service.GrantInfo, error) {

}
// }
Loading