コネクション切断の問題を乗り越える方法
データベースサーバがリブートしたり、あるいはネットワーク障害が発生すると、データベースのコネクションプール内の全てのコネクションが切断され ます。通常、この問題を乗り越えるには、JIRA の再起動を行います(JIRA WAR ディストリビューションにおいては、JIRA を実行しているアプリケーションサーバを再起動する必要があります)。
しかし、単純な SQL クエリの実行によって、データベースのコネクションプール内のコネクションを有効にすることができます。プール内で切断されたデータベースコネクションが検出されると、新しいものが作成されてこれに置き替えられます。
To do this, you need to specify an optional <validation-query/>
element (in the dbconfig.xml
file of your JIRA Home Directory), whose content is the query which validates connections in the database connection pool. See the following procedure for details.
JIRA がデータベースコネクションを確実に有効にする方法
JIRA がデータベースのコネクションプール内のデータベースコネクションを確実に有効にするには:
- JIRA をシャットダウンします(もしくは JIRA を実行中の Tomcat インストレーション)
- Edit the
dbconfig.xml
file at the root of your JIRA Home Directory or use the Advanced tab of the JIRA Configuration Tool to configure the relevant settings. - お使いのデータベース向けのバリデーションクエリを設定します:
If editing the
dbconfig.xml
file, add the<validation-query/>
element with the appropriate validation query for your type of database, as shown in the example below for MySQL. (See Determining the Validation Query below for details.)<?xml version="1.0" encoding="UTF-8"?> <jira-database-config> <name>defaultDS</name> <delegator-name>default</delegator-name> <database-type>mysql</database-type> <jdbc-datasource> <url>jdbc:mysql://dbserver:3306/jiradb?useUnicode=true&characterEncoding=UTF8&sessionVariables=storage_engine=InnoDB</url> <driver-class>com.mysql.jdbc.Driver</driver-class> <username>jiradbuser</username> <password>password</password> <pool-min-size>20</pool-min-size> <pool-max-size>20</pool-max-size> <pool-max-wait>30000</pool-max-wait> <validation-query>select 1</validation-query> <min-evictable-idle-time-millis>60000</min-evictable-idle-time-millis> <time-between-eviction-runs-millis>300000</time-between-eviction-runs-millis> <pool-max-idle>20</pool-max-idle> <pool-remove-abandoned>true</pool-remove-abandoned> <pool-remove-abandoned-timeout>300</pool-remove-abandoned-timeout> <pool-test-on-borrow>false</pool-test-on-borrow> <pool-test-while-idle>true</pool-test-while-idle> <validation-query-timeout>3</validation-query-timeout> </jdbc-datasource> </jira-database-config>
- If using the JIRA Configuration Tool, on the Advanced tab, select the Validation Query check box and enter the appropriate validation query for your type of database. (See Determining the Validation Query below for details.)
- バリデーションクエリのタイムアウトを指定します。この値は、データベースコネクションが切断されたものとシステムが判断するまで、システムが待機しなくてはならない適当な時間 (秒単位) となります:
- If editing the
dbconfig.xml
file, add the<validation-query-timeout/>
element with the appropriate length of time (in seconds).This should only be done for MySQL.
- If using the JIRA Configuration Tool, on the Advanced tab, select the Validation Query Timeout check box and enter the appropriate length of time (in seconds).
- If editing the
You may wish to specify the following options, which relate to the above validation query options (see Tuning Database Connections - Connection pool settings section for details):
JIRA 設定ツール 'Advanced' タブオプション
dbconfig.xml
の要素アイドル状態にテスト pool-test-while-idle
追い出し実行間の時間 time-between-eviction-runs-millis
追い出し可能な最小限のアイドル時間 min-evictable-idle-time-millis
Save your edited
dbconfig.xml
file (or click the Save button if using the JIRA Configuration Tool).- JIRA (もしくは、JIRA を実行している Tomcat) を再起動します。
Please Note: If you continue to have problems with connections closing, you may need to set the
time-between-eviction-runs-millis
parameter to a lower value or as a last resort, set test-on-borrow
to true
. For more information about test-on-borrow
, see Tuning Database Connections - Connection pool settings section.
バリデーションクエリおよびタイムアウトの決定
各データベースの種類におけるバリデーションクエリは、それぞれ若干異なる SQL 構文の条件を有しています。バリデーションクエリは、プールからコネクションが回収される度に実行されるため、可能な限りシンプルなものが臨まれます。バ リデーションクエリのタイムアウトは、MySQL 向けにおいてのみ設定します。
各バリデーションクエリに推奨されるバリデーションクエリを以下に紹介します。:
データベースタイプ | バリデーションクエリ | バリデーションクエリのタイムアウト |
---|---|---|
MySQL |
| 3 |
Microsoft SQL Server |
| N/A |
Oracle |
| N/A |
PostgreSQL |
| N/A |
If the Validation Query Timeout is used on any database other than MySQL it will cause significant problems with the JIRA instance.
結果
これで、データベースのコネクションプールにおける全てのコネクションが完全に失われても、JIRA 、あるいは JIRA を実行中のアプリケーションサーバを再起動させる事無くコネクションを回復できます。
パフォーマンス上の留意点:
- このオプションを設定すると、パフォーマンスに影響が及びますが、クエリそのものは素早く実行されるため、パフォーマンス上の全体的な影響は最低 限に保たれます。更に、このクエリが実行されるのは、コネクションが成立した場合においてのみとなります。よって、リクエストの間ずっとコネクションが保 たれると、クエリは一回のリクエストに対して一度のみしか発生しません。
- 大きな JIRA インストレーションを実行している場合は、これがもたらすパフォーマンス上の影響を評価してから実装した方がよいかもしれません。