MyCATApache/Mycat-Server · error · RuntimeException

sequnce not found in db table

Error message

sequnce not found in db table 

What it means

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.

Solutions

  1. 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);
  2. Verify the sequence name in the SQL (table prefix) matches the mycat_sequence name column exactly.
  3. Confirm the sequence's dataNode/host points at the database that actually contains the populated mycat_sequence table.

Example fix

// before: SQL references MYSEQ, mycat_sequence has no row -> throw
SELECT MYSEQ.NEXTVAL FOR MYCAT SEQUENCE;
// after: on the sequence DB
INSERT INTO mycat_sequence(name, current_value, increment) VALUES ('MYSEQ', 100000, 1);
Defensive patterns

Strategy: try-catch

Validate before calling

// verify before use
SELECT COUNT(*) FROM mycat_sequence WHERE name = 'MYSEQ'; // must be 1

Try / catch

try { long v = seqVal.nextValue(); } catch (RuntimeException e) { log.error("sequence missing in mycat_sequence", e); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/2897d8e40ef5d85b. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/route/sequence/handler/SequenceVal.java:109

		//进入waitFinish小于4次,或者可以后端获取数据
		if(retryCount <= systemRetryCount && canSendFetch) {

			this.reset();
			mysqlSeqFetcher.execute(this);
		} else if(retryCount > systemRetryCount){
			fetching.compareAndSet(true, false); //
			return null;
		}
		long start = System.currentTimeMillis();
		//直接等待
		long mysqlWaitTime = MycatServer.getInstance().getConfig().getSystem().getSequnceMySqlWaitTime();

		long end = start + mysqlWaitTime;
		while (System.currentTimeMillis() < end) {
			if(dbfinished){
				if (dbretVal == IncrSequenceMySQLHandler.errSeqResult) {
					fetching.compareAndSet(true, false); //修改
					throw new RuntimeException(
							"sequnce not found in db table ");
				}
				//进行处理 还有可能是链接错误等。
				if(dbretVal == null ){
					LOGGER.warn("can't fetch sequnce in db,sequnce :"
							+ seqName + " detail:"
							+ mysqlSeqFetcher.getLastestError(seqName) + "\n"
									+ ", and retry " + (retryCount) +" time");
					//数据库之类的连接错误,休息一下在重试。
					sleep(10);
					return getSequenceByNaitve(mysqlSeqFetcher, ++retryCount , true);
				}
				String[] items = dbretVal.split(",");

				Long curVal = Long.parseLong(items[0]);
				int span = Integer.parseInt(items[1]);
				//处理返回0,0
				if(0 == curVal) {

View on GitHub (pinned to 65f8d8beb7)