{"record":{"id":"2897d8e40ef5d85b","repo":"MyCATApache/Mycat-Server","slug":"sequnce-not-found-in-db-table","errorCode":null,"errorMessage":"sequnce not found in db table ","messagePattern":"sequnce not found in db table ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/sequence/handler/SequenceVal.java","lineNumber":109,"sourceCode":"\t\t//进入waitFinish小于4次，或者可以后端获取数据\n\t\tif(retryCount <= systemRetryCount && canSendFetch) {\n\n\t\t\tthis.reset();\n\t\t\tmysqlSeqFetcher.execute(this);\n\t\t} else if(retryCount > systemRetryCount){\n\t\t\tfetching.compareAndSet(true, false); //\n\t\t\treturn null;\n\t\t}\n\t\tlong start = System.currentTimeMillis();\n\t\t//直接等待\n\t\tlong mysqlWaitTime = MycatServer.getInstance().getConfig().getSystem().getSequnceMySqlWaitTime();\n\n\t\tlong end = start + mysqlWaitTime;\n\t\twhile (System.currentTimeMillis() < end) {\n\t\t\tif(dbfinished){\n\t\t\t\tif (dbretVal == IncrSequenceMySQLHandler.errSeqResult) {\n\t\t\t\t\tfetching.compareAndSet(true, false); //修改\n\t\t\t\t\tthrow new RuntimeException(\n\t\t\t\t\t\t\t\"sequnce not found in db table \");\n\t\t\t\t}\n\t\t\t\t//进行处理 还有可能是链接错误等。\n\t\t\t\tif(dbretVal == null ){\n\t\t\t\t\tLOGGER.warn(\"can't fetch sequnce in db,sequnce :\"\n\t\t\t\t\t\t\t+ seqName + \" detail:\"\n\t\t\t\t\t\t\t+ mysqlSeqFetcher.getLastestError(seqName) + \"\\n\"\n\t\t\t\t\t\t\t\t\t+ \", and retry \" + (retryCount) +\" time\");\n\t\t\t\t\t//数据库之类的连接错误，休息一下在重试。\n\t\t\t\t\tsleep(10);\n\t\t\t\t\treturn getSequenceByNaitve(mysqlSeqFetcher, ++retryCount , true);\n\t\t\t\t}\n\t\t\t\tString[] items = dbretVal.split(\",\");\n\n\t\t\t\tLong curVal = Long.parseLong(items[0]);\n\t\t\t\tint span = Integer.parseInt(items[1]);\n\t\t\t\t//处理返回0，0\n\t\t\t\tif(0 == curVal) {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/sequence/handler/SequenceVal.java#L91-L127","documentation":"When fetching the next sequence value via the native MySQL fetcher, Mycat compares the DB result against IncrSequenceMySQLHandler.errSeqResult, the sentinel the fetcher returns when the sequence row is missing or invalid in mycat_sequence. Seeing that sentinel means the DB lookup completed but no valid sequence value exists for seqName.","triggerScenarios":"getSequenceByNaitve's retry/wait loop sees dbretVal == IncrSequenceMySQLHandler.errSeqResult after the SELECT on mycat_sequence finished, i.e. the sequence name has no row (or a bad row) in the sequence table.","commonSituations":"Global sequence type 1 used with a sequence name never inserted into mycat_sequence on the backing MySQL server; schema/database mismatch between the sequence name's prefix and where mycat_sequence lives.","solutions":["Insert a row for the sequence name into mycat_sequence on the configured MySQL host: INSERT INTO mycat_sequence(name,current_value,increment) VALUES('YOUR_SEQ', 1, 1);","Verify the sequence name in the SQL (table prefix) matches the mycat_sequence name column exactly.","Confirm the sequence's dataNode/host points at the database that actually contains the populated mycat_sequence table."],"exampleFix":"// before: SQL references MYSEQ, mycat_sequence has no row -> throw\nSELECT MYSEQ.NEXTVAL FOR MYCAT SEQUENCE;\n// after: on the sequence DB\nINSERT INTO mycat_sequence(name, current_value, increment) VALUES ('MYSEQ', 100000, 1);","handlingStrategy":"try-catch","validationCode":"// verify before use\nSELECT COUNT(*) FROM mycat_sequence WHERE name = 'MYSEQ'; // must be 1","typeGuard":null,"tryCatchPattern":"try { long v = seqVal.nextValue(); } catch (RuntimeException e) { log.error(\"sequence missing in mycat_sequence\", e); }","preventionTips":["Seed every sequence name into mycat_sequence during deployment","Match sequence names exactly between SQL and mycat_sequence","Monitor errSeqResult fetch failures in logs"],"tags":["java","mysql","sequence","missing-row","sql"],"backgroundTag":"record-not-found","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}