Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Limit max connections to postgres; Don't log giant message on gateway…
Browse files Browse the repository at this point in the history
… startup

Test plan:
- spec and bvt passed
- provision a postgresql service, then use psql to verify the no. db_conn_limit+1 connection is refused by pg server
- verified that giant message is not logged

Change-Id: I57013c5a49c9fb749f1e1fe4204d85f930ee89d0
  • Loading branch information
figo authored and kushmerick committed Sep 9, 2011
1 parent 80b4e7b commit 56475ec
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions base/lib/base/provisioner.rb
Expand Up @@ -30,7 +30,7 @@ def flavor
# Updates our internal state to match that supplied by handles
# +handles+ An array of config handles
def update_handles(handles)
@logger.debug("Update handles: #{handles.inspect}")
@logger.info("[#{service_description}] Updating #{handles.size} handles")
handles.each do |handle|
h = handle.deep_dup
@prov_svcs[h['service_id']] = {
Expand All @@ -39,7 +39,7 @@ def update_handles(handles)
:service_id => h['service_id']
}
end
@logger.debug("[#{service_description}] Handles updated prov_svcs: #{@prov_svcs}")
@logger.info("[#{service_description}] Handles updated")
end

def find_all_bindings(name)
Expand Down
1 change: 1 addition & 0 deletions postgresql/bin/postgresql_node
Expand Up @@ -26,6 +26,7 @@ class VCAP::Services::Postgresql::NodeBin < VCAP::Services::Base::NodeBin
options[:max_long_query] = parse_property(config, "max_long_query", Integer)
options[:max_long_tx] = parse_property(config, "max_long_tx", Integer)
options[:postgresql] = parse_property(config, "postgresql", Hash)
options[:max_db_conns] = parse_property(config, "max_db_conns", Integer)
options
end

Expand Down
1 change: 1 addition & 0 deletions postgresql/config/postgresql_node.yml
Expand Up @@ -11,6 +11,7 @@ node_id: postgresql_node_1
max_db_size: 20
max_long_query: 3
max_long_tx: 30
max_db_conns: 20
postgresql:
host: 127.0.0.1
port: 5432
Expand Down
4 changes: 3 additions & 1 deletion postgresql/lib/postgresql_service/node.rb
Expand Up @@ -61,6 +61,7 @@ def initialize(options)
@max_db_size = options[:max_db_size] * 1024 * 1024
@max_long_query = options[:max_long_query]
@max_long_tx = options[:max_long_tx]
@max_db_conns = options[:max_db_conns]

@connection = postgresql_connect(@postgresql_config["host"],@postgresql_config["user"],@postgresql_config["pass"],@postgresql_config["port"],@postgresql_config["database"])

Expand Down Expand Up @@ -321,7 +322,8 @@ def create_database(provisionedservice)
user = bindusers[0].user
sys_user = bindusers[0].sys_user
@logger.info("Creating: #{provisionedservice.inspect}")
@connection.query("CREATE DATABASE #{name}")
@logger.debug("Maximum connections: #{@max_db_conns}")
@connection.query("CREATE DATABASE #{name} WITH CONNECTION LIMIT = #{@max_db_conns}")
@connection.query("REVOKE ALL ON DATABASE #{name} FROM PUBLIC")
if not create_database_user(name, bindusers[0], false) then
raise PostgresqlError.new(PostgresqlError::POSTGRESQL_LOCAL_DB_ERROR)
Expand Down
1 change: 1 addition & 0 deletions postgresql/spec/spec_helper.rb
Expand Up @@ -37,6 +37,7 @@ def getNodeTestConfig()
:postgresql => parse_property(config, "postgresql", Hash),
:ip_route => parse_property(config, "ip_route", String, :optional => true),
:max_long_tx => parse_property(config, "max_long_tx", Integer),
:max_db_conns => parse_property(config, "max_db_conns", Integer)
}
options
end
Expand Down

0 comments on commit 56475ec

Please sign in to comment.