Skip to content

Commit

Permalink
fix: compatibility with mysql8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeffcaii committed Oct 9, 2022
1 parent 186a3f8 commit de69364
Show file tree
Hide file tree
Showing 29 changed files with 290 additions and 115 deletions.
2 changes: 1 addition & 1 deletion pkg/admin/router/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func CreateCluster(c *gin.Context) error {
return exception.Wrap(exception.CodeInvalidParams, err)
}

//TODO how to get cluster name?
// TODO how to get cluster name?
err := service.UpsertCluster(context.Background(), tenant, "", cluster)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/admin/router/db_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func CreateGroup(c *gin.Context) error {
func ListGroups(c *gin.Context) error {
service := admin.GetService(c)
tenantName := c.Param("tenant")
//cluster := c.Param("cluster")
// cluster := c.Param("cluster")
clusters, err := service.ListClusters(context.Background(), tenantName)
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions pkg/admin/router/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import (
"github.com/pkg/errors"
)

var _tenantNameRegexp *regexp.Regexp
var _tenantNameRegexpOnce sync.Once
var (
_tenantNameRegexp *regexp.Regexp
_tenantNameRegexpOnce sync.Once
)

func validateTenantName(name string) error {
_tenantNameRegexpOnce.Do(func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/boot/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func buildNamespace(ctx context.Context, tenant string, provider Discovery, clus
return nil, err
}

var initCmds = []namespace.Command{
initCmds := []namespace.Command{
namespace.UpdateSlowLogger(provider.GetOptions().SlowLogPath),
namespace.UpdateParameters(cluster.Parameters),
namespace.UpdateSlowThreshold(),
Expand Down
25 changes: 11 additions & 14 deletions pkg/boot/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,57 +102,57 @@ func (fp *discovery) UpsertTenant(ctx context.Context, tenant string, body *Tena
}

func (fp *discovery) RemoveTenant(ctx context.Context, tenant string) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) UpsertCluster(ctx context.Context, tenant, cluster string, body *ClusterBody) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) RemoveCluster(ctx context.Context, tenant, cluster string) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) UpsertNode(ctx context.Context, tenant, node string, body *NodeBody) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) RemoveNode(ctx context.Context, tenant, node string) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) UpsertGroup(ctx context.Context, tenant, cluster, group string, body *GroupBody) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) RemoveGroup(ctx context.Context, tenant, cluster, group string) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) BindNode(ctx context.Context, tenant, cluster, group, node string) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) UnbindNode(ctx context.Context, tenant, cluster, group, node string) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) UpsertTable(ctx context.Context, tenant, cluster, table string, body *TableBody) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (fp *discovery) RemoveTable(ctx context.Context, tenant, cluster, table string) error {
//TODO implement me
// TODO implement me
panic("implement me")
}

Expand Down Expand Up @@ -263,7 +263,6 @@ func (fp *discovery) GetCluster(ctx context.Context, tenant, cluster string) (*C
}

func (fp *discovery) ListTenants(ctx context.Context) ([]string, error) {

return fp.tenantOp.ListTenants(), nil
}

Expand Down Expand Up @@ -349,7 +348,6 @@ func (fp *discovery) ListGroups(ctx context.Context, tenant, cluster string) ([]
}

func (fp *discovery) ListNodes(ctx context.Context, tenant, cluster, group string) ([]string, error) {

bingo, ok := fp.loadGroup(tenant, cluster, group)
if !ok {
return nil, nil
Expand Down Expand Up @@ -393,7 +391,6 @@ func (fp *discovery) ListTables(ctx context.Context, tenant, cluster string) ([]
}

func (fp *discovery) GetNode(ctx context.Context, tenant, cluster, group, node string) (*config.Node, error) {

op, ok := fp.centers[tenant]
if !ok {
return nil, ErrorNoTenant
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type (
Options map[string]interface{} `yaml:"options"`
}

//TenantOperator actions specific to tenant spaces
// TenantOperator actions specific to tenant spaces
TenantOperator interface {
io.Closer

Expand Down
8 changes: 2 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type PathInfo struct {
}

func NewPathInfo(tenant string) *PathInfo {

p := &PathInfo{}

p.DefaultTenantBaseConfigPath = PathKey(filepath.Join(string(DefaultRootPath), fmt.Sprintf("tenants/%s", tenant)))
Expand Down Expand Up @@ -260,7 +259,7 @@ func (tp *tenantOperate) CreateTenant(name string) error {
return errors.Wrap(err, "create tenant name")
}

//need to insert the relevant configuration data under the relevant tenant
// need to insert the relevant configuration data under the relevant tenant
tenantPathInfo := NewPathInfo(name)
for i := range tenantPathInfo.ConfigKeyMapping {
if err := tp.op.Save(i, []byte("")); err != nil {
Expand Down Expand Up @@ -390,7 +389,6 @@ type center struct {
}

func NewCenter(tenant string, op StoreOperator) Center {

p := NewPathInfo(tenant)

holders := map[PathKey]*atomic.Value{}
Expand Down Expand Up @@ -544,7 +542,6 @@ func (c *center) PersistContext(ctx context.Context) error {
}

func (c *center) doPersist(ctx context.Context, conf *Tenant) error {

configJson, err := json.Marshal(conf)
if err != nil {
return errors.Wrap(err, "config json.marshal failed")
Expand All @@ -564,9 +561,8 @@ func (c *center) doPersist(ctx context.Context, conf *Tenant) error {
return nil
}

//Subscribe
// Subscribe
func (c *center) Subscribe(ctx context.Context, et EventType, f callback) context.CancelFunc {

return c.observers.add(et, f)
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import (
"github.com/arana-db/arana/pkg/util/log"
)

var (
ErrorNoStoreOperate = errors.New("no store operate")
)
var ErrorNoStoreOperate = errors.New("no store operate")

func GetStoreOperate() StoreOperator {
return storeOperate
Expand Down
1 change: 0 additions & 1 deletion pkg/config/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ func (c Clusters) Diff(old Clusters) *ClustersEvent {
}

func (d *DataSourceCluster) Diff(old *DataSourceCluster) *ClusterEvent {

ret := &ClusterEvent{
Name: d.Name,
Type: d.Type,
Expand Down
1 change: 0 additions & 1 deletion pkg/config/equals.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
)

func (u *User) Equals(o *User) bool {

return u.Username == o.Username && u.Password == o.Password
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/config/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ import (
"github.com/arana-db/arana/pkg/util/log"
)

var (
PluginName = "etcd"
)
var PluginName = "etcd"

func init() {
config.Register(&storeOperate{
Expand All @@ -67,7 +65,6 @@ func (c *storeOperate) Init(options map[string]interface{}) error {
DialTimeout: 10 * time.Second,
DialOptions: []grpc.DialOption{grpc.WithBlock()},
})

if err != nil {
log.Errorf("failed to initialize etcd client error: %s", err.Error())
return err
Expand Down Expand Up @@ -142,7 +139,6 @@ func (w *etcdWatcher) run(ctx context.Context) {
}

func (c *storeOperate) Watch(key config.PathKey) (<-chan []byte, error) {

c.lock.Lock()
defer c.lock.Unlock()

Expand Down
9 changes: 3 additions & 6 deletions pkg/config/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (s *storeOperate) Save(key config.PathKey, val []byte) error {
return nil
}

//Get
// Get
func (s *storeOperate) Get(key config.PathKey) ([]byte, error) {
s.lock.RLock()
defer s.lock.RUnlock()
Expand All @@ -201,15 +201,14 @@ func (s *storeOperate) Name() string {
}

func (s *storeOperate) Close() error {

for i := range s.cancels {
s.cancels[i]()
}

return nil
}

//readFromFile
// readFromFile
func (s *storeOperate) readFromFile(path string, cfg *config.Configuration) error {
var (
f *os.File
Expand Down Expand Up @@ -257,9 +256,8 @@ func formatPath(path string) (string, error) {
return path, nil
}

//watchFileChange
// watchFileChange
func (s *storeOperate) watchFileChange(ctx context.Context, path string) {

refreshT := time.NewTicker(30 * time.Second)

oldStat, err := os.Stat(path)
Expand Down Expand Up @@ -292,5 +290,4 @@ func (s *storeOperate) watchFileChange(ctx context.Context, path string) {

}
}

}
1 change: 0 additions & 1 deletion pkg/config/nacos/nacos.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func (s *storeOperate) Get(key config.PathKey) ([]byte, error) {
DataId: buildNacosDataId(string(key)),
Group: s.groupName,
})

if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/config/nacos/nacos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,4 @@ func Test_storeOpertae(t *testing.T) {
err = operate.Save(mockPath[newCfg.Data.Tenants[0].Name].DefaultConfigDataShadowRulePath, []byte(" "))

assert.NoError(t, err, "blank string should be success")

}
1 change: 0 additions & 1 deletion pkg/executor/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func (executor *RedirectExecutor) ExecuteFieldList(ctx *proto.Context) ([]proto.
}

func (executor *RedirectExecutor) ExecutorComQuery(ctx *proto.Context) (proto.Result, uint16, error) {

var (
schemaless bool // true if schema is not specified
err error
Expand Down
19 changes: 19 additions & 0 deletions pkg/proto/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ const (
)

type (
// VersionSupport provides the version string.
VersionSupport interface {
// Version returns the version.
Version(ctx context.Context) (string, error)
}

// VConn represents a virtual connection which can be used to query/exec from a db.
VConn interface {
// Query requests a query command.
Query(ctx context.Context, db string, query string, args ...interface{}) (Result, error)

// Exec requests a exec command
Exec(ctx context.Context, db string, query string, args ...interface{}) (Result, error)
}
Expand Down Expand Up @@ -73,24 +80,36 @@ type (
DB interface {
io.Closer
Callable

// ID returns the unique id.
ID() string

// IdleTimeout returns the idle timeout.
IdleTimeout() time.Duration

// MaxCapacity returns the max capacity.
MaxCapacity() int

// Capacity returns the capacity.
Capacity() int

// Weight returns the weight.
Weight() Weight

// SetCapacity sets the capacity.
SetCapacity(capacity int) error

// SetMaxCapacity sets the max capacity.
SetMaxCapacity(maxCapacity int) error

// SetIdleTimeout sets the idle timeout.
SetIdleTimeout(idleTimeout time.Duration) error

// SetWeight sets the weight.
SetWeight(weight Weight) error

// Variable returns the variable value.
Variable(ctx context.Context, name string) (string, error)
}

// Executable represents an executor which can send sql request.
Expand Down
19 changes: 18 additions & 1 deletion pkg/runtime/ast/expression_atom.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ var (
_ ExpressionAtom = (*IntervalExpressionAtom)(nil)
)

var _compat80Dict = map[string]string{
"query_cache_size": "'1048576'",
"query_cache_type": "'OFF'",
"tx_isolation": "@@transaction_isolation",
}

type expressionAtomPhantom struct{}

type ExpressionAtom interface {
Expand Down Expand Up @@ -109,7 +115,18 @@ func (sy *SystemVariableExpressionAtom) Accept(visitor Visitor) (interface{}, er
return visitor.VisitAtomSystemVariable(sy)
}

func (sy *SystemVariableExpressionAtom) Restore(_ RestoreFlag, sb *strings.Builder, _ *[]int) error {
func (sy *SystemVariableExpressionAtom) IsCompat80() bool {
_, ok := _compat80Dict[sy.Name]
return ok
}

func (sy *SystemVariableExpressionAtom) Restore(rf RestoreFlag, sb *strings.Builder, _ *[]int) error {
if rf.Has(RestoreCompat80) {
if compat80, ok := _compat80Dict[sy.Name]; ok {
sb.WriteString(compat80)
return nil
}
}
sb.WriteString("@@")
sb.WriteString(sy.Name)
return nil
Expand Down
Loading

0 comments on commit de69364

Please sign in to comment.