Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared DB pools #1217

Merged
merged 4 commits into from
Mar 21, 2017
Merged

Shared DB pools #1217

merged 4 commits into from
Mar 21, 2017

Conversation

chrzaszcz
Copy link
Member

@chrzaszcz chrzaszcz commented Mar 13, 2017

Make DB connection pool configuration independent from the host config.

To declare a DB connection pool, use on of the following formats:

  {pool, odbc, PoolName}.
  {pool, odbc, PoolName, Options}.

PoolName is an atom and Options is a list of ODBC options. Options can be still specified at the top level.

  1. All hosts use the ‘default’ pool by default.
    To change this, use the {odbc_pool, Option} option (top-level or per-host).

  2. This means that setting ‘odbc_server’ is not enough for a DB connection to work. The default pool has to be declared as well.

  3. The ODBC options specified per-host are not allowed anymore. They have been replaced with the Options element of the pool declaration.

To update the previous config with ODBC enabled to the new format, add the following line to ejabberd.cfg:

{pool, odbc, default}.

@@ -57,11 +56,11 @@ query(Connection, Query, Timeout) when is_binary(Query) ->
query(Connection, Query, Timeout) ->
parse(odbc:sql_query(Connection, Query, Timeout)).

-spec prepare(Host :: ejabberd:server(), Connection :: term(), Name :: atom(), Table :: binary(),
-spec prepare(Pool :: mongoose_rdbms:pool(), Connection :: term(), Name :: atom(), Table :: binary(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Elvis:

Line 59 is too long: -spec prepare(Pool :: mongoose_rdbms:pool(), Connection :: term(), Name :: atom(), Table :: binary(),.

@@ -51,10 +51,10 @@ disconnect(Connection) ->
query(Connection, Query, _Timeout) ->
mysql_to_odbc(mysql:query(Connection, Query), Connection).

-spec prepare(Host :: ejabberd:server(), Connection :: term(), Name :: atom(), Table :: binary(),
-spec prepare(Pool :: mongoose_rdbms:pool(), Connection :: term(), Name :: atom(), Table :: binary(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Elvis:

Line 54 is too long: -spec prepare(Pool :: mongoose_rdbms:pool(), Connection :: term(), Name :: atom(), Table :: binary(),.

@@ -51,10 +51,10 @@ disconnect(Connection) ->
query(Connection, Query, _Timeout) ->
pgsql_to_odbc(epgsql:squery(Connection, Query)).

-spec prepare(Host :: ejabberd:server(), Connection :: term(), Name :: atom(), Table :: binary(),
-spec prepare(Pool :: mongoose_rdbms:pool(), Connection :: term(), Name :: atom(), Table :: binary(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Elvis:

Line 54 is too long: -spec prepare(Pool :: mongoose_rdbms:pool(), Connection :: term(), Name :: atom(), Table :: binary(),.

* **odbc_pool** (local)
* **Description:** Name of the default connection pool used to connect to the database.
* **Syntax:** `{odbc_pool, PoolName}`
* **Default:** `"deafult"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "default"

To declare a DB connection pool, use on of the following formats:

  {pool, odbc, PoolName}.
  {pool, odbc, PoolName, Options}.

PoolName is an atom and Options is a list of ODBC options. Options can be still specified at the top level.

1. All hosts use the ‘default’ pool by default.
  To change this, use the {odbc_pool, Option} option (top-level or per-host).

2. This means that setting ‘odbc_server’ is not enough for a DB connection to work. The default pool has to be declared as well.

3. The ODBC options specified per-host are not allowed anymore. They have been replaced with the Options element of the pool declaration.

To update the previous config with ODBC enabled to the new format, add the following line to ejabberd.cfg:

  {pool, odbc, default}.
Copy link
Contributor

@michalwski michalwski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for these changes @chrzaszcz. This was long waited feature!

I've put two comments which I'd like to get clarified.

Size
end.

-spec get_option(mongoose_rdbms:pool(), atom()) -> term().
get_option(Pool, Option) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it feel more natural if this function was moved to mongooseim_rdbms module?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation here was to avoid cyclic dependencies between modules - I would be less reluctant to allow mongoose_rdbms_sup call mongoose_rdbms if the worker logic was extracted from the latter - which I would recommend.

@@ -86,10 +85,10 @@ keepalive_exit(Config) ->
meck_config(Server, KeepaliveInterval) ->
meck:new(ejabberd_config, [no_link]),
meck:expect(ejabberd_config, get_local_option,
fun({odbc_keepalive_interval, _Host}) -> KeepaliveInterval;
({odbc_start_interval, _Host}) -> 30;
fun({odbc_keepalive_interval, odbc_pool, default}) -> KeepaliveInterval;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is a test. It's also a code we read and this 3 element tuple is not intuitive at first glance. Would it be possible to mock mongoose_rdbms_sup:get_option here instead of ejabberd_config:get_local_option?

That's OK if you don't have time for this @chrzaszcz now, I'd just like to know that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion makes sense. I don't feel it's necessary, but it would improve the readability and unit test isolation indeed.

@michalwski michalwski merged commit 9d4be70 into master Mar 21, 2017
@michalwski michalwski deleted the shared-db-pools branch March 21, 2017 07:12
@michalwski
Copy link
Contributor

Thanks!

fblackburn1 added a commit to wazo-platform/wazo-calld that referenced this pull request Aug 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants