Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomikos XA transaction started when it is not configured in server.yaml #18894

Closed
sandynz opened this issue Jul 6, 2022 · 11 comments
Closed

Comments

@sandynz
Copy link
Contributor

sandynz commented Jul 6, 2022

Bug Report

Which version of ShardingSphere did you use?

master branch, 0b41852

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

Proxy

Expected behavior

XA transaction won't be started.

Actual behavior

It started.

Reason analyze (If you can)

In GlobalRulesBuilder:
WX20220706-152940@2x

In XAShardingSphereTransactionManager:
Since AtomikosTransactionManagerProvider is the default impl of XATransactionManagerProvider, XATransactionManagerProviderFactory.getInstance(null) in XAShardingSphereTransactionManager.init return AtomikosTransactionManagerProvider instance.
图片

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

server.yaml:

mode:
  type: Cluster
  repository:
    type: ZooKeeper
    props:
      namespace: mysql
      server-lists: localhost:2181
      retryIntervalMilliseconds: 500
      timeToLiveSeconds: 60
      maxRetries: 3
      operationTimeoutMilliseconds: 500
  overwrite: false

rules:
  - !AUTHORITY
    users:
      - root@%:root
      - sharding@:sharding
    provider:
      type: ALL_PERMITTED
#  - !TRANSACTION
#    defaultType: XA
#    providerType: Atomikos
  - !SQL_PARSER
    sqlCommentParseEnabled: true
    sqlStatementCache:
      initialCapacity: 2000
      maximumSize: 65535
    parseTreeCache:
      initialCapacity: 128
      maximumSize: 1024

Global rules in ZK after Proxy 3307 started:

- !AUTHORITY
  provider:
    type: ALL_PERMITTED
  users:
  - root@%:root
  - sharding@%:sharding
- !SQL_PARSER
  parseTreeCache:
    initialCapacity: 128
    maximumSize: 1024
  sqlCommentParseEnabled: true
  sqlStatementCache:
    initialCapacity: 2000
    maximumSize: 65535

1, Start Proxy with 3307 port

2, Start another Proxy with 3308 port

The second one will start failed with exception:

[ERROR] 2022-07-06 15:16:50.805 [main] c.a.persistence.imp.LogFileLock - The specified log seems to be in use already: xa_tx in ./logs/. Make sure that no other instance is running, or kill any pending process if needed.
Exception in thread "main" com.atomikos.icatch.SysException: Error in init: The specified log seems to be in use already: xa_tx in ./logs/. Make sure that no other instance is running, or kill any pending process if needed.
	at com.atomikos.icatch.provider.imp.AssemblerImp.createRepository(AssemblerImp.java:200)
	at com.atomikos.icatch.provider.imp.AssemblerImp.assembleTransactionService(AssemblerImp.java:170)
	at com.atomikos.icatch.config.Configuration.assembleSystemComponents(Configuration.java:424)
	at com.atomikos.icatch.config.Configuration.init(Configuration.java:390)
	at com.atomikos.icatch.config.UserTransactionServiceImp.initialize(UserTransactionServiceImp.java:100)
	at com.atomikos.icatch.config.UserTransactionServiceImp.init(UserTransactionServiceImp.java:189)
	at org.apache.shardingsphere.transaction.xa.atomikos.manager.AtomikosTransactionManagerProvider.init(AtomikosTransactionManagerProvider.java:46)
	at org.apache.shardingsphere.transaction.xa.XAShardingSphereTransactionManager.init(XAShardingSphereTransactionManager.java:55)
	at org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine.lambda$init$0(ShardingSphereTransactionManagerEngine.java:66)
	at java.util.Map.forEach(Map.java:630)
	at org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine.init(ShardingSphereTransactionManagerEngine.java:66)
	at org.apache.shardingsphere.transaction.rule.TransactionRule.createTransactionManagerEngine(TransactionRule.java:75)
	at org.apache.shardingsphere.transaction.rule.TransactionRule.createTransactionManagerEngines(TransactionRule.java:67)
	at org.apache.shardingsphere.transaction.rule.TransactionRule.<init>(TransactionRule.java:61)
	at org.apache.shardingsphere.transaction.rule.builder.TransactionRuleBuilder.build(TransactionRuleBuilder.java:36)
	at org.apache.shardingsphere.transaction.rule.builder.TransactionRuleBuilder.build(TransactionRuleBuilder.java:32)
	at org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder.buildRules(GlobalRulesBuilder.java:53)
	at org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder.buildMetaDataContexts(ClusterContextManagerBuilder.java:91)
	at org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder.build(ClusterContextManagerBuilder.java:69)
	at org.apache.shardingsphere.proxy.initializer.BootstrapInitializer.createContextManager(BootstrapInitializer.java:66)
	at org.apache.shardingsphere.proxy.initializer.BootstrapInitializer.init(BootstrapInitializer.java:55)
	at org.apache.shardingsphere.proxy.Bootstrap.main(Bootstrap.java:50)
Caused by: com.atomikos.recovery.LogException: The specified log seems to be in use already: xa_tx in ./logs/. Make sure that no other instance is running, or kill any pending process if needed.
	at com.atomikos.persistence.imp.LogFileLock.acquireLock(LogFileLock.java:60)
	at com.atomikos.recovery.fs.FileSystemRepository.init(FileSystemRepository.java:53)
	at com.atomikos.icatch.provider.imp.AssemblerImp.createCoordinatorLogEntryRepository(AssemblerImp.java:248)
	at com.atomikos.icatch.provider.imp.AssemblerImp.createRepository(AssemblerImp.java:198)
	... 21 more

Example codes for reproduce this issue (such as a github link).

@jingshanglu
Copy link
Contributor

This is because two proxy are started on one machine, and the two proxy use the same file to record the transaction log, and different files can be used to record the transaction log.

@sandynz
Copy link
Contributor Author

sandynz commented Jul 6, 2022

Hi @jingshanglu , the root reason is Atomikos XA transaction started when it's not configured, starting 2 proxy instances and print exception just prove Atomikos XA transaction has been started.

Is XA transaction must be started?
And could it just start LOCAL transaction? (Looks defaultType is LOCAL in TransactionRuleConfiguration)

@jingshanglu
Copy link
Contributor

Hi @jingshanglu , the root reason is Atomikos XA transaction started when it's not configured, starting 2 proxy instances and print exception just prove Atomikos XA transaction has been started.

Is XA transaction must be started? And could it just start LOCAL transaction? (Looks defaultType is LOCAL in TransactionRuleConfiguration)

The XA transaction is not necessary. Currently, the specific implementation of TM is loaded through SPI. If there is an implementation of xa, the TM will be initialized unless the specific implementation of xa is removed. Any suggestions?

@sandynz
Copy link
Contributor Author

sandynz commented Jul 6, 2022

The XA transaction is not necessary. Currently, the specific implementation of TM is loaded through SPI. If there is an implementation of xa, the TM will be initialized unless the specific implementation of xa is removed. Any suggestions?

If !TRANSACTION is not configured in server.yaml:

  • Should TransactionRule be initialized?
  • If TransactionRule is initialized, what's the defaultType of transaction (TransactionType), LOCAL, XA or BASE?

@jingshanglu
Copy link
Contributor

The XA transaction is not necessary. Currently, the specific implementation of TM is loaded through SPI. If there is an implementation of xa, the TM will be initialized unless the specific implementation of xa is removed. Any suggestions?

If !TRANSACTION is not configured in server.yaml:

  • Should TransactionRule be initialized?
  • If TransactionRule is initialized, what's the defaultType of transaction (TransactionType), LOCAL, XA or BASE?
    If !TRANSACTION is not configured in server.yaml:
  • TransactionRule should be initialized, because ss should provide the default transaction function
  • LOCAL, Atomikos for XA

@sandynz
Copy link
Contributor Author

sandynz commented Jul 7, 2022

* TransactionRule should be initialized, because ss should provide the default transaction function

* LOCAL, Atomikos for XA

So could the default transaction function be LOCAL if !TRANSACTION is not configured?

XA is not necessary sometimes.

If we want to support XA even it's not configured, could we initialize XA implementation on demand?

@miaopass-future
Copy link

Hi, has this issue been resolved? I seem to have this problem too。The XA transaction does not seem to be opened, the LOCAL transaction is used

@sandynz
Copy link
Contributor Author

sandynz commented Sep 28, 2022

Hi, has this issue been resolved? I seem to have this problem too。The XA transaction does not seem to be opened, the LOCAL transaction is used

Yes, it's not updated. I just checked it.

Example server.yaml:

#  - !TRANSACTION
#    defaultType: XA
#    providerType: Atomikos

proxy log:

[INFO ] 2022-09-28 14:44:12.542 [main-EventThread] o.a.c.framework.imps.EnsembleTracker - New config event received: {}
Thanks for using Atomikos! This installation is not registered yet. 
REGISTER FOR FREE at http://www.atomikos.com/Main/RegisterYourDownload and receive:
- tips & advice 
- working demos 
- access to the full documentation 
- special exclusive bonus offers not available to others 
- everything you need to get the most out of using Atomikos!

@FlyingZC
Copy link
Member

FlyingZC commented Nov 8, 2022

@natehuangting

@natehuangting
Copy link
Contributor

I will implement this function, other transaction types will not be loaded by default, if you need to load other transaction types, please configure in loadTypes

@sandynz
Copy link
Contributor Author

sandynz commented May 17, 2023

Close it, it's fixed by #25696

@sandynz sandynz closed this as completed May 17, 2023
@sandynz sandynz added this to the 5.4.0 milestone May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants