mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-29 10:17:58 +08:00
perf: set interpolate params for compatible oceanbase (#1954)
Signed-off-by: yangk <yangk@goodrain.com>
This commit is contained in:
parent
2603c0f4c0
commit
d4bf69f384
@ -51,6 +51,7 @@ func (d *ConDB) Start(ctx context.Context, cfg *configs.Config) error {
|
||||
MysqlConnectionInfo: cfg.APIConfig.DBConnectionInfo,
|
||||
DBType: cfg.APIConfig.DBType,
|
||||
ShowSQL: cfg.APIConfig.ShowSQL,
|
||||
DBInterpolateParams: cfg.APIConfig.DBInterpolateParams,
|
||||
}
|
||||
if err := db.CreateManager(dbCfg); err != nil {
|
||||
logrus.Errorf("get db manager failed,%s", err.Error())
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
// Config config
|
||||
type Config struct {
|
||||
DBType string
|
||||
DBInterpolateParams string
|
||||
APIAddr string
|
||||
APIHealthzAddr string
|
||||
APIAddrSSL string
|
||||
@ -87,6 +88,7 @@ func (a *APIServer) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&a.LogLevel, "log-level", "info", "the api log level")
|
||||
fs.StringVar(&a.DBType, "db-type", "mysql", "db type mysql or etcd")
|
||||
fs.StringVar(&a.DBConnectionInfo, "mysql", "admin:admin@tcp(127.0.0.1:3306)/region", "mysql db connection info")
|
||||
fs.StringVar(&a.DBInterpolateParams, "db-interpolate-params", "false", "db interpolate params, for compatible oceanbase, should set true")
|
||||
fs.StringVar(&a.APIAddr, "api-addr", "127.0.0.1:8888", "the api server listen address")
|
||||
fs.StringVar(&a.APIHealthzAddr, "api-healthz-addr", "0.0.0.0:8889", "the api server health check listen address")
|
||||
fs.StringVar(&a.APIAddrSSL, "api-addr-ssl", "0.0.0.0:8443", "the api server listen address")
|
||||
|
@ -37,6 +37,7 @@ type Config struct {
|
||||
EtcdPrefix string
|
||||
ClusterName string
|
||||
MysqlConnectionInfo string
|
||||
DBInterpolateParams string
|
||||
BuildKitImage string
|
||||
BuildKitArgs string
|
||||
BuildKitCache bool
|
||||
@ -89,6 +90,7 @@ func (a *Builder) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&a.BuildKitImage, "buildkit-image", "registry.cn-hangzhou.aliyuncs.com/goodrain/buildkit:v0.12.0", "buildkit image version")
|
||||
fs.StringVar(&a.DBType, "db-type", "mysql", "db type mysql or etcd")
|
||||
fs.StringVar(&a.MysqlConnectionInfo, "mysql", "root:admin@tcp(127.0.0.1:3306)/region", "mysql db connection info")
|
||||
fs.StringVar(&a.DBInterpolateParams, "db-interpolate-params", "false", "db interpolate params, for compatible oceanbase, should set true")
|
||||
fs.StringVar(&a.KubeConfig, "kube-config", "", "kubernetes api server config file")
|
||||
fs.IntVar(&a.MaxTasks, "max-tasks", 50, "Maximum number of simultaneous build tasks")
|
||||
fs.IntVar(&a.APIPort, "api-port", 3228, "the port for api server")
|
||||
|
@ -52,6 +52,7 @@ func Run(s *option.Builder) error {
|
||||
dbconfig := config.Config{
|
||||
DBType: s.Config.DBType,
|
||||
MysqlConnectionInfo: s.Config.MysqlConnectionInfo,
|
||||
DBInterpolateParams: s.Config.DBInterpolateParams,
|
||||
EtcdEndPoints: s.Config.EtcdEndPoints,
|
||||
EtcdTimeout: s.Config.EtcdTimeout,
|
||||
}
|
||||
|
@ -106,6 +106,7 @@ func (s *LogServer) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&s.Conf.WebSocket.PrometheusMetricPath, "monitor-path", "/metrics", "promethesu monitor metrics path")
|
||||
fs.StringVar(&s.Conf.EventStore.DB.Type, "db.type", "mysql", "Data persistence type.")
|
||||
fs.StringVar(&s.Conf.EventStore.DB.URL, "db.url", "root:admin@tcp(127.0.0.1:3306)/event", "Data persistence db url.")
|
||||
fs.StringVar(&s.Conf.EventStore.DB.DBInterpolateParams, "db-interpolate-params", "false", "db interpolate params, for compatible oceanbase, should set true")
|
||||
fs.IntVar(&s.Conf.EventStore.DB.PoolSize, "db.pool.size", 3, "Data persistence db pool init size.")
|
||||
fs.IntVar(&s.Conf.EventStore.DB.PoolMaxSize, "db.pool.maxsize", 10, "Data persistence db pool max size.")
|
||||
fs.StringVar(&s.Conf.EventStore.DB.HomePath, "docker.log.homepath", "/grdata/logs/", "container log persistent home path")
|
||||
|
@ -38,6 +38,7 @@ type Config struct {
|
||||
EtcdPrefix string
|
||||
ClusterName string
|
||||
MysqlConnectionInfo string
|
||||
DBInterpolateParams string
|
||||
DBType string
|
||||
PrometheusMetricPath string
|
||||
EventLogServers []string
|
||||
@ -91,6 +92,7 @@ func (a *Worker) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&a.Listen, "listen", ":6369", "prometheus listen host and port")
|
||||
fs.StringVar(&a.DBType, "db-type", "mysql", "db type mysql or etcd")
|
||||
fs.StringVar(&a.MysqlConnectionInfo, "mysql", "root:admin@tcp(127.0.0.1:3306)/region", "mysql db connection info")
|
||||
fs.StringVar(&a.DBInterpolateParams, "db-interpolate-params", "false", "db interpolate params, for compatible oceanbase, should set true")
|
||||
fs.StringVar(&a.KubeConfig, "kube-config", "", "kubernetes api server config file")
|
||||
fs.IntVar(&a.KubeAPIQPS, "kube-api-qps", 50, "kube client qps")
|
||||
fs.IntVar(&a.KubeAPIBurst, "kube-api-burst", 10, "kube clint burst")
|
||||
|
@ -53,6 +53,7 @@ func Run(s *option.Worker) error {
|
||||
dbconfig := config.Config{
|
||||
DBType: s.Config.DBType,
|
||||
MysqlConnectionInfo: s.Config.MysqlConnectionInfo,
|
||||
DBInterpolateParams: s.Config.DBInterpolateParams,
|
||||
EtcdEndPoints: s.Config.EtcdEndPoints,
|
||||
EtcdTimeout: s.Config.EtcdTimeout,
|
||||
}
|
||||
|
@ -18,10 +18,11 @@
|
||||
|
||||
package config
|
||||
|
||||
//Config db config
|
||||
// Config db config
|
||||
type Config struct {
|
||||
MysqlConnectionInfo string
|
||||
DBType string
|
||||
DBInterpolateParams string
|
||||
EtcdEndPoints []string
|
||||
EtcdCaFile string // TODO db module do not use etcd at all
|
||||
EtcdCertFile string
|
||||
|
@ -34,7 +34,7 @@ import (
|
||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||
)
|
||||
|
||||
//Manager db manager
|
||||
// Manager db manager
|
||||
type Manager struct {
|
||||
db *gorm.DB
|
||||
config config.Config
|
||||
@ -42,12 +42,16 @@ type Manager struct {
|
||||
models []model.Interface
|
||||
}
|
||||
|
||||
//CreateManager create manager
|
||||
// CreateManager create manager
|
||||
func CreateManager(config config.Config) (*Manager, error) {
|
||||
var db *gorm.DB
|
||||
if config.DBType == "mysql" {
|
||||
var err error
|
||||
db, err = gorm.Open("mysql", config.MysqlConnectionInfo+"?charset=utf8mb4&parseTime=True&loc=Local")
|
||||
dsn := config.MysqlConnectionInfo + "?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
if config.DBInterpolateParams == "true" {
|
||||
dsn = config.MysqlConnectionInfo + "?charset=utf8mb4&parseTime=True&loc=Local&interpolateParams=true"
|
||||
}
|
||||
db, err = gorm.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -91,12 +95,12 @@ func CreateManager(config config.Config) (*Manager, error) {
|
||||
return manager, nil
|
||||
}
|
||||
|
||||
//CloseManager 关闭管理器
|
||||
// CloseManager 关闭管理器
|
||||
func (m *Manager) CloseManager() error {
|
||||
return m.db.Close()
|
||||
}
|
||||
|
||||
//Begin begin a transaction
|
||||
// Begin begin a transaction
|
||||
func (m *Manager) Begin() *gorm.DB {
|
||||
return m.db.Begin()
|
||||
}
|
||||
@ -116,12 +120,12 @@ func (m *Manager) EnsureEndTransactionFunc() func(tx *gorm.DB) {
|
||||
}
|
||||
}
|
||||
|
||||
//Print Print
|
||||
// Print Print
|
||||
func (m *Manager) Print(v ...interface{}) {
|
||||
logrus.Info(v...)
|
||||
}
|
||||
|
||||
//RegisterTableModel register table model
|
||||
// RegisterTableModel register table model
|
||||
func (m *Manager) RegisterTableModel() {
|
||||
m.models = append(m.models, &model.Tenants{})
|
||||
m.models = append(m.models, &model.TenantServices{})
|
||||
@ -178,39 +182,12 @@ func (m *Manager) RegisterTableModel() {
|
||||
m.models = append(m.models, &model.K8sResource{})
|
||||
}
|
||||
|
||||
//CheckTable check and create tables
|
||||
// CheckTable check and create tables
|
||||
func (m *Manager) CheckTable() {
|
||||
m.initOne.Do(func() {
|
||||
for _, md := range m.models {
|
||||
if !m.db.HasTable(md) {
|
||||
if m.config.DBType == "mysql" {
|
||||
err := m.db.Set("gorm:table_options", "ENGINE=InnoDB charset=utf8mb4").CreateTable(md).Error
|
||||
if err != nil {
|
||||
logrus.Errorf("auto create table %s to db error."+err.Error(), md.TableName())
|
||||
} else {
|
||||
logrus.Infof("auto create table %s to db success", md.TableName())
|
||||
}
|
||||
}
|
||||
if m.config.DBType == "cockroachdb" { //cockroachdb
|
||||
err := m.db.CreateTable(md).Error
|
||||
if err != nil {
|
||||
logrus.Errorf("auto create cockroachdb table %s to db error."+err.Error(), md.TableName())
|
||||
} else {
|
||||
logrus.Infof("auto create cockroachdb table %s to db success", md.TableName())
|
||||
}
|
||||
}
|
||||
if m.config.DBType == "sqlite" {
|
||||
err := m.db.CreateTable(md).Error
|
||||
if err != nil {
|
||||
logrus.Errorf("auto create sqlite table %s to db error."+err.Error(), md.TableName())
|
||||
} else {
|
||||
logrus.Infof("auto create sqlite table %s to db success", md.TableName())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err := m.db.AutoMigrate(md).Error; err != nil {
|
||||
logrus.Errorf("auto Migrate table %s to db error."+err.Error(), md.TableName())
|
||||
}
|
||||
if err := m.db.AutoMigrate(md).Error; err != nil {
|
||||
logrus.Errorf("auto Migrate table %s to db error."+err.Error(), md.TableName())
|
||||
}
|
||||
}
|
||||
m.patchTable()
|
||||
|
@ -40,11 +40,12 @@ type WebHookConf struct {
|
||||
|
||||
// DBConf db conf
|
||||
type DBConf struct {
|
||||
Type string
|
||||
URL string
|
||||
PoolSize int
|
||||
PoolMaxSize int
|
||||
HomePath string
|
||||
Type string
|
||||
URL string
|
||||
DBInterpolateParams string
|
||||
PoolSize int
|
||||
PoolMaxSize int
|
||||
HomePath string
|
||||
}
|
||||
|
||||
// WebSocketConf websocket conf
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
//CreateDBManager -
|
||||
// CreateDBManager -
|
||||
func CreateDBManager(conf conf.DBConf) error {
|
||||
logrus.Infof("creating dbmanager ,details %v", conf)
|
||||
var tryTime time.Duration
|
||||
@ -38,6 +38,7 @@ func CreateDBManager(conf conf.DBConf) error {
|
||||
if err = db.CreateManager(config.Config{
|
||||
MysqlConnectionInfo: conf.URL,
|
||||
DBType: conf.Type,
|
||||
DBInterpolateParams: conf.DBInterpolateParams,
|
||||
}); err != nil {
|
||||
logrus.Errorf("get db manager failed, try time is %v,%s", tryTime, err.Error())
|
||||
time.Sleep((5 + tryTime*10) * time.Second)
|
||||
|
Loading…
Reference in New Issue
Block a user