{"record":{"id":"3a9315198948c06d","repo":"alibaba/canal","slug":"apply-failed","errorCode":null,"errorMessage":"apply failed","messagePattern":"apply failed","errorType":"exception","errorClass":"CanalParseException","httpStatus":null,"severity":"error","filePath":"parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/DatabaseTableMeta.java","lineNumber":643,"sourceCode":"\n                // 如果是同一秒内,对比一下history的位点，如果比期望的位点要大，忽略之\n                if (snapshotPosition.getTimestamp() > rollbackPosition.getTimestamp()) {\n                    continue;\n                } else if (rollbackPosition.getServerId().equals(snapshotPosition.getServerId())\n                           && snapshotPosition.compareTo(rollbackPosition) > 0) {\n                               continue;\n                           }\n\n                // 记录到内存\n                if (!memoryTableMeta.apply(snapshotPosition, useSchema, sqlData, null)) {\n                    return false;\n                }\n\n            }\n\n            return metaHistoryDOList.size() > 0;\n        } catch (Throwable e) {\n            throw new CanalParseException(\"apply failed\", e);\n        }\n    }\n\n    private String structureSchema(String schema) {\n        if (schema.startsWith(\"`\") && schema.endsWith(\"`\")) {\n            return schema;\n        }\n        return \"`\" + schema + \"`\";\n    }\n\n    private String getFullName(String schema, String table) {\n        StringBuilder builder = new StringBuilder();\n        return builder.append(structureSchema(schema))\n            .append('.')\n            .append('`')\n            .append(StringUtils.replace(table, \"`\", \"``\"))\n            .append('`')\n            .toString();","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/parse/src/main/java/com/alibaba/otter/canal/parse/inbound/mysql/tsdb/DatabaseTableMeta.java#L625-L661","documentation":"Thrown as CanalParseException by DatabaseTableMeta.applyHistoryOnMemory() when any Throwable occurs while replaying DDL history records from the TSDB into memory. Unlike error 436, this message has NO cause detail — it only says 'apply failed' with the exception attached.","triggerScenarios":"memoryTableMeta.apply() returns false for a history DDL entry, OR an exception is thrown during the loop: metaHistoryDAO.findByTimestamp() fails, Long.valueOf(binlogMasterId) throws NumberFormatException for non-numeric master IDs, or EntryPosition.compareTo() fails.","commonSituations":"binlogMasterId in the TSDB history table is non-numeric or null (stored as string that fails Long.valueOf); corrupt DDL text in history table; TSDB connection lost during history query; version mismatch in the history record format.","solutions":["Examine the attached cause exception (the 'e' parameter) for the real root cause — the message itself is uninformative.","If NumberFormatException on binlogMasterId, inspect and clean the meta_history table for invalid masterId values.","If memoryTableMeta.apply() returned false, check if the DDL text in the history record is valid and parseable.","Clear corrupt history records from the TSDB and trigger a fresh full dump."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    tableMeta.rollback(position);\n} catch (CanalParseException e) {\n    if (e.getMessage().equals(\"apply failed\")) {\n        Throwable cause = e.getCause();\n        // inspect cause: if NumberFormatException on masterId, clean history records\n        // if DDL parse failure, remove corrupt history entry\n    }\n}","preventionTips":["Validate TSDB history data integrity periodically.","Do not manually insert records into the meta_history table.","Handle null/non-numeric binlogMasterId gracefully in custom DAO implementations.","Back up TSDB data before maintenance."],"tags":["tsdb","ddl","history","rollback","canal-parse"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}