mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-06 21:52:54 +08:00
fix: region-dns not support dameng dialect (#23806)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -39,29 +39,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/dbutils"
|
||||
)
|
||||
|
||||
func InitDB(options *common_options.DBOptions) {
|
||||
if options.DebugSqlchemy {
|
||||
log.Warningf("debug Sqlchemy is turned on")
|
||||
sqlchemy.DEBUG_SQLCHEMY = true
|
||||
}
|
||||
|
||||
log.Infof("Registered SQL drivers: %s", strings.Join(sql.Drivers(), ", "))
|
||||
|
||||
consts.QueryOffsetOptimization = options.QueryOffsetOptimization
|
||||
|
||||
if options.HistoricalUniqueName {
|
||||
consts.EnableHistoricalUniqueName()
|
||||
} else {
|
||||
consts.DisableHistoricalUniqueName()
|
||||
}
|
||||
|
||||
if options.OpsLogMaxKeepMonths > 0 {
|
||||
consts.SetSplitableMaxKeepMonths(options.OpsLogMaxKeepMonths)
|
||||
}
|
||||
if options.SplitableMaxDurationHours > 0 {
|
||||
consts.SetSplitableMaxDurationHours(options.SplitableMaxDurationHours)
|
||||
}
|
||||
|
||||
func InitDBConn(options *common_options.DBOptions) {
|
||||
dialect, sqlStr, err := options.GetDBConnection()
|
||||
if err != nil {
|
||||
log.Fatalf("Invalid SqlConnection string: %s error: %v", options.SqlConnection, err)
|
||||
@@ -103,8 +81,10 @@ func InitDB(options *common_options.DBOptions) {
|
||||
dbConn.SetConnMaxLifetime(time.Duration(options.DbMaxWaitTimeoutSeconds) * time.Second)
|
||||
// ConnMaxIdleTime should be half of ConnMaxLifetime
|
||||
dbConn.SetConnMaxIdleTime(time.Duration(options.DbMaxWaitTimeoutSeconds/2) * time.Second)
|
||||
}
|
||||
|
||||
dialect, sqlStr, err = options.GetClickhouseConnStr()
|
||||
func InitClickhouseConn(options *common_options.DBOptions) {
|
||||
dialect, sqlStr, err := options.GetClickhouseConnStr()
|
||||
if err == nil {
|
||||
// connect to clickcloud
|
||||
// force convert sqlstr from clickhouse v2 to v1
|
||||
@@ -126,6 +106,33 @@ func InitDB(options *common_options.DBOptions) {
|
||||
consts.OpsLogWithClickhouse = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func InitDB(options *common_options.DBOptions) {
|
||||
if options.DebugSqlchemy {
|
||||
log.Warningf("debug Sqlchemy is turned on")
|
||||
sqlchemy.DEBUG_SQLCHEMY = true
|
||||
}
|
||||
|
||||
log.Infof("Registered SQL drivers: %s", strings.Join(sql.Drivers(), ", "))
|
||||
|
||||
consts.QueryOffsetOptimization = options.QueryOffsetOptimization
|
||||
|
||||
if options.HistoricalUniqueName {
|
||||
consts.EnableHistoricalUniqueName()
|
||||
} else {
|
||||
consts.DisableHistoricalUniqueName()
|
||||
}
|
||||
|
||||
if options.OpsLogMaxKeepMonths > 0 {
|
||||
consts.SetSplitableMaxKeepMonths(options.OpsLogMaxKeepMonths)
|
||||
}
|
||||
if options.SplitableMaxDurationHours > 0 {
|
||||
consts.SetSplitableMaxDurationHours(options.SplitableMaxDurationHours)
|
||||
}
|
||||
|
||||
InitDBConn(options)
|
||||
InitClickhouseConn(options)
|
||||
|
||||
switch options.LockmanMethod {
|
||||
case common_options.LockMethodInMemory, "":
|
||||
|
||||
@@ -16,8 +16,6 @@ package dns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -33,13 +31,15 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/sqlchemy"
|
||||
_ "yunion.io/x/sqlchemy/backends"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
identity_api "yunion.io/x/onecloud/pkg/apis/identity"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
@@ -99,17 +99,12 @@ func New() *SRegionDNS {
|
||||
}
|
||||
|
||||
func (r *SRegionDNS) initDB(c *caddy.Controller) error {
|
||||
dialect, sqlStr, err := utils.TransSQLAchemyURL(r.SqlConnection)
|
||||
if err != nil {
|
||||
return err
|
||||
options := &common_options.DBOptions{
|
||||
SqlConnection: r.SqlConnection,
|
||||
}
|
||||
sqlDb, err := sql.Open(dialect, sqlStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sqlDb.SetMaxOpenConns(defaultDbMaxOpenConn)
|
||||
sqlDb.SetMaxIdleConns(defaultDbMaxIdleConn)
|
||||
sqlchemy.SetDB(sqlDb)
|
||||
|
||||
cloudcommon.InitDBConn(options)
|
||||
|
||||
db.InitAllManagers()
|
||||
|
||||
c.OnShutdown(func() error {
|
||||
@@ -206,9 +201,9 @@ func (r *SRegionDNS) ServeDNS(ctx context.Context, w dns.ResponseWriter, rmsg *d
|
||||
}
|
||||
|
||||
var (
|
||||
errRefused = errors.New("refused the query")
|
||||
errNotFound = errors.New("not found")
|
||||
errCallNext = errors.New("continue to next")
|
||||
errRefused = errors.Error("refused the query")
|
||||
errNotFound = errors.Error("not found")
|
||||
errCallNext = errors.Error("continue to next")
|
||||
)
|
||||
|
||||
// Services implements the ServiceBackend interface
|
||||
|
||||
Reference in New Issue
Block a user