0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Liberty Resource Adapter で commit‑priority をテストする

0
Last updated at Posted at 2026-10-29

目的

以前に作成した Resource Adapter に commit‑priority を設定し、コミット時の優先順位が正しく適用されているかを検証します。

で使用したものです。

commit-priority とは

resource-ref の commit-priority に数字を指定します。数字が大きいリソースほどトランザクション処理を優先して実行します。10 と 5 を指定している場合は、10 のリソースが優先されます。

詳しい内容は以下のサイトを確認します。

commit-priority の指定

class 中で指定される @Resource アノテーションと server.xml の JNDI 名にあわせて指定します。ibm-web-ext.xml で指定する resource-ref に commit-priority を指定します。

class のアノテーション

server.xml のリソース定義

ibm-web-ext.xml での commit-priority 指定

server.xml での commit-priority 指定

環境の構築

docker で環境を構築します。

git clone https://github.com/pdprof/resource-adapter.git
cd resource-adapter/resource-adapter-docker
./setup-docker.sh

Libertyを起動します。

./start.sh 

ibm-web-ext.xml の指定を確認

ibm-web-ext.xml に commit-priority を指定しているリソースにアクセスしてログを確認します。以下は localhost にアクセスするときのURLです。

トランザクションの処理時間は、下記パラメータで変更できます。

  • sleepTime, transaction begin から commit の間の時間
  • prepareTime, prepare 開始後、prepare 終了までの時間
  • commitTime, commit 開始後、commit 完了までの時間

以下の設定により、secondcf が commit 時に優先されていることが確認できます。

Resource cf (commit-priority=1)
Resource secondcf (commit-priority=2)

console.log
> HelloServlet.doGet start
= HelloServlet.doGet call   > ut.begin()
= HelloServlet.doGet called < ut.begin()
= HelloServlet.doGet call   > sleep time in ms = 1000
= HelloServlet.doGet called < sleep
= null: PdprofXAResource.start - 1463898948 flags = 0
= PdprofConnectionImpl.hello()
= null: PdprofXAResource.start - 1463898948 flags = 0
= PdprofConnectionImpl.hello(msg)
= HelloServlet.doGet call   > ut.commit()
= secondcf: PdprofXAResource.end - 1463898948 flags = 67108864
= cf: PdprofXAResource.end - 1463898948 flags = 67108864
> secondcf: PdprofXAResource.prepare start (sleep time in ms = 1000)
< secondcf: PdprofXAResource.prepare end id = 1463898948
> cf: PdprofXAResource.prepare start (sleep time in ms = 1000)
< cf: PdprofXAResource.prepare end id = 1463898948
> secondcf: PdprofXAResource.commit start (sleep time in ms = 20000)
< secondcf: PdprofXAResource.commit end id = 1463898948 isOnePhase = false
> cf: PdprofXAResource.commit start (sleep time in ms = 20000)
< cf: PdprofXAResource.commit end id = 1463898948 isOnePhase = false
= PdprofConnectionImpl.close()
= PdprofConnectionImpl.close()
= HelloServlet.doGet called < ut.commit()
< HelloServlet.doGet end

server.xml の指定を確認

server.xml に commit-priority を指定しているリソースにアクセスしてログを確認します。以下は localhost にアクセスするときのURLです。

トランザクションの処理時間は、下記パラメータで変更できます。

  • sleepTime, transaction begin から commit の間の時間
  • prepareTime, prepare 開始後、prepare 終了までの時間
  • commitTime, commit 開始後、commit 完了までの時間

以下の設定により、bcf が commit 時に優先されていることが確認できます。

Resource acf (commit-priority=5)
Resource bcf (commit-priority=10)

> CommitPriorityTestServlet.doGet start
= CommitPriorityTestServlet.doGet call   > ut.begin()
= CommitPriorityTestServlet.doGet called < ut.begin()
= CommitPriorityTestServlet.doGet call   > sleep time in ms = 0
= CommitPriorityTestServlet.doGet called < sleep
= null: PdprofXAResource.start - 1463898948 flags = 0
= PdprofConnectionImpl.hello(msg)
= null: PdprofXAResource.start - 1463898948 flags = 0
= PdprofConnectionImpl.hello(msg)
= CommitPriorityTestServlet.doGet call   > ut.commit()
= bcf: PdprofXAResource.end - 1463898948 flags = 67108864
= acf: PdprofXAResource.end - 1463898948 flags = 67108864
> bcf: PdprofXAResource.prepare start (sleep time in ms = 0)
< bcf: PdprofXAResource.prepare end id = 1463898948
> acf: PdprofXAResource.prepare start (sleep time in ms = 0)
< acf: PdprofXAResource.prepare end id = 1463898948
> bcf: PdprofXAResource.commit start (sleep time in ms = 5000)
< bcf: PdprofXAResource.commit end id = 1463898948 isOnePhase = false
> acf: PdprofXAResource.commit start (sleep time in ms = 5000)
< acf: PdprofXAResource.commit end id = 1463898948 isOnePhase = false
= PdprofConnectionImpl.close()
= PdprofConnectionImpl.close()
= CommitPriorityTestServlet.doGet called < ut.commit()
< CommitPriorityTestServlet.doGet end

server.xml を編集して bcf に対応する ra/resourceB の commit-priority を 3 に変更すると以下の様に acf と bcf の commit 順序が変わるのを確認できます。

> CommitPriorityTestServlet.doGet start
= CommitPriorityTestServlet.doGet call   > ut.begin()
= CommitPriorityTestServlet.doGet called < ut.begin()
= CommitPriorityTestServlet.doGet call   > sleep time in ms = 0
= CommitPriorityTestServlet.doGet called < sleep
= acf: PdprofXAResource.start - 1463898948 flags = 0
= PdprofConnectionImpl.hello(msg)
= bcf: PdprofXAResource.start - 1463898948 flags = 0
= PdprofConnectionImpl.hello(msg)
= CommitPriorityTestServlet.doGet call   > ut.commit()
= bcf: PdprofXAResource.end - 1463898948 flags = 67108864
= acf: PdprofXAResource.end - 1463898948 flags = 67108864
> acf: PdprofXAResource.prepare start (sleep time in ms = 0)
< acf: PdprofXAResource.prepare end id = 1463898948
> bcf: PdprofXAResource.prepare start (sleep time in ms = 0)
< bcf: PdprofXAResource.prepare end id = 1463898948
> acf: PdprofXAResource.commit start (sleep time in ms = 5000)
< acf: PdprofXAResource.commit end id = 1463898948 isOnePhase = false
> bcf: PdprofXAResource.commit start (sleep time in ms = 5000)
< bcf: PdprofXAResource.commit end id = 1463898948 isOnePhase = false
= PdprofConnectionImpl.close()
= PdprofConnectionImpl.close()
= CommitPriorityTestServlet.doGet called < ut.commit()
< CommitPriorityTestServlet.doGet end

トラブルシューティング

よく使用する Docker コマンドをまとめておきます。

docker ps # 動作中のContainer確認
docker logs -f resource-adapter # ログ確認
docker restart resource-adapter # 再起動
docker inspect resource-adapter # container 確認
docker exec -it resource-adapter bash # Container内状況確認
docker stop -t 1 resource-adapter # 1秒後に強制停止

まとめ

トランザクションの commit-priority についてテストしました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?