码迷,mamicode.com
首页 > 数据库 > 详细

ActiveMQ中使用mysql做持久化报错:Cannot execute statement: impossible to write to binary log since BINLOG_FORM

时间:2014-08-27 14:50:47      阅读:2492      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   os   java   使用   io   strong   for   

ActiveMQ中如果使用mysql innodb的同时,开启了binlog,那么在ack消息的时候,日志里就可会报错:java.sql.SQLException: Cannot execute statement: binlogging impossible since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.

bubuko.com,布布扣

这是因为,mysql默认的binlog_format是STATEMENT,而在READ COMMITTED或READ UNCOMMITTED隔离级别下,innodb只能使用的binlog_format是ROW。

而在ActiveMQ的store JDBC实现中(TransactionContext),为了提高并发性能,使用的是READ UNCOMMITTED:

  1. // a cheap dirty level that we can live with     
  2. private int transactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED; 
所以,就会出现上面的问题。

解决办法有两个:

1、在mysql里设置binlog_format为ROW,此时binlog会增大,但是一般来说对数据复制支持的更好,建议单机高性能环境下使用。

2、在activemq.xml的jdbcPersistenceAdapter里配置transactionIsolation=“4”,即TRANSACTION_REPEATABLE_READ,此时事务更严格,会影响性能,建议在集群、强实时一致、不强调单机性能的情况下使用。

可以参见源码里的说明:

  1. /**
  2.      * set the Transaction isolation level to something other that TRANSACTION_READ_UNCOMMITTED
  3.      * This allowable dirty isolation level may not be achievable in clustered DB environments
  4.      * so a more restrictive and expensive option may be needed like TRANSACTION_REPEATABLE_READ
  5.      * see isolation level constants in {@link java.sql.Connection}
  6.      * @param transactionIsolation the isolation level to use
  7.      */ 
  8.     public void setTransactionIsolation(int transactionIsolation) { 
  9.         this.transactionIsolation = transactionIsolation; 
  10.     } 

ActiveMQ中使用mysql做持久化报错:Cannot execute statement: impossible to write to binary log since BINLOG_FORM

标签:style   blog   http   os   java   使用   io   strong   for   

原文地址:http://blog.csdn.net/luo446718254/article/details/38868455

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!