mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
Add a max_idle_connections parameter.
This commit is contained in:
@@ -98,6 +98,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
|
||||
}
|
||||
|
||||
@@ -19,13 +19,24 @@ func pathConfigConnection(b *backend) *framework.Path {
|
||||
},
|
||||
"value": &framework.FieldSchema{
|
||||
Type: framework.TypeString,
|
||||
Description: `
|
||||
DB connection string. Use 'connection_url' instead.
|
||||
This will be deprecated.`,
|
||||
Description: `DB connection string. Use 'connection_url' instead.
|
||||
This will be deprecated.`,
|
||||
},
|
||||
"max_open_connections": &framework.FieldSchema{
|
||||
Type: framework.TypeInt,
|
||||
Description: "Maximum number of open connections to the database",
|
||||
Type: framework.TypeInt,
|
||||
Description: `Maximum number of open connections to the database;
|
||||
a zero uses the default value of two and a
|
||||
negative value means unlimited`,
|
||||
},
|
||||
|
||||
// Implementation note:
|
||||
"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.`,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -48,6 +59,14 @@ func (b *backend) pathConnectionWrite(
|
||||
maxOpenConns = 2
|
||||
}
|
||||
|
||||
maxIdleConns := data.Get("max_idle_connections").(int)
|
||||
if maxIdleConns == 0 {
|
||||
maxIdleConns = maxOpenConns
|
||||
}
|
||||
if maxIdleConns > maxOpenConns {
|
||||
maxIdleConns = maxOpenConns
|
||||
}
|
||||
|
||||
// Verify the string
|
||||
db, err := sql.Open("postgres", connString)
|
||||
if err != nil {
|
||||
@@ -65,6 +84,7 @@ func (b *backend) pathConnectionWrite(
|
||||
ConnectionString: connString,
|
||||
ConnectionURL: connURL,
|
||||
MaxOpenConnections: maxOpenConns,
|
||||
MaxIdleConnections: maxIdleConns,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -84,6 +104,7 @@ type connectionConfig struct {
|
||||
// Deprecate "value" in coming releases
|
||||
ConnectionString string `json:"value"`
|
||||
MaxOpenConnections int `json:"max_open_connections"`
|
||||
MaxIdleConnections int `json:"max_idle_connections"`
|
||||
}
|
||||
|
||||
const pathConfigConnectionHelpSyn = `
|
||||
|
||||
Reference in New Issue
Block a user