{"record":{"id":"5844f7a96684e29a","repo":"MyCATApache/Mycat-Server","slug":"sequnce-fetched-failed-from-db","errorCode":null,"errorMessage":"sequnce fetched failed  from db ","messagePattern":"sequnce fetched failed  from db ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/sequence/handler/SequenceVal.java","lineNumber":252,"sourceCode":"\t\treturn physicalDatasource.getHostConfig();\n\t}\n\n\tpublic void sleep(long time) {\n\t\ttry {\n\t\t\tThread.sleep(time);\n\t\t} catch (InterruptedException e) {\n\t\t\tIncrSequenceMySQLHandler.LOGGER\n\t\t\t\t\t.warn(\"wait db fetch sequnce err \" + e);\n\t\t}\n\t}\n\t//是否成功返回。\n\tpublic boolean isSuccessFetched() {\n\t\treturn successFetched;\n\t}\n\t//下一个可用的id\n\tpublic long nextValue() {\n\t\tif (successFetched == false) {\n\t\t\tthrow new RuntimeException(\n\t\t\t\t\t\"sequnce fetched failed  from db \");\n\t\t}\n\t\treturn curVal.incrementAndGet();\n\t}\n}\n","sourceCodeStart":234,"sourceCodeEnd":258,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/sequence/handler/SequenceVal.java#L234-L258","documentation":"nextValue() increments and returns the cached current value, but only if a prior fetch of the sequence succeeded. If successFetched is false (fetch never ran or failed), it throws a RuntimeException instead of handing out a possibly invalid id.","triggerScenarios":"Calling nextValue() (via nexVal) when the asynchronous DB fetch failed, timed out, or the error from getSequenceByNaitve (e.g. missing sequence row) left successFetched=false.","commonSituations":"Sequence row missing in mycat_sequence (error 293), repeated DB connection failures during fetch, or application code reading ids after a fetch that already logged a failure.","solutions":["Fix the underlying fetch failure (check Mycat logs for 'can't fetch sequnce in db' or the sequence-not-found error).","Ensure the sequence exists in mycat_sequence and the backing MySQL is reachable.","Retry the sequence request after the fetch succeeds rather than calling nextValue() on a failed SequenceVal."],"exampleFix":"// before\nlong id = seqVal.nextValue(); // throws if fetch failed\n// after\nif (!seqVal.isSuccessFetched()) {\n    seqVal.fetchSequenceFromDB(); // or surface a clear error\n}\nlong id = seqVal.nextValue();","handlingStrategy":"try-catch","validationCode":"if (!seqVal.isSuccessFetched()) { throw new IllegalStateException(\"sequence not fetched yet, cannot produce ids\"); }","typeGuard":"boolean canProduceId(SequenceVal s) { return s.isSuccessFetched(); }","tryCatchPattern":"try { long id = seqVal.nextValue(); } catch (RuntimeException e) { log.warn(\"sequence fetch failed, refetching\", e); seqVal.fetchSequenceFromDB(); }","preventionTips":["Always check isSuccessFetched() before nextValue()","Investigate fetch failures logged as 'can't fetch sequnce in db'","Add health checks on the sequence backing DB"],"tags":["java","sequence","fetch-failed","state"],"backgroundTag":"database-query-failed","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"}