max_idle_connections added
This commit is contained in:
parent
03c7eb7d18
commit
7cdb8a28bc
|
@ -86,6 +86,7 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
|
|||
// Set some connection pool settings. We don't need much of this,
|
||||
// since the request rate shouldn't be high.
|
||||
b.db.SetMaxOpenConns(connConfig.MaxOpenConnections)
|
||||
b.db.SetMaxIdleConns(connConfig.MaxIdleConnections)
|
||||
|
||||
return b.db, nil
|
||||
}
|
||||
|
|
|
@ -82,7 +82,8 @@ func TestBackend_config_connection(t *testing.T) {
|
|||
configData := map[string]interface{}{
|
||||
"value": "",
|
||||
"connection_url": "sample_connection_url",
|
||||
"max_open_connections": 7,
|
||||
"max_open_connections": 9,
|
||||
"max_idle_connections": 7,
|
||||
"verify_connection": false,
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ This name is deprecated.`,
|
|||
Description: "Maximum number of open connections to database",
|
||||
},
|
||||
"max_idle_connections": &framework.FieldSchema{
|
||||
Type: framework.TypeInt,
|
||||
Description: 'Maximum number of idle connections to the database; a zero uses the value of max_open_connections and a negative value disables idle connections. If larger than max_open_connections it will be reduced to the same size.',
|
||||
Type: framework.TypeInt,
|
||||
Description: "Maximum number of idle connections to the database; a zero uses the value of max_open_connections and a negative value disables idle connections. If larger than max_open_connections it will be reduced to the same size.",
|
||||
},
|
||||
"verify_connection": &framework.FieldSchema{
|
||||
Type: framework.TypeBool,
|
||||
|
@ -84,6 +84,14 @@ func (b *backend) pathConnectionWrite(
|
|||
maxOpenConns = 2
|
||||
}
|
||||
|
||||
maxIdleConns := data.Get("max_idle_connections").(int)
|
||||
if maxIdleConns == 0 {
|
||||
maxIdleConns = maxOpenConns
|
||||
}
|
||||
if maxIdleConns > maxOpenConns {
|
||||
maxIdleConns = maxOpenConns
|
||||
}
|
||||
|
||||
// Don't check the connection_url if verification is disabled
|
||||
verifyConnection := data.Get("verify_connection").(bool)
|
||||
if verifyConnection {
|
||||
|
@ -105,6 +113,7 @@ func (b *backend) pathConnectionWrite(
|
|||
entry, err := logical.StorageEntryJSON("config/connection", connectionConfig{
|
||||
ConnectionURL: connURL,
|
||||
MaxOpenConnections: maxOpenConns,
|
||||
MaxIdleConnections: maxIdleConns,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -127,6 +136,7 @@ type connectionConfig struct {
|
|||
// Deprecate "value" in coming releases
|
||||
ConnectionString string `json:"value" structs:"value" mapstructure:"value"`
|
||||
MaxOpenConnections int `json:"max_open_connections" structs:"max_open_connections" mapstructure:"max_open_connections"`
|
||||
MaxIdleConnections int `json:"max_idle_connections" structs: "max_idle_connections" mapstructure:"max_idle_connections"`
|
||||
}
|
||||
|
||||
const pathConfigConnectionHelpSyn = `
|
||||
|
|
Loading…
Reference in a new issue