当一个人测试系统时,不会发生这些错误。但是通过 jmeter 测试,我可以非常可靠地重现一些错误,例如:
ActiveRecord::JDBCError: SAVEPOINT active_record_1 does not exist: ROLLBACK TO SAVEPOINT active_record_1
Stack:
gems/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `log'
gems/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract_adapter.rb:200:in `log'
gems/gems/activerecord-jdbc-adapter-1.2.1/lib/arjdbc/jdbc/adapter.rb:208:in `execute'
gems/gems/activerecord-jdbc-adapter-1.2.1/lib/arjdbc/mysql/adapter.rb:156:in `rollback_to_savepoint'
gems/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract/database_statements.rb:179:in `transaction'
gems/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract/database_statements.rb:171:in `transaction'
gems/gems/activerecord-3.0.10/lib/active_record/transactions.rb:207:in `transaction'
gems/gems/activerecord-3.0.10/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
gems/gems/activerecord-3.0.10/lib/active_record/transactions.rb:240:in `save'
gems/gems/activerecord-3.0.10/lib/active_record/transactions.rb:251:in `rollback_active_record_state!'
gems/gems/activerecord-3.0.10/lib/active_record/transactions.rb:239:in `save'
...(our code that simply calls save on a new instance of a model class)...
我们没有嵌套事务,甚至没有明确地使用它们。我发现围绕此错误消息的一个现有错误,但它不相关;我们不会截断或做任何 DDL 工作。只需创建记录并保存即可。
我们使用 Rails 3.0.10、JRuby 1.6.5、activerecord-jdbcmysql-adapter、Warbler 1.3.2 并通过 Elastic Beanstalk 部署在具有单个 Mysql 实例 v5.1.57 的 64 位 Tomcat 7/Amazon RDS 上。我们为 config.threadsafe 做好了准备!- 这感觉就像是 ActiveRecord 内部的某种竞赛 - 但是 ActiveRecord 应该在线程安全中工作,不是吗?
最后一点:我担心这是一个 JRuby 或 Warbler 问题,因为如果我们从 JRuby 切换到 MRI Ruby 1.9,我们将无法重现这个问题。