Forums: Open Discussion (Thread #23506)

多重化のコミット単位の設定 (2009-07-29 14:22 by ちょちょぽりす #45193)

こんにちは。

ちょちょぽりすいくおです。

今回初めて、TERASOLUNA Batch Framework for Javaフレームワークを使用して開発を試みていますが
結構苦戦しています。

そこで、標題の件、多重化のコミット単位の設定について教えて頂きたい事があります。

様々な資料をみるかぎり、チャンク単位、または分割キー単位のコミットは行えますが
分割キー全体で1トランザクションとしてコミットは可能なのでしょうか?

出来る場合、どのようにやってできるのでしょうか?


要件としては、1000件の各顧客の口座情報をマルチスレッドで別々に処理をさせておき、
どれか一つスレッドが失敗した場合ロールバックをさせたい。また、全スレッド成功した時点でコミットさせたい。

よろしくお願いします。

Reply to #45193×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 多重化のコミット単位の設定 (2009-07-29 18:19 by ahn #45196)

分割ジョブの子ジョブ全体を一つのトランザクションとして制御することはできません。
ただし、この回答は現行のバッチフレームワークをそのまま利用する場合の話で
バッチフレームワークのトランザクションモデルを拡張すればできなくはないと思います。
Reply to #45193

Reply to #45196×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 多重化のコミット単位の設定 (2009-07-29 19:18 by ちょちょぽりす #45197)

早速のご回答ありがとうございます。

>バッチフレームワークのトランザクションモデルを拡張すればできなくはないと思います。

この回答からすると、拡張した方がよろしいのでしょうか?
それとも、バッチフレームワークを使用せずに、行った方がよろしいのでしょうか?

また、私が今考えてる方法として、ジョブ分割非トランザクションモデルを使用して
ジョブ定義モデル.xmlにtransactionManagerを定義し
----------------------------------------------------------------------------------------------------
  <!--ビジネスロジック-->
<bean id="blogic" scope="singleton" class="jp.terasoluna.batch.sample.uc00XX.JB0001BLogic">
<property name="queryDAO" ref="queryDAO" />
<property name="updateDAO" ref="updateDAO" />
<property name="transactionManager" ref="transactionManager" />
</bean>
----------------------------------------------------------------------------------------------------

ロジックで下記のように自前でトランザクションを開始して、コミット制御しようと考えています。
----------------------------------------------------------------------------------------------------
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

// トランザクション開始
TransactionStatus status = transactionManager.getTransaction(def);
// コミット
transactionManager.commit(status);
----------------------------------------------------------------------------------------------------

どうでしょうか?

よろしくお願いします。
Reply to #45196

Reply to #45197×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 多重化のコミット単位の設定 (2009-07-30 11:25 by ahn #45209)

拡張するかしないかの判断はプロジェクトの判断でお願いします。
また上記の拡張方法だと分割ジョブ内は1レコード毎にトランザクション制御がかかり
想定した動きにはならないと思います。

こちらで動作確認はできていませんが、
分割ジョブモデルの「PartitionSingleTransactionBean.xml」の
partitionSingleTransactionQueueProcessor定義をTransactionalQueueProcessorにし、
各子ジョブのsingleTransactionChildQueueProcessor定義を非トランザクション用の
プロセス「baseQueueProcessor」に設定すれば対応可能ではないかと考えております。

上記にも書きましたが、これらの拡張につきましてはプロジェクトの責任でご判断下さい。
Reply to #45197

Reply to #45209×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 多重化のコミット単位の設定 (2009-07-30 14:35 by ちょちょぽりす #45210)

ご返答ありがとうございます。

もちろん、判断につきましてはプロジェクトの責任で行います。

ahnさんのご回答の内容を要約すると、自前のジョブ定義ファイル.xmlにPartitionSingleTransactionBean.xmlを
importしPartitionSingleTransactionBean.xmlを拡張すれば良いという事でよろしいのでしょうか。

また、下記の内容に合わせ、
>partitionSingleTransactionQueueProcessor定義をTransactionalQueueProcessorにし、
>各子ジョブのsingleTransactionChildQueueProcessor定義を非トランザクション用の
>プロセス「baseQueueProcessor」に設定すれば対応可能ではないかと考えております。

下記のようにPartitionSingleTransactionBean.xmlを変更しましたが、分割キー全体で
1コミットとして扱われず複数回コミットされてしまいました。
----------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

<!-- プレースホルダ -->
<import resource="classpath:common/PlaceHolderConfig.xml" />

<!-- ===================== マネージャ定義 ===================== -->
<!-- ジョブ分割を行う親ジョブのマネージャ -->
<bean id="jobManager" parent="baseManager">
<property name="name" value="partitionSingleTransactionJobManager" />
<property name="collector" ref="partitionkeyCollector" />
<property name="workQueueFactory">
<bean class="${workQueueFactory.class}">
<property name="workerExecutorService" ref="workerExecutorService" />

<!-- <property name="queueProcessor" ref="partitionSingleTransactionQueueProcessor" /> -->
<!--20090730 hiro 修正 ●↑↑↑修正前 ↓↓↓修正後 -->
<property name="queueProcessor" ref="transactionalQueueProcessor" />


<property name="queueLength" ref="partitionQueueLength" />
<property name="multiplicity" ref="multiplicity" />
</bean>
</property>
<!-- 親ジョブ前処理 -->
<property name="preProcessor" ref="parentJobPreProcessor" />
<!-- 親ジョブ後処理 -->
<property name="postProcessor" ref="parentJobPostProcessor" />
</bean>

<!-- 親ジョブ前処理 -->
<bean id="parentJobPreProcessor" parent="transactionalSupportProcessor">
<property name="supportProcessor">
<bean parent="transactionalStandardSupportProcessor">
<property name="supportProcessorName" ref="parentJobPreProcessorName" />
<property name="supportLogicList" ref="parentjobPreLogicList" />
</bean>
</property>
</bean>

<!-- 親ジョブ後処理 -->
<bean id="parentJobPostProcessor" parent="transactionalSupportProcessor">
<property name="supportProcessor">
<bean parent="transactionalStandardSupportProcessor">
<property name="supportProcessorName" ref="parentJobPostProcessorName" />
<property name="supportLogicList" ref="parentjobPostLogicList" />
</bean>
</property>
</bean>

<!-- ===================== キュープロセッサ定義 ===================== -->
<!--
<bean id="partitionSingleTransactionQueueProcessor" parent="baseQueueProcessor">
<property name="name" value="partitionSingleTransactionQueueProcessor" />
<property name="worker" ref="childJobManager" />
</bean>
-->
<!--20090730 hiro 修正 ●↑↑↑修正前 ↓↓↓修正後 -->
<bean id="transactionalQueueProcessor" parent="baseQueueProcessor">
<property name="name" value="transactionalQueueProcessor" />
<property name="worker" ref="childJobManager" />
</bean>



<!-- 子ジョブのマネージャ -->
<bean id="childJobManager" parent="baseManager">
<property name="name" value="childJobManager" />
<property name="collector" ref="collector" />
<property name="workQueueFactory">
<bean class="${workQueueFactory.class}">
<property name="workerExecutorService" ref="workerExecutorService" />


<!-- <property name="queueProcessor" ref="singleTransactionChildQueueProcessor" /> -->
<!--20090730 hiro 修正 ●↑↑↑修正前 ↓↓↓修正後 -->
<property name="queueProcessor" ref="baseQueueProcessor" />


<property name="queueLength" ref="chunkQueueLength" />
</bean>
</property>
<!-- ジョブ前処理 -->
<property name="preProcessor" ref="jobPreProcessor" />
<!-- ジョブ後処理 -->
<property name="postProcessor" ref="jobPostProcessor" />
</bean>

<!-- ジョブ前処理 -->
<bean id="jobPreProcessor" parent="transactionalSupportProcessor">
<property name="supportProcessor">
<bean parent="transactionalStandardSupportProcessor">
<property name="supportProcessorName" ref="jobPreProcessorName" />
<property name="supportLogicList" ref="jobPreLogicList" />
</bean>
</property>
</bean>

<!-- ジョブ後処理 -->
<bean id="jobPostProcessor" parent="transactionalSupportProcessor">
<property name="supportProcessor">
<bean parent="transactionalStandardSupportProcessor">
<property name="supportProcessorName" ref="jobPostProcessorName" />
<property name="supportLogicList" ref="jobPostLogicList" />
</bean>
</property>
</bean>

<!-- ===================== キュープロセッサ定義 ===================== -->
<!--
<bean id="singleTransactionChildQueueProcessor" class="jp.terasoluna.fw.batch.springsupport.transaction.TransactionalQueueProcessor">
<property name="name" value="singleTransactionChildQueueProcessor" />
<property name="worker" ref="singleTransactionWorker" />
-->
<!-- 先頭チャンク前処理 -->
<!--
<property name="preProcessor" ref="firstchunkPreProcessor" />
-->
<!-- 最終チャンク後処理 -->
<!--
<property name="postProcessor" ref="lastchunkPostProcessor" />

</bean>
-->
<!--20090730 hiro 修正 ●↑↑↑修正前 ↓↓↓修正後 -->
<bean id="baseQueueProcessor" class="jp.terasoluna.fw.batch.springsupport.transaction.TransactionalQueueProcessor">
<property name="name" value="baseQueueProcessor" />
<property name="worker" ref="singleTransactionWorker" />
<!-- 先頭チャンク前処理 -->
<property name="preProcessor" ref="firstchunkPreProcessor" />
<!-- 最終チャンク後処理 -->
<property name="postProcessor" ref="lastchunkPostProcessor" />
</bean>



<!-- 先頭チャンク前処理 -->
<bean id="firstchunkPreProcessor" parent="transactionalStandardSupportProcessor">
<property name="supportProcessorName" ref="firstchunkPreProcessorName" />
<property name="supportLogicList" ref="firstchunkPreLogicList" />
</bean>

<!-- 最終チャンク後処理 -->
<bean id="lastchunkPostProcessor" parent="transactionalStandardSupportProcessor">
<property name="supportProcessorName" ref="lastchunkPostProcessorName" />
<property name="supportLogicList" ref="lastchunkPostLogicList" />
</bean>

<!-- ===================== ワーカ定義 ===================== -->
<bean id="singleTransactionWorker" class="jp.terasoluna.fw.batch.core.JobWorker">
<property name="blogicExecutor" ref="blogicExecutor" />
<property name="batchUpdateProcessor" ref="batchUpdateProcessor" />
<property name="exceptionHandlerMap" ref="exceptionHandlerMap" />
<property name="defaultJobExceptionHandler" ref="defaultJobExceptionHandler" />
<property name="batchUpdateResultHandler" ref="batchUpdateResultHandler" />
</bean>

<bean id="batchUpdateProcessor" class="jp.terasoluna.fw.batch.standard.StandardBatchUpdateProcessor">
<property name="updateDAO" ref="updateDAO" />
</bean>

<bean id="blogicExecutor" class="jp.terasoluna.fw.batch.core.StandardBLogicExecutor">
<property name="blogic" ref="blogic" />
<property name="blogicResultHandler" ref="BLogicResultHandler" />
<property name="exceptionHandlerMap" ref="exceptionHandlerMap" />
<property name="defaultJobExceptionHandler" ref="defaultJobExceptionHandler" />
</bean>

<!-- JobStatus設定 -->
<bean id="MonitorableJobStatus" class="jp.terasoluna.fw.batch.monitor.MonitorableTransactionalJobStatus" scope="prototype">
<property name="mbeanRegister" ref="MBeanRegister" />
<property name="transactionManager" ref="transactionManager" />
<property name="useSavepoint" ref="useSavepoint" />
<property name="partitionNo" value="-1" />
</bean>

<bean id="JobStatus" class="jp.terasoluna.fw.batch.springsupport.transaction.TransactionalJobStatus" scope="prototype">
<property name="transactionManager" ref="transactionManager" />
<property name="useSavepoint" ref="useSavepoint" />
<property name="partitionNo" value="-1" />
</bean>

<!-- ===================== スレッドプール作成時のサイズ ===================== -->
<bean id="threadSize" class="jp.terasoluna.fw.batch.springsupport.standard.ThreadSizeFactoryBean">
<property name="multiplicity" ref="multiplicity" />
</bean>

</beans>

----------------------------------------------------------------------------------------------------------
上記、PartitionSingleTransactionBean.xmlにおかしな記述箇所があればご教授頂けると幸いです。
また、修正箇所は「●」が記述してあります。

よろしくお願い致します。
Reply to #45209

Reply to #45210×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login