javaspringspring-boottransactionsatomikos

XA resource has become unavailable XID raised -7


I am getting below error in a random way. It doesn't throw error initially but after a while the error is thrown. Once I restart my server everything gets reset and error is not thrown.

XA resource 'XXXXAtomikosDataSource': resume for XID '31302E3137382E36382E3235302E746D30303031353030303138:31302E3137382E36382E3235302E746D3135' raised -7: the XA resource has become unavailable

I am using below dependencies.

   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jta-atomikos</artifactId>
        <version>1.4.2.RELEASE</version>
   </dependency>

And with configuration beans

    @Bean(name= "userTransaction")
    public UserTransaction userTransaction() throws Throwable {
       UserTransactionImp userTransactionImp = new UserTransactionImp();
       return userTransactionImp;
    }

    @Bean
    @Primary
    public TransactionManager atomTransactionManager() throws Throwable {
        UserTransactionManager userTransactionManager = new UserTransactionManager();
        userTransactionManager.setForceShutdown(false);

        return userTransactionManager;
    }

    @Bean("atomikosTransactionManager")
    public PlatformTransactionManager platformTransactionManager()  throws Throwable {
        UserTransaction userTransaction = userTransaction();
        TransactionManager transactionManager = atomTransactionManager();

        JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(userTransaction, transactionManager);
        jtaTransactionManager.setAllowCustomIsolationLevels(true);
        jtaTransactionManager.setDefaultTimeout(1000);

        return jtaTransactionManager;
    }

    @Bean(name = "atomikosDataSources")
    public Map<String, DataSource> atomikosDataSources(PropertiesFactoryBean databaseProperties, Environment environment, BcusDefaultEncrytor bcusDefaultEncrytor) throws SQLException, IOException {

        List<String> databases= Collections.list(databaseProperties.getObject().propertyNames()).stream().map(key->key.toString()).filter(key-> key.contains("url")).collect(Collectors.toList());

        Map<String, DataSource> collect = databases.stream().collect(Collectors.toMap(dbName -> dbName.split("\\.")[0].toUpperCase() + "AtomikosDataSource", dbName -> {

            OracleXADataSource dataSource = null;
            try {
                dataSource = new OracleXADataSource();
                dataSource.setURL(environment.getProperty(dbName));
                dataSource.setUser(environment.getProperty("database.username"));
                dataSource.setPassword(bcusDefaultEncrytor.decryptQAPassword(environment.getProperty("database.password")));
            }
            catch (SQLException e)
            {
                LOG.error(
                        "DatabaseConditionException [errorCode= Error while configuring atomikos data sources- Could not OracleXADataSource object, errorMessage= {} ]",
                        e.getMessage());
            }
            catch (Exception e) {
                LOG.error(
                        "DatabaseConditionException [errorCode= Error while configuring atomikos data sources- Could not decrypt QA Password make sure you have proper **QA** Encryption password in your folder, errorMessage= {} ]",
                        e.getMessage());            
            }

            AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
            xaDataSource.setXaDataSource(dataSource);
            xaDataSource.setUniqueResourceName(dbName.split("\\.")[0].toUpperCase() + "AtomikosDataSource");
            xaDataSource.setPoolSize(5);
            return xaDataSource;
        }));
        return collect;
    }

Solution

  • The issue is because of a bug in atomikos 3.9.3 version in spring-boot-starter-jta-atomikos brings:1.4.2.RELEASE.

    Once you update the version to atomikos 4.0.4, the issue resolves.

         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jta-atomikos</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>transactions-jdbc</artifactId>
                    <groupId>com.atomikos</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>transactions-jms</artifactId>
                    <groupId>com.atomikos</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>transactions-jta</artifactId>
                    <groupId>com.atomikos</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    
        <dependency>
            <groupId>com.atomikos</groupId>
            <artifactId>transactions-jms</artifactId>
            <version>${transaction.version}</version>
        </dependency>
        <dependency>
            <groupId>com.atomikos</groupId>
            <artifactId>transactions-jta</artifactId>
            <version>${transaction.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.geronimo.specs</groupId>
                    <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.atomikos</groupId>
            <artifactId>transactions-jdbc</artifactId>
            <version>${transaction.version}</version>
        </dependency>