By1995 opened a new issue, #17542:
URL: https://github.com/apache/shardingsphere/issues/17542

   version: 5.1.1  and latest
   project:    shardingsphere-proxy
   use  Atomikos
   
   I have two logical databases , sharding_db and sharding_db2
   
   Expected behavior:
   The two databases should support XA transaction.
   
   actual behavior:
   only  sharding_db2 supports XA transaction.
   sharding_db error:
   `ERROR 1815 (HY000): Internal error: javax.transaction.SystemException: 
There is no registered resource that can recover the given XAResource instance. 
   Please register a corresponding resource first.`
   
   I found shardingsphere have three virtual system databases;
   
   During initialization, the system database is also added to Engines of 
transactionContexts.
   if these databases are in this order ,like   local_db -> system_db->local_db,
   then error will happen, data before the system database will disappear.
   
   The problem is by
   class AtomikosTransactionManagerProvider 
   In close method exist userTransactionService.shutdown(true);
   
   The call stack:
   ContextManager :renewAllTransactionContext -> renewTransactionContext -> 
closeTransactionEngine ->  staleEngine.close();
   ShardingSphereTransactionManagerEngine : close
   XAShardingSphereTransactionManager: close   ->. 
xaTransactionManagerProvider.close();
   AtomikosTransactionManagerProvider: close. -> 
userTransactionService.shutdown(true);
   UserTransactionServiceImp: shutdown(true)
   Configuration: Configuration.shutdown(force) -> 
removeAndCloseResources(maxWaitTime <= 0);  // remove all resource , error 
happen
   
   `    public static synchronized void shutdown(long maxWaitTime) {
                if (service_ != null) {
                        service_.shutdown(maxWaitTime);
                        notifyAfterShutdown();
                        removeShutdownHooks();
                        removeAndCloseResources(maxWaitTime <= 0);
                        clearSystemComponents();
                }
        }`
   
   
![image](https://user-images.githubusercontent.com/37041805/167761400-404cb19a-8743-46c5-bebe-98b9d90397c1.png)
   
   `    private void renewTransactionContext(final String databaseName, final 
ShardingSphereResource resource) {
           ShardingSphereTransactionManagerEngine changedStaleEngine = 
transactionContexts.getEngines().get(databaseName);
           if (null != changedStaleEngine) {
               System.out.println("renewTransactionContext-A---------" + 
databaseName);
               closeTransactionEngine(changedStaleEngine);
           }
           System.out.println("renewTransactionContext----------" + 
databaseName);
           resource.getDataSources().forEach((key, value) -> 
System.out.println(key + " ----- " + value));
           transactionContexts.getEngines().put(databaseName, 
createNewEngine(resource.getDatabaseType(), resource.getDataSources()));
       }`
   
   
   
   
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
notifications-unsubscr...@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to