use of com.alibaba.otter.canal.parse.exception.ServerIdNotMatchException in project canal by alibaba.
the class LocalBinLogConnection method checkServerId.
/**
* 1. 非 rdsOos 模式下需要要校验 serverId 是否一致 防止解析其他实例的 binlog
* 2. rdsOos 高可用模式下解析 binlog 会有两个 serverId,分别对应着主从节点 binlog解析出来的 serverId
* 主从的关系可能会变, 但是 serverId一直都会是这两个 serverId
*
* @param event
*/
private void checkServerId(LogEvent event) {
if (serverId != 0 && event.getServerId() != serverId) {
if (isRdsOssMode()) {
// 第一次添加主从信息
if (firstUpdateRdsOssMasterSlave) {
firstUpdateRdsOssMasterSlave = false;
rdsOssMasterSlaveInfo.add(event.getServerId());
} else if (!rdsOssMasterSlaveInfo.contains(event.getServerId())) {
// 主从节点信息之外的节点信息
throw new ServerIdNotMatchException("unexpected rds serverId " + serverId + " in binlog file !");
}
} else {
throw new ServerIdNotMatchException("unexpected serverId " + serverId + " in binlog file !");
}
}
}
Aggregations