mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 11:38:02 +00:00
max_idle_connections added
This commit is contained in:
@@ -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,
|
// Set some connection pool settings. We don't need much of this,
|
||||||
// since the request rate shouldn't be high.
|
// since the request rate shouldn't be high.
|
||||||
b.db.SetMaxOpenConns(connConfig.MaxOpenConnections)
|
b.db.SetMaxOpenConns(connConfig.MaxOpenConnections)
|
||||||
|
b.db.SetMaxIdleConns(connConfig.MaxIdleConnections)
|
||||||
|
|
||||||
return b.db, nil
|
return b.db, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ func TestBackend_config_connection(t *testing.T) {
|
|||||||
configData := map[string]interface{}{
|
configData := map[string]interface{}{
|
||||||
"value": "",
|
"value": "",
|
||||||
"connection_url": "sample_connection_url",
|
"connection_url": "sample_connection_url",
|
||||||
"max_open_connections": 7,
|
"max_open_connections": 9,
|
||||||
|
"max_idle_connections": 7,
|
||||||
"verify_connection": false,
|
"verify_connection": false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ This name is deprecated.`,
|
|||||||
},
|
},
|
||||||
"max_idle_connections": &framework.FieldSchema{
|
"max_idle_connections": &framework.FieldSchema{
|
||||||
Type: framework.TypeInt,
|
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.',
|
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{
|
"verify_connection": &framework.FieldSchema{
|
||||||
Type: framework.TypeBool,
|
Type: framework.TypeBool,
|
||||||
@@ -84,6 +84,14 @@ func (b *backend) pathConnectionWrite(
|
|||||||
maxOpenConns = 2
|
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
|
// Don't check the connection_url if verification is disabled
|
||||||
verifyConnection := data.Get("verify_connection").(bool)
|
verifyConnection := data.Get("verify_connection").(bool)
|
||||||
if verifyConnection {
|
if verifyConnection {
|
||||||
@@ -105,6 +113,7 @@ func (b *backend) pathConnectionWrite(
|
|||||||
entry, err := logical.StorageEntryJSON("config/connection", connectionConfig{
|
entry, err := logical.StorageEntryJSON("config/connection", connectionConfig{
|
||||||
ConnectionURL: connURL,
|
ConnectionURL: connURL,
|
||||||
MaxOpenConnections: maxOpenConns,
|
MaxOpenConnections: maxOpenConns,
|
||||||
|
MaxIdleConnections: maxIdleConns,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -127,6 +136,7 @@ type connectionConfig struct {
|
|||||||
// Deprecate "value" in coming releases
|
// Deprecate "value" in coming releases
|
||||||
ConnectionString string `json:"value" structs:"value" mapstructure:"value"`
|
ConnectionString string `json:"value" structs:"value" mapstructure:"value"`
|
||||||
MaxOpenConnections int `json:"max_open_connections" structs:"max_open_connections" mapstructure:"max_open_connections"`
|
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 = `
|
const pathConfigConnectionHelpSyn = `
|
||||||
|
|||||||
Reference in New Issue
Block a user