WASdev / standards.jsr352.jbatch

Home of 'jbatch', a compatible implementation of the Jakarta Batch specification (and the former Reference Implementation for the JSR 352, Batch Applications for the Java Platform specification).
Other
21 stars 18 forks source link

Chunk step's reader/writer open() methods don't allow for configuration of tran timeout #58

Closed Juljan closed 4 years ago

Juljan commented 6 years ago

Hello,

There seems to have no way to override the Application Server default timeout for the open() method of the reader.

The following property from the job description xml is not considered for open() :

        <properties>
            <property name="javax.transaction.global.timeout" value="600"/>
        </properties>

If think thatChunkStepControllerImpl.invokeChunk() should call userTransaction.setTransactionTimeout() with the property value before the transactionManager.begin(); that precedes this.openReaderAndWriter(); .

private void invokeChunk() {
        logger.entering(sourceClass, "invokeChunk");

        List<Object> chunkToWrite = new ArrayList<Object>();

        try {
                        //should set the timeout here 
            transactionManager.begin();
            this.openReaderAndWriter();
            transactionManager.commit();

            while (true) {

                // Done with the previous chunk status so advance reference to next one.
                currentChunkStatus = getNextChunkStatusBasedOnPrevious();

                // Sequence surrounding beginCheckpoint() updated per MR
                // https://java.net/bugzilla/show_bug.cgi?id=5873
                setNextChunkTransactionTimeout();

                // Remember we "wrap" the built-in item-count + time-limit "algorithm"
                // in a CheckpointAlgorithm for ease in keeping the sequence consistent
                checkpointManager.beginCheckpoint();

                transactionManager.begin();
                                ...

To reproduce, just add some Thread.sleep() with a value higher than the application server default JTA timeout and you will see some logs and then an exception when the checkpoint is persisted.

<13-juin-2018, 11:21:52,518 AM CEST> <Info> <JTA> <BEA-111015> <The commit operation for transaction BEA1-04C735054CD03057A4BD timed out after 31 seconds.> 

com.ibm.jbatch.container.exception.PersistenceException: java.sql.SQLException: Unexpected exception while enlisting XAConnection java.sql.SQLException: Transaction rolled back: Transaction timed out after 31 seconds 
BEA1-04C735054CD03057A4BD
    at weblogic.jdbc.jta.DataSource.enlist(DataSource.java:1798)
scottkurz commented 6 years ago

Discussion

Good point to raise. The spec is not clear here.

The transaction around open() is managed by the batch impl, like the chunk-by-chunk transactions. It could be useful to allow the application some way to influence this.

I don't think there's a clear, obvious fix here, though.

If we don't think there's a need to set a separate timeout around open/close vs. the chunk-by-chunk timeout, we could start by looking at javax.transaction.global.timeout, and possibly ask if we should also call CheckpointAlgorithm.checkpointTimeout() first.

I recognize there's an asymmetry here in that the chunk-by-chunk timeouts will have been set on the thread by the time close() is called, unlike open().

Given that the existing behavior is well-defined, though, I would not want to risk breaking anyone by changing the behavior to, say, all of a sudden start using the javax.transaction.global.timeout value.

I'd like to leave this open, and possibly consider it as an issue against the spec, going forwards.

Workaround

In the meantime, I think you could workaround this for a non-partitioned step by using StepListener.beforeStep() and setting the transaction timeout on the thread.

scottkurz commented 4 years ago

I'm closing this issue here.

@Juljan feel free to open an issue at https://github.com/eclipse-ee4j/batch-api if you are still interested in this item. Thank you.