mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: set db connection keepalive options (#22357)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -94,6 +94,16 @@ func InitDB(options *common_options.DBOptions) {
|
||||
}
|
||||
sqlchemy.SetDBWithNameBackend(dbConn, sqlchemy.DefaultDB, backend)
|
||||
|
||||
if options.DbMaxWaitTimeoutSeconds <= 300 {
|
||||
options.DbMaxWaitTimeoutSeconds = 3600
|
||||
}
|
||||
// ConnMaxLifetime is the maximum amount of time a connection may be reused.
|
||||
// mysql default max_waitimeout is 28800 seconds, 1 hour should be enough
|
||||
// but if user set a customized mysql max_waittimeout, the value should be adjusted accordingly
|
||||
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()
|
||||
if err == nil {
|
||||
// connect to clickcloud
|
||||
|
||||
@@ -165,6 +165,8 @@ type DBOptions struct {
|
||||
|
||||
Clickhouse string `help:"Connection string for click house"`
|
||||
|
||||
DbMaxWaitTimeoutSeconds int `help:"max wait timeout for db connection, default 1 hour" default:"3600"`
|
||||
|
||||
OpsLogWithClickhouse bool `help:"store operation logs with clickhouse" default:"false"`
|
||||
EnableDBChecksumTables bool `help:"Enable DB tables with record checksum for consistency"`
|
||||
DBChecksumSkipInit bool `help:"Skip DB tables with record checksum calculation when init" default:"false"`
|
||||
|
||||
Reference in New Issue
Block a user