MyCATApache/Mycat-Server · error · ConfigException

can't find definition for sequence

Error message

can't find definition for sequence :{seqName}

What it means

IncrSequenceMySQLHandler.nextId looks up the requested sequence name in its in-memory seqValueMap, which is populated at startup from the configured DB sequence definitions (sequence table in a schema, per sequence_db_conf). If the name is absent, it throws ConfigException — this is a configuration-time lookup failure, not a runtime fetch failure. MyCat refuses to generate IDs for sequences it has no definition for.

Solutions

  1. Add a row for the sequence name in the sequence table (e.g. MYCAT_SEQUENCE) of the schema referenced by sequence_db_conf and restart/reload MyCat.
  2. Check that sequence_db_conf maps the sequence's target schema correctly and that the name matches exactly (case-sensitive) the one used in nextId/SQL.
  3. Verify the name used in the application/SQL matches the defined sequence; fix typos.
  4. After config changes, restart MyCat or trigger config reload so seqValueMap is repopulated.

Example fix

// before
// SELECT next value for MYCATSEQ_AUDIT  -> ConfigException: can't find definition for sequence :AUDIT
// after
-- insert the missing definition, then retry
INSERT INTO MYCAT_SEQUENCE(name, current_value, increment)
VALUES ('AUDIT', 100000, 100);
Defensive patterns

Strategy: validation

Validate before calling

public static void requireSequenceDefined(Map<String, ?> seqValueMap, String seqName) {
    if (!seqValueMap.containsKey(seqName)) {
        throw new ConfigException("can't find definition for sequence :" + seqName
            + " — add a row to the sequence table and map it in sequence_db_conf");
    }
}

Try / catch

try {
    long id = handler.nextId(seqName);
} catch (ConfigException e) {
    log.error("Sequence {} not defined; check sequence table + sequence_db_conf", seqName, e);
    throw new MissingSequenceConfigException(e);
}

Prevention

When it happens

Trigger: Calling nextId(seqName) with a sequence name that has no row in the sequence table referenced by sequence_db_conf (or the schema is not mapped for that sequence), so seqValueMap.get(seqName) returns null.

Common situations: Typo in the sequence/table name in SQL (e.g. using NEXT VALUE FOR mytable where mytable has no sequence row); missing row in the MYCAT_SEQUENCE table; sequence_db_conf pointing at the wrong schema; sequence added to app code before being added to MyCat config.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/main/java/io/mycat/route/sequence/handler/IncrSequenceMySQLHandler.java:87

			String dataNode = (String) entry.getValue();
			if (!seqValueMap.containsKey(seqName)) {
				seqValueMap.put(seqName, new SequenceVal(seqName, dataNode));
			} else {
				seqValueMap.get(seqName).dataNode = dataNode;
			}
		}
	}

	/**
	 * save sequnce -> curval
	 */
	private ConcurrentHashMap<String, SequenceVal> seqValueMap = new ConcurrentHashMap<String, SequenceVal>();

	@Override
	public long nextId(String seqName) {
		SequenceVal seqVal = seqValueMap.get(seqName);
		if (seqVal == null) {
			throw new ConfigException("can't find definition for sequence :"
					+ seqName);
		}
		if (!seqVal.isSuccessFetched()) {
			//从数据库获取
			return getSeqValueFromDB(seqVal);
		} else {
			//已经设置 获取下一个有效id
			return getNextValidSeqVal(seqVal);
		}

	}
	//获取有效的sequence
	private Long getNextValidSeqVal(SequenceVal seqVal) {
		Long nexVal = seqVal.nextValue();
		//当前id有效返回 无效则从数据库获取
		if (seqVal.isNexValValid(nexVal)) {
			return nexVal;
		} else {

View on GitHub (pinned to 65f8d8beb7)