mirror of
https://gitee.com/johng/gf.git
synced 2024-12-03 20:58:47 +08:00
change MaxConnCount to 0 for ulimited connections for package gdb
This commit is contained in:
parent
71399d1f65
commit
b6df7b94d0
@ -250,6 +250,7 @@ type (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
defaultModelSafe = false
|
defaultModelSafe = false
|
||||||
|
defaultCharset = `utf8`
|
||||||
queryTypeNormal = 0
|
queryTypeNormal = 0
|
||||||
queryTypeCount = 1
|
queryTypeCount = 1
|
||||||
unionTypeNormal = 0
|
unionTypeNormal = 0
|
||||||
@ -260,8 +261,8 @@ const (
|
|||||||
insertOptionIgnore = 3
|
insertOptionIgnore = 3
|
||||||
defaultBatchNumber = 10 // Per count for batch insert/replace/save.
|
defaultBatchNumber = 10 // Per count for batch insert/replace/save.
|
||||||
defaultMaxIdleConnCount = 10 // Max idle connection count in pool.
|
defaultMaxIdleConnCount = 10 // Max idle connection count in pool.
|
||||||
defaultMaxOpenConnCount = 100 // Max open connection count in pool.
|
defaultMaxOpenConnCount = 0 // Max open connection count in pool. Default is no limit.
|
||||||
defaultMaxConnLifeTime = 30 * time.Second // Max life time for per connection in pool in seconds.
|
defaultMaxConnLifeTime = 30 * time.Second // Max lifetime for per connection in pool in seconds.
|
||||||
ctxTimeoutTypeExec = iota
|
ctxTimeoutTypeExec = iota
|
||||||
ctxTimeoutTypeQuery
|
ctxTimeoutTypeQuery
|
||||||
ctxTimeoutTypePrepare
|
ctxTimeoutTypePrepare
|
||||||
@ -409,7 +410,10 @@ func getConfigNodeByGroup(group string, master bool) (*ConfigNode, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(masterList) < 1 {
|
if len(masterList) < 1 {
|
||||||
return nil, gerror.NewCode(gcode.CodeInvalidConfiguration, "at least one master node configuration's need to make sense")
|
return nil, gerror.NewCode(
|
||||||
|
gcode.CodeInvalidConfiguration,
|
||||||
|
"at least one master node configuration's need to make sense",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if len(slaveList) < 1 {
|
if len(slaveList) < 1 {
|
||||||
slaveList = masterList
|
slaveList = masterList
|
||||||
@ -420,7 +424,11 @@ func getConfigNodeByGroup(group string, master bool) (*ConfigNode, error) {
|
|||||||
return getConfigNodeByWeight(slaveList), nil
|
return getConfigNodeByWeight(slaveList), nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, gerror.NewCodef(gcode.CodeInvalidConfiguration, "empty database configuration for item name '%s'", group)
|
return nil, gerror.NewCodef(
|
||||||
|
gcode.CodeInvalidConfiguration,
|
||||||
|
"empty database configuration for item name '%s'",
|
||||||
|
group,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,7 +481,7 @@ func (c *Core) getSqlDb(master bool, schema ...string) (sqlDb *sql.DB, err error
|
|||||||
}
|
}
|
||||||
// Default value checks.
|
// Default value checks.
|
||||||
if node.Charset == "" {
|
if node.Charset == "" {
|
||||||
node.Charset = "utf8"
|
node.Charset = defaultCharset
|
||||||
}
|
}
|
||||||
// Changes the schema.
|
// Changes the schema.
|
||||||
nodeSchema := c.schema.Val()
|
nodeSchema := c.schema.Val()
|
||||||
@ -521,13 +529,7 @@ func (c *Core) getSqlDb(master bool, schema ...string) (sqlDb *sql.DB, err error
|
|||||||
sqlDb.SetMaxOpenConns(defaultMaxOpenConnCount)
|
sqlDb.SetMaxOpenConns(defaultMaxOpenConnCount)
|
||||||
}
|
}
|
||||||
if c.config.MaxConnLifeTime > 0 {
|
if c.config.MaxConnLifeTime > 0 {
|
||||||
// Automatically checks whether MaxConnLifetime is configured using string like: "30s", "60s", etc.
|
sqlDb.SetConnMaxLifetime(c.config.MaxConnLifeTime)
|
||||||
// Or else it is configured just using number, which means value in seconds.
|
|
||||||
if c.config.MaxConnLifeTime > time.Second {
|
|
||||||
sqlDb.SetConnMaxLifetime(c.config.MaxConnLifeTime)
|
|
||||||
} else {
|
|
||||||
sqlDb.SetConnMaxLifetime(c.config.MaxConnLifeTime * time.Second)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
sqlDb.SetConnMaxLifetime(defaultMaxConnLifeTime)
|
sqlDb.SetConnMaxLifetime(defaultMaxConnLifeTime)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user