MyCATApache/Mycat-Server · error · RuntimeException

sequnce fetched failed from db

Error message

sequnce fetched failed  from db 

What it means

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.

Solutions

  1. Fix the underlying fetch failure (check Mycat logs for 'can't fetch sequnce in db' or the sequence-not-found error).
  2. Ensure the sequence exists in mycat_sequence and the backing MySQL is reachable.
  3. Retry the sequence request after the fetch succeeds rather than calling nextValue() on a failed SequenceVal.

Example fix

// before
long id = seqVal.nextValue(); // throws if fetch failed
// after
if (!seqVal.isSuccessFetched()) {
    seqVal.fetchSequenceFromDB(); // or surface a clear error
}
long id = seqVal.nextValue();
Defensive patterns

Strategy: try-catch

Validate before calling

if (!seqVal.isSuccessFetched()) { throw new IllegalStateException("sequence not fetched yet, cannot produce ids"); }

Type guard

boolean canProduceId(SequenceVal s) { return s.isSuccessFetched(); }

Try / catch

try { long id = seqVal.nextValue(); } catch (RuntimeException e) { log.warn("sequence fetch failed, refetching", e); seqVal.fetchSequenceFromDB(); }

Prevention

When it happens

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

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

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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

Appendix: source

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

		return physicalDatasource.getHostConfig();
	}

	public void sleep(long time) {
		try {
			Thread.sleep(time);
		} catch (InterruptedException e) {
			IncrSequenceMySQLHandler.LOGGER
					.warn("wait db fetch sequnce err " + e);
		}
	}
	//是否成功返回。
	public boolean isSuccessFetched() {
		return successFetched;
	}
	//下一个可用的id
	public long nextValue() {
		if (successFetched == false) {
			throw new RuntimeException(
					"sequnce fetched failed  from db ");
		}
		return curVal.incrementAndGet();
	}
}

View on GitHub (pinned to 65f8d8beb7)