{"record":{"id":"be3f216cac46a2ab","repo":"alibaba/canal","slug":"unexpected-rds-serverid-serverid-in-binlog-f","errorCode":null,"errorMessage":"unexpected rds serverId  + serverId +  in binlog file !","messagePattern":"unexpected rds serverId  \\+ serverId \\+  in binlog file !","errorType":"exception","errorClass":"ServerIdNotMatchException","httpStatus":null,"severity":"error","filePath":"parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/LocalBinLogConnection.java","lineNumber":170,"sourceCode":"\r\n    /**\r\n     * 1. 非 rdsOos 模式下需要要校验 serverId 是否一致 防止解析其他实例的 binlog <br/>\r\n     * 2. rdsOos 高可用模式下解析 binlog\r\n     * 会有两个 serverId,分别对应着主从节点 binlog解析出来的 serverId 主从的关系可能会变, 但是 serverId一直都会是这两个\r\n     * serverId\r\n     *\r\n     * @param event\r\n     */\r\n    private void checkServerId(LogEvent event) {\r\n        if (serverId != 0 && event.getServerId() != serverId) {\r\n            if (isRdsOssMode()) {\r\n                // 第一次添加主从信息\r\n                if (firstUpdateRdsOssMasterSlave) {\r\n                    firstUpdateRdsOssMasterSlave = false;\r\n                    rdsOssMasterSlaveInfo.add(event.getServerId());\r\n                } else if (!rdsOssMasterSlaveInfo.contains(event.getServerId())) {\r\n                    // 主从节点信息之外的节点信息\r\n                    throw new ServerIdNotMatchException(\"unexpected rds serverId \" + serverId + \" in binlog file !\");\r\n                }\r\n            } else {\r\n                throw new ServerIdNotMatchException(\"unexpected serverId \" + serverId + \" in binlog file !\");\r\n            }\r\n        }\r\n    }\r\n\r\n    public void dump(long timestampMills, SinkFunction func) throws IOException {\r\n        List<File> currentBinlogs = binlogs.currentBinlogs();\r\n        File current = currentBinlogs.get(currentBinlogs.size() - 1);\r\n        long timestampSeconds = timestampMills / 1000;\r\n\r\n        String binlogFilename = null;\r\n        long binlogFileOffset = 0;\r\n\r\n        FileLogFetcher fetcher = new FileLogFetcher(bufferSize);\r\n        LogDecoder decoder = new LogDecoder();\r\n        decoder.handle(LogEvent.FORMAT_DESCRIPTION_EVENT);\r","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/LocalBinLogConnection.java#L152-L188","documentation":"Thrown as ServerIdNotMatchException by LocalBinLogConnection.checkServerId in RDS-OSS mode when a binlog event's serverId is neither the configured serverId nor already known in rdsOssMasterSlaveInfo. In RDS-OSS mode the first differing serverId seeds the master-slave set; subsequent unknown serverIds are rejected as foreign to protect against mixing unrelated instances' binlogs.","triggerScenarios":"checkServerId(event): serverId != 0 and event.getServerId() != serverId, isRdsOssMode() true, firstUpdateRdsOssMasterSlave already false, and rdsOssMasterSlaveInfo.contains(event.getServerId()) is false. So a third+ distinct serverId appears in the streamed binlog.","commonSituations":"Replaying an OSS binlog bundle that unexpectedly contains events from an extra MySQL node (e.g. a new replica promoted, or binlogs from a different instance mixed in), or the configured serverId does not match the OSS binlog's actual server_id. Also if the first event seeded the wrong id due to ordering.","solutions":["Confirm the OSS binlog files belong to the intended instance and its known replicas only.","Set canal.instance.master.serverId / the LocalBinLogConnection serverId to match the binlog's primary server_id.","If multi-source is intentional, ensure all expected replica serverIds are encountered in the correct seeding order (the first new id becomes the slave set).","Re-verify isRdsOssMode configuration; if not actually RDS-OSS, disable it to use the plain serverId check instead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before replay, confirm every serverId in the OSS bundle is expected\nSet<Long> ids = listBinlogServerIds(directory);\nif (!expectedMasterSlaveIds.containsAll(ids)) throw new IllegalStateException(\"unexpected serverIds: \" + ids);","typeGuard":null,"tryCatchPattern":"try { conn.dump(...); }\ncatch (ServerIdNotMatchException e) {\n    // either widen the allowed set or fix the configured serverId\n    log.warn(\"foreign serverId in rds-oss bundle: {}\", e.getMessage());\n}","preventionTips":["Replay only OSS binlogs from the intended instance and its known replicas.","Set LocalBinLogConnection.serverId to the primary server_id, or 0 to skip.","Seed the master-slave set in the correct first-event order."],"tags":["parse","binlog","serverid","rds-oss","local-binlog"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}