在我们的一个环境中,mysql 复制间歇性地失败。下面是相关的mysql服务器日志。
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Connect_Retry: 60
Master_Log_File: mysql-bin.000421
Read_Master_Log_Pos: 997653853
Relay_Log_File: mysql-relay-bin.000058
Relay_Log_Pos: 498026393
Relay_Master_Log_File: mysql-bin.000421
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table: mysql.servers,mysql.proc,mysql.user,mysql.columns_priv,mysql.ndb_binlog_index,mysql.slow_log,mysql.event,mysql.tables_priv,mysql.procs_priv,mysql.func,mysql.general_log,mysql.db,mysql.plugin
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table: mysql.help%,ndbinfo.%,mysql.time_zone%,information_schema.%
Last_Errno: 1296
Last_Error: Error 'Got error 240 'Unknown error code' from NDBCLUSTER' on query. Default database: ''. Query: 'COMMIT'
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1296
Last_SQL_Error: Error 'Got error 240 'Unknown error code' from NDBCLUSTER' on query. Default database: ''. Query: 'COMMIT'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 22
Master_UUID:
Master_Info_File: /opt/mysql/cluster/server/database/master.info
1 row in set (0.00 sec)
Oracle 支持建议此错误代码与 Forgein Key 相关,因此我们可以隔离一些在特定故障时间发生的查询。
下面是最后一个 sql 成功插入主节点但未能复制到从节点。
### INSERT INTO `app_db`.`child_batch`
### SET
### @1=2080
### @4='000062'
### INSERT INTO `app_db`.`main_batch`
### SET
### @1=648518346341351432
### @6='NPROCESS\x02\x00\x00\x00\x00A\x00\x00\x00\x00\x00\x00\x00some_status\x00_app_event\x00ent\x00\x01\x0f\x11\x0f\x11\x0f\x08\x03@\x00\x00\x00'
### @7=0
与 child_batch 和 main_batch 表相关的有趣的事情是,两者都以 ID 作为主键,一个是 FK,另一个是 FK(InheritanceType.JOINED)。
在 JPA 中,它被设计为 InheritanceType.JOINED。
@Table(name = "main_batch")
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class MainBatch {
protected Long id;
protected Integer version;
private String transactionId;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public void setVersion(Integer version) {
this.version = version;
}
@Version
public Integer getVersion() {
return version;
}
@Column(name = "transaction_id")
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
}
@Table(name = "child_batch", uniqueConstraints = {
@UniqueConstraint(columnNames = {
"received_file_name"
})
})
@Entity
public class ChildBatch extends MainBatch {
private String receivedFileName;
@Column(name = "received_file_name")
public String getReceivedFileName() {
return receivedFileName;
}
public void setReceivedFileName(String receivedFileName) {
this.receivedFileName = receivedFileName;
}
}
- Mysql 版本:NDB 7.3.3 集群
- OpenJPA:2.2.2
- 爪哇:1.7.0_79
由于 Mysql 支持说这与外键有关,我怀疑 main_batch 和 child_batch 中的插入顺序在这里很重要。因为 child_batch.id 是 main_batch.id 的 FK。所以 main_batch 记录应该在插入 child_batch 记录之前首先可用。
如果有人有任何建议或想法,将不胜感激。提前致谢。