Skip to content

Commit 7baeb23

Browse files
swordqiuQiu Jian
andauthored
fix: region-dns not support dameng dialect (#23809)
Co-authored-by: Qiu Jian <[email protected]>
1 parent c8ccbc6 commit 7baeb23

File tree

2 files changed

+42
-40
lines changed

2 files changed

+42
-40
lines changed

pkg/cloudcommon/database.go

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,7 @@ import (
3939
"yunion.io/x/onecloud/pkg/util/dbutils"
4040
)
4141

42-
func InitDB(options *common_options.DBOptions) {
43-
if options.DebugSqlchemy {
44-
log.Warningf("debug Sqlchemy is turned on")
45-
sqlchemy.DEBUG_SQLCHEMY = true
46-
}
47-
48-
log.Infof("Registered SQL drivers: %s", strings.Join(sql.Drivers(), ", "))
49-
50-
consts.QueryOffsetOptimization = options.QueryOffsetOptimization
51-
52-
if options.HistoricalUniqueName {
53-
consts.EnableHistoricalUniqueName()
54-
} else {
55-
consts.DisableHistoricalUniqueName()
56-
}
57-
58-
if options.OpsLogMaxKeepMonths > 0 {
59-
consts.SetSplitableMaxKeepMonths(options.OpsLogMaxKeepMonths)
60-
}
61-
if options.SplitableMaxDurationHours > 0 {
62-
consts.SetSplitableMaxDurationHours(options.SplitableMaxDurationHours)
63-
}
64-
42+
func InitDBConn(options *common_options.DBOptions) {
6543
dialect, sqlStr, err := options.GetDBConnection()
6644
if err != nil {
6745
log.Fatalf("Invalid SqlConnection string: %s error: %v", options.SqlConnection, err)
@@ -103,8 +81,10 @@ func InitDB(options *common_options.DBOptions) {
10381
dbConn.SetConnMaxLifetime(time.Duration(options.DbMaxWaitTimeoutSeconds) * time.Second)
10482
// ConnMaxIdleTime should be half of ConnMaxLifetime
10583
dbConn.SetConnMaxIdleTime(time.Duration(options.DbMaxWaitTimeoutSeconds/2) * time.Second)
84+
}
10685

107-
dialect, sqlStr, err = options.GetClickhouseConnStr()
86+
func InitClickhouseConn(options *common_options.DBOptions) {
87+
dialect, sqlStr, err := options.GetClickhouseConnStr()
10888
if err == nil {
10989
// connect to clickcloud
11090
// force convert sqlstr from clickhouse v2 to v1
@@ -126,6 +106,33 @@ func InitDB(options *common_options.DBOptions) {
126106
consts.OpsLogWithClickhouse = true
127107
}
128108
}
109+
}
110+
111+
func InitDB(options *common_options.DBOptions) {
112+
if options.DebugSqlchemy {
113+
log.Warningf("debug Sqlchemy is turned on")
114+
sqlchemy.DEBUG_SQLCHEMY = true
115+
}
116+
117+
log.Infof("Registered SQL drivers: %s", strings.Join(sql.Drivers(), ", "))
118+
119+
consts.QueryOffsetOptimization = options.QueryOffsetOptimization
120+
121+
if options.HistoricalUniqueName {
122+
consts.EnableHistoricalUniqueName()
123+
} else {
124+
consts.DisableHistoricalUniqueName()
125+
}
126+
127+
if options.OpsLogMaxKeepMonths > 0 {
128+
consts.SetSplitableMaxKeepMonths(options.OpsLogMaxKeepMonths)
129+
}
130+
if options.SplitableMaxDurationHours > 0 {
131+
consts.SetSplitableMaxDurationHours(options.SplitableMaxDurationHours)
132+
}
133+
134+
InitDBConn(options)
135+
InitClickhouseConn(options)
129136

130137
switch options.LockmanMethod {
131138
case common_options.LockMethodInMemory, "":

pkg/dns/dns.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ package dns
1616

1717
import (
1818
"context"
19-
"database/sql"
20-
"errors"
2119
"fmt"
2220
"strconv"
2321
"strings"
@@ -33,13 +31,15 @@ import (
3331

3432
"yunion.io/x/jsonutils"
3533
"yunion.io/x/log"
36-
"yunion.io/x/pkg/utils"
34+
"yunion.io/x/pkg/errors"
3735
"yunion.io/x/sqlchemy"
3836
_ "yunion.io/x/sqlchemy/backends"
3937

4038
api "yunion.io/x/onecloud/pkg/apis/compute"
4139
identity_api "yunion.io/x/onecloud/pkg/apis/identity"
40+
"yunion.io/x/onecloud/pkg/cloudcommon"
4241
"yunion.io/x/onecloud/pkg/cloudcommon/db"
42+
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
4343
"yunion.io/x/onecloud/pkg/compute/models"
4444
"yunion.io/x/onecloud/pkg/mcclient"
4545
"yunion.io/x/onecloud/pkg/mcclient/auth"
@@ -99,17 +99,12 @@ func New() *SRegionDNS {
9999
}
100100

101101
func (r *SRegionDNS) initDB(c *caddy.Controller) error {
102-
dialect, sqlStr, err := utils.TransSQLAchemyURL(r.SqlConnection)
103-
if err != nil {
104-
return err
105-
}
106-
sqlDb, err := sql.Open(dialect, sqlStr)
107-
if err != nil {
108-
return err
102+
options := &common_options.DBOptions{
103+
SqlConnection: r.SqlConnection,
109104
}
110-
sqlDb.SetMaxOpenConns(defaultDbMaxOpenConn)
111-
sqlDb.SetMaxIdleConns(defaultDbMaxIdleConn)
112-
sqlchemy.SetDB(sqlDb)
105+
106+
cloudcommon.InitDBConn(options)
107+
113108
db.InitAllManagers()
114109

115110
c.OnShutdown(func() error {
@@ -206,9 +201,9 @@ func (r *SRegionDNS) ServeDNS(ctx context.Context, w dns.ResponseWriter, rmsg *d
206201
}
207202

208203
var (
209-
errRefused = errors.New("refused the query")
210-
errNotFound = errors.New("not found")
211-
errCallNext = errors.New("continue to next")
204+
errRefused = errors.Error("refused the query")
205+
errNotFound = errors.Error("not found")
206+
errCallNext = errors.Error("continue to next")
212207
)
213208

214209
// Services implements the ServiceBackend interface

0 commit comments

Comments
 (0)