第10章 管理データソースの Data Grid Server への追加

管理データソースを Data Grid Server 設定に追加して、JDBC データベース接続の接続プールとパフォーマンスを最適化します。

10.1. 管理対象データソースの設定

Data Grid Server 設定の一部としてマネージドデータソースを作成し、JDBC データベース接続の接続プールとパフォーマンスを最適化します。その後、キャッシュ内のマネージドデータソースの JDNI 名を指定して、デプロイメントの JDBC 接続設定を一元化できます。

前提条件

  • データベースドライバーを、Data Grid Server インストールの server/lib ディレクトリーにコピーします。

手順

  1. Data Grid Server 設定を開いて編集します。
  2. data-sources セクションに新しい data-source を追加します。
  3. name 属性またはフィールドでデータソースを一意に識別します。
  4. jndi-name 属性またはフィールドを使用してデータソースの JNDI 名を指定します。

    ヒント

    JNDI 名を使用して、JDBC キャッシュストア設定でデータソースを指定します。

  5. truestatistics 属性またはフィールドの値に設定し、/metrics エンドポイント経由でデータソースの統計を有効にします。
  6. connection-factory セクションのデータソースへの接続方法を定義する JDBC ドライバーの詳細を提供します。

    1. driver 属性またはフィールドを使用して、データベースドライバーの名前を指定します。
    2. url 属性またはフィールドを使用して、JDBC 接続 URL を指定します。
    3. username および password 属性またはフィールドを使用して、認証情報を指定します。
    4. 必要に応じて他の設定を指定します。
  7. Data Grid Server ノードが接続をプールして再利用する方法を、connection-pool セクションの接続プール調整プロパティーで定義します。
  8. 変更を設定に保存します。

検証

以下のように、Data Grid コマンドラインインターフェイス (CLI) を使用して、データソース接続をテストします。

  1. CLI セッションを開始します。

    bin/cli.sh
  2. すべてのデータソースをリスト表示し、作成したデータソースが利用できることを確認します。

    server datasource ls
  3. データソース接続をテストします。

    server datasource test my-datasource

マネージドデータソースの設定

XML

<server xmlns="urn:infinispan:server:13.0">
  <data-sources>
     <!-- Defines a unique name for the datasource and JNDI name that you
          reference in JDBC cache store configuration.
          Enables statistics for the datasource, if required. -->
     <data-source name="ds"
                  jndi-name="jdbc/postgres"
                  statistics="true">
        <!-- Specifies the JDBC driver that creates connections. -->
        <connection-factory driver="org.postgresql.Driver"
                            url="jdbc:postgresql://localhost:5432/postgres"
                            username="postgres"
                            password="changeme">
           <!-- Sets optional JDBC driver-specific connection properties. -->
           <connection-property name="name">value</connection-property>
        </connection-factory>
        <!-- Defines connection pool tuning properties. -->
        <connection-pool initial-size="1"
                         max-size="10"
                         min-size="3"
                         background-validation="1000"
                         idle-removal="1"
                         blocking-timeout="1000"
                         leak-detection="10000"/>
     </data-source>
  </data-sources>
</server>

JSON

{
  "server": {
    "data-sources": [{
      "name": "ds",
      "jndi-name": "jdbc/postgres",
      "statistics": true,
      "connection-factory": {
        "driver": "org.postgresql.Driver",
        "url": "jdbc:postgresql://localhost:5432/postgres",
        "username": "postgres",
        "password": "changeme",
        "connection-properties": {
          "name": "value"
        }
      },
      "connection-pool": {
        "initial-size": 1,
        "max-size": 10,
        "min-size": 3,
        "background-validation": 1000,
        "idle-removal": 1,
        "blocking-timeout": 1000,
        "leak-detection": 10000
      }
    }]
  }
}

YAML

server:
  dataSources:
    - name: ds
      jndiName: 'jdbc/postgres'
      statistics: true
      connectionFactory:
        driver: "org.postgresql.Driver"
        url: "jdbc:postgresql://localhost:5432/postgres"
        username: "postgres"
        password: "changeme"
        connectionProperties:
          name: value
      connectionPool:
        initialSize: 1
        maxSize: 10
        minSize: 3
        backgroundValidation: 1000
        idleRemoval: 1
        blockingTimeout: 1000
        leakDetection: 10000