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

feat(backend): drs mysql rpc 增加复杂接口 #8820 #8826

Merged
Merged
Show file tree
Hide file tree
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
)

func (c *RPCWrapper) executeOneAddr(address string) (res []cmdResult, err error) {
func (c *RPCWrapper) executeOneAddr(address string) (res []CmdResultType, err error) {
db, err := c.MakeConnection(address, c.user, c.password, c.connectTimeout, c.timezone)

if err != nil {
Expand Down Expand Up @@ -48,7 +48,7 @@ func (c *RPCWrapper) executeOneAddr(address string) (res []cmdResult, err error)
slog.String("address", address), slog.String("command", command),
)
res = append(
res, cmdResult{
res, CmdResultType{
Cmd: command,
RowsAffected: 0,
TableData: nil,
Expand All @@ -61,7 +61,7 @@ func (c *RPCWrapper) executeOneAddr(address string) (res []cmdResult, err error)
continue
}
res = append(
res, cmdResult{
res, CmdResultType{
Cmd: command,
TableData: tableData,
RowsAffected: 0,
Expand All @@ -77,7 +77,7 @@ func (c *RPCWrapper) executeOneAddr(address string) (res []cmdResult, err error)
slog.String("address", address), slog.String("command", command),
)
res = append(
res, cmdResult{
res, CmdResultType{
Cmd: command,
TableData: nil,
RowsAffected: 0,
Expand All @@ -90,7 +90,7 @@ func (c *RPCWrapper) executeOneAddr(address string) (res []cmdResult, err error)
continue
}
res = append(
res, cmdResult{
res, CmdResultType{
Cmd: command,
TableData: nil,
RowsAffected: rowsAffected,
Expand All @@ -101,7 +101,7 @@ func (c *RPCWrapper) executeOneAddr(address string) (res []cmdResult, err error)
err = errors.Errorf("commands[%d]: %s not support", idx, command)
slog.Error("dispatch command", slog.String("error", err.Error()))
res = append(
res, cmdResult{Cmd: command, TableData: nil, RowsAffected: 0, ErrorMsg: err.Error()},
res, CmdResultType{Cmd: command, TableData: nil, RowsAffected: 0, ErrorMsg: err.Error()},
)
if !c.force {
return res, err
Expand Down
10 changes: 5 additions & 5 deletions dbm-services/mysql/db-remote-service/pkg/rpc_core/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package rpc_core

type tableDataType []map[string]interface{}

type cmdResult struct {
type CmdResultType struct {
Cmd string `json:"cmd"`
TableData tableDataType `json:"table_data"`
RowsAffected int64 `json:"rows_affected"`
ErrorMsg string `json:"error_msg"`
}

type oneAddressResult struct {
Address string `json:"address"`
CmdResults []cmdResult `json:"cmd_results"`
ErrorMsg string `json:"error_msg"`
type OneAddressResultType struct {
Address string `json:"address"`
CmdResults []CmdResultType `json:"cmd_results"`
ErrorMsg string `json:"error_msg"`
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package rpc_core

import (
"dbm-services/mysql/db-remote-service/pkg/parser"

"github.com/jmoiron/sqlx"
)

Expand All @@ -15,9 +13,9 @@ type RPCEmbedInterface interface {
timeout int,
timezone string,
) (*sqlx.DB, error)
ParseCommand(command string) (*parser.ParseQueryBase, error)
IsQueryCommand(*parser.ParseQueryBase) bool
IsExecuteCommand(*parser.ParseQueryBase) bool
ParseCommand(command string) (*ParseQueryBase, error)
IsQueryCommand(*ParseQueryBase) bool
IsExecuteCommand(*ParseQueryBase) bool
User() string
Password() string
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package parser sql解析
package parser
package rpc_core

// ParseQueryBase query result base field
type ParseQueryBase struct {
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions dbm-services/mysql/db-remote-service/pkg/rpc_core/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

// Run 执行
func (c *RPCWrapper) Run() (res []oneAddressResult) {
addrResChan := make(chan oneAddressResult)
func (c *RPCWrapper) Run() (res []OneAddressResultType) {
addrResChan := make(chan OneAddressResultType)
tokenBulkChan := make(chan struct{}, config.RuntimeConfig.Concurrent)
slog.Debug("init bulk chan", slog.Int("concurrent", config.RuntimeConfig.Concurrent))

Expand All @@ -27,7 +27,7 @@ func (c *RPCWrapper) Run() (res []oneAddressResult) {
if err != nil {
errMsg = err.Error()
}
addrResChan <- oneAddressResult{
addrResChan <- OneAddressResultType{
Address: address,
CmdResults: addrRes,
ErrorMsg: errMsg,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mysql_complex_rpc

import "github.com/gin-gonic/gin"

func Handler(c *gin.Context) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package mysql_rpc

import (
"dbm-services/mysql/db-remote-service/pkg/config"
"dbm-services/mysql/db-remote-service/pkg/parser"
"dbm-services/mysql/db-remote-service/pkg/rpc_core"
"fmt"
"log/slog"
"net/url"
Expand Down Expand Up @@ -92,8 +92,8 @@ func (c *MySQLRPCEmbed) MakeConnection(address string, user string, password str
}

// ParseCommand mysql 解析命令
func (c *MySQLRPCEmbed) ParseCommand(command string) (*parser.ParseQueryBase, error) {
return &parser.ParseQueryBase{
func (c *MySQLRPCEmbed) ParseCommand(command string) (*rpc_core.ParseQueryBase, error) {
return &rpc_core.ParseQueryBase{
QueryId: 0,
Command: command,
ErrorCode: 0,
Expand All @@ -102,12 +102,12 @@ func (c *MySQLRPCEmbed) ParseCommand(command string) (*parser.ParseQueryBase, er
}

// IsQueryCommand mysql 解析命令
func (c *MySQLRPCEmbed) IsQueryCommand(pc *parser.ParseQueryBase) bool {
func (c *MySQLRPCEmbed) IsQueryCommand(pc *rpc_core.ParseQueryBase) bool {
return isQueryCommand(pc.Command)
}

// IsExecuteCommand mysql 解析命令
func (c *MySQLRPCEmbed) IsExecuteCommand(pc *parser.ParseQueryBase) bool {
func (c *MySQLRPCEmbed) IsExecuteCommand(pc *rpc_core.ParseQueryBase) bool {
return !isQueryCommand(pc.Command)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package proxy_rpc

import (
"dbm-services/mysql/db-remote-service/pkg/config"
"dbm-services/mysql/db-remote-service/pkg/parser"
"dbm-services/mysql/db-remote-service/pkg/rpc_core"
"fmt"
"log/slog"
"strings"
Expand All @@ -27,8 +27,8 @@ type ProxyRPCEmbed struct {
}

// ParseCommand proxy 解析命令
func (c *ProxyRPCEmbed) ParseCommand(command string) (*parser.ParseQueryBase, error) {
return &parser.ParseQueryBase{
func (c *ProxyRPCEmbed) ParseCommand(command string) (*rpc_core.ParseQueryBase, error) {
return &rpc_core.ParseQueryBase{
QueryId: 0,
Command: command,
ErrorCode: 0,
Expand Down Expand Up @@ -73,7 +73,7 @@ func (c *ProxyRPCEmbed) MakeConnection(address string, user string, password str
}

// IsQueryCommand proxy 解析命令
func (c *ProxyRPCEmbed) IsQueryCommand(pc *parser.ParseQueryBase) bool {
func (c *ProxyRPCEmbed) IsQueryCommand(pc *rpc_core.ParseQueryBase) bool {
for _, ele := range proxyQueryParseCommands {
if strings.HasPrefix(strings.ToLower(pc.Command), ele) {
return true
Expand All @@ -84,7 +84,7 @@ func (c *ProxyRPCEmbed) IsQueryCommand(pc *parser.ParseQueryBase) bool {
}

// IsExecuteCommand proxy 解析命令
func (c *ProxyRPCEmbed) IsExecuteCommand(pc *parser.ParseQueryBase) bool {
func (c *ProxyRPCEmbed) IsExecuteCommand(pc *rpc_core.ParseQueryBase) bool {
for _, ele := range proxyExecuteParseCommands {
if strings.HasPrefix(strings.ToLower(pc.Command), ele) {
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package sqlserver_rpc

import (
"context"
"dbm-services/mysql/db-remote-service/pkg/rpc_core"
"fmt"
"log/slog"
"strings"
"time"

"dbm-services/mysql/db-remote-service/pkg/config"
"dbm-services/mysql/db-remote-service/pkg/parser"

_ "github.com/denisenkom/go-mssqldb" // go-mssqldb TODO
"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -39,8 +39,8 @@ type SqlserverRPCEmbed struct {
}

// ParseCommand sqlserver 解析命令
func (c *SqlserverRPCEmbed) ParseCommand(command string) (*parser.ParseQueryBase, error) {
return &parser.ParseQueryBase{
func (c *SqlserverRPCEmbed) ParseCommand(command string) (*rpc_core.ParseQueryBase, error) {
return &rpc_core.ParseQueryBase{
QueryId: 0,
Command: command,
ErrorCode: 0,
Expand Down Expand Up @@ -76,7 +76,7 @@ func (c *SqlserverRPCEmbed) MakeConnection(address string, user string, password
}

// IsQueryCommand sqlserver 解析命令
func (c *SqlserverRPCEmbed) IsQueryCommand(pc *parser.ParseQueryBase) bool {
func (c *SqlserverRPCEmbed) IsQueryCommand(pc *rpc_core.ParseQueryBase) bool {
for _, ele := range sqlserverQueryParseCommands {
if strings.HasPrefix(strings.ToLower(pc.Command), ele) {
return true
Expand All @@ -87,7 +87,7 @@ func (c *SqlserverRPCEmbed) IsQueryCommand(pc *parser.ParseQueryBase) bool {
}

// IsExecuteCommand sqlserver 解析命令
func (c *SqlserverRPCEmbed) IsExecuteCommand(pc *parser.ParseQueryBase) bool {
func (c *SqlserverRPCEmbed) IsExecuteCommand(pc *rpc_core.ParseQueryBase) bool {
for _, ele := range sqlserverExecuteParseCommands {
if strings.HasPrefix(strings.ToLower(pc.Command), ele) {
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package webconsole_rpc

import (
"dbm-services/mysql/db-remote-service/pkg/config"
"dbm-services/mysql/db-remote-service/pkg/mysql_rpc"
"dbm-services/mysql/db-remote-service/pkg/rpc_implement/mysql_rpc"
)

type WebConsoleRPC struct {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type queryRequest struct {

// TrimSpace delete space around address
func (r *queryRequest) TrimSpace() {
r.Timezone = strings.TrimSpace(r.Timezone)
for idx, val := range r.Addresses {
r.Addresses[idx] = strings.TrimSpace(val)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package handler_rpc

import "dbm-services/mysql/db-remote-service/pkg/mysql_rpc"
import (
"dbm-services/mysql/db-remote-service/pkg/rpc_implement/mysql_rpc"
)

// MySQLRPCHandler mysql 请求响应
var MySQLRPCHandler = generalHandler(&mysql_rpc.MySQLRPCEmbed{})
Loading