MyCATApache/Mycat-Server · error · UnknownTxIsolationException

txIsolation

Error message

txIsolation:${txIsolation}

What it means

MySQLConnection.getTxIsolationCommand throws UnknownTxIsolationException with message 'txIsolation:<value>' when building the SET SESSION TRANSACTION ISOLATION LEVEL statement for a transaction-isolation constant it does not recognize. Only the known Mycat Isolations constants (READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE) map to SQL; anything else reaches the default branch.

Solutions

  1. Set txIsolation to a valid Mycat Isolations value (1=READ_UNCOMMITTED, 2=READ_COMMITTED, 3=REPEATABLE_READ, 4=SERIALIZABLE) in the datasource config
  2. Check the message's txIsolation:<n> value and map it against io.mycat.backend.mysql.Isolations before deploying
  3. Add a startup validation step that rejects unknown isolation values early instead of at connection time

Example fix

// before (schema.xml)
<dsNode ... txIsolation="5" />
// after
<dsNode ... txIsolation="3" /> <!-- REPEATABLE_READ -->
Defensive patterns

Strategy: validation

Validate before calling

int tx = cfg.getTxIsolation();
if (tx < 1 || tx > 4) throw new IllegalArgumentException("txIsolation must be 1-4 (Isolations constants), got " + tx);

Type guard

boolean isValidTxIsolation(int v){ return v >= 1 && v <= 4; } // matches Isolations.READ_UNCOMMITTED..SERIALIZABLE

Try / catch

try { conn.synAndDoExecute(...); } catch (UnknownTxIsolationException e) { log.error("Invalid txIsolation in datasource config: {}", e.getMessage()); throw new ConfigException(e); }

Prevention

When it happens

Trigger: A datasource/transaction configuration sets txIsolation to an out-of-range or unknown integer, then synAndDoExecute prepares to send the connection to MySQL.

Common situations: Typo'd or hand-edited schema.xml/server.xml txIsolation values; custom code passing raw integers instead of the Isolations constants; config migrated from another product with different enum numbering.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/main/java/io/mycat/backend/mysql/nio/MySQLConnection.java:345

				.append(";");
	}

	private static void getTxIsolationCommand(StringBuilder sb, int txIsolation) {
		switch (txIsolation) {
		case Isolations.READ_UNCOMMITTED:
			sb.append("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
			return;
		case Isolations.READ_COMMITTED:
			sb.append("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;");
			return;
		case Isolations.REPEATED_READ:
			sb.append("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;");
			return;
		case Isolations.SERIALIZABLE:
			sb.append("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;");
			return;
		default:
			throw new UnknownTxIsolationException("txIsolation:" + txIsolation);
		}
	}

	private void getAutocommitCommand(StringBuilder sb, boolean autoCommit) {
		if (autoCommit) {
			sb.append("SET autocommit=1;");
		} else {
			sb.append("SET autocommit=0;");
		}
	}
	private void getTxReadonly(StringBuilder sb, boolean txReadonly) {
		if (txReadonly) {
			sb.append("SET SESSION TRANSACTION READ ONLY;");
		} else {
			sb.append("SET SESSION TRANSACTION READ WRITE;");
		}
	}
	private void getSqlSelectLimit(StringBuilder sb, int sqlSelectLimit) {

View on GitHub (pinned to 65f8d8beb7)