apache/shardingsphere · error · InvalidRuleConfigurationException

0

0

Error message

Invalid 'Transaction' rule, error message is: Unsupported transaction type `%s`

What it means

AlterTransactionRuleExecutor validates ALTER TRANSACTION RULE DistSQL before applying it and calls TransactionType.valueOf on DEFAULT_TYPE. If the value is not exactly LOCAL, XA, or BASE (case-insensitive), valueOf throws IllegalArgumentException, which is wrapped into InvalidRuleConfigurationException with the message 'Invalid Transaction rule, error message is: Unsupported transaction type `<type>`'.

Source

Thrown at kernel/transaction/distsql/handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleExecutor.java:51

/**
 * Alter transaction rule executor.
 */
public final class AlterTransactionRuleExecutor implements GlobalRuleDefinitionExecutor<AlterTransactionRuleStatement, TransactionRule> {
    
    @Override
    public void checkBeforeUpdate(final AlterTransactionRuleStatement sqlStatement) {
        checkTransactionType(sqlStatement);
        TransactionType transactionType = TransactionType.valueOf(sqlStatement.getDefaultType().toUpperCase());
        if (TransactionType.LOCAL != transactionType) {
            checkTransactionManager(sqlStatement, transactionType);
        }
    }
    
    private void checkTransactionType(final AlterTransactionRuleStatement statement) {
        try {
            TransactionType.valueOf(statement.getDefaultType().toUpperCase());
        } catch (final IllegalArgumentException ignored) {
            throw new InvalidRuleConfigurationException("Transaction", String.format("Unsupported transaction type `%s`", statement.getDefaultType()));
        }
    }
    
    private void checkTransactionManager(final AlterTransactionRuleStatement statement, final TransactionType transactionType) {
        Collection<ShardingSphereDistributedTransactionManager> distributedTransactionManagers = ShardingSphereServiceLoader.getServiceInstances(ShardingSphereDistributedTransactionManager.class);
        Optional<ShardingSphereDistributedTransactionManager> distributedTransactionManager =
                distributedTransactionManagers.stream().filter(each -> transactionType == each.getTransactionType()).findFirst();
        ShardingSpherePreconditions.checkState(distributedTransactionManager.isPresent(),
                () -> new InvalidRuleConfigurationException("Transaction", String.format("No transaction manager with type `%s`", statement.getDefaultType())));
        if (TransactionType.XA == transactionType) {
            checkTransactionManagerProviderType(distributedTransactionManager.get(), statement.getProvider().getProviderType());
        }
    }
    
    private void checkTransactionManagerProviderType(final ShardingSphereDistributedTransactionManager distributedTransactionManager, final String providerType) {
        ShardingSpherePreconditions.checkState(distributedTransactionManager.containsProviderType(providerType),
                () -> new InvalidRuleConfigurationException("Transaction", String.format("No transaction manager provider with type `%s`", providerType)));
    }

View on GitHub (pinned to e952770a21)

Solutions

  1. Use one of the supported DEFAULT_TYPE values: LOCAL, XA, or BASE (case-insensitive).
  2. If you intended a specific XA provider, keep DEFAULT_TYPE=XA and put the provider in the PROVIDER clause, e.g. ALTER TRANSACTION RULE ... DEFAULT_TYPE=XA, PROVIDER(TYPE=Narayana).
  3. Check for typos, extra quotes, or whitespace in the DistSQL string before resubmitting.
  4. Run SHOW TRANSACTION RULES first to confirm the current rule and syntax on your version.

Example fix

-- before
ALTER TRANSACTION RULE DEFAULT_TYPE="XA_ATOMIKOS", PROVIDER(TYPE=Atomikos);

-- after
ALTER TRANSACTION RULE DEFAULT_TYPE=XA, PROVIDER(TYPE=Atomikos);
Defensive patterns

Strategy: validation

Validate before calling

Set<String> VALID = Set.of("LOCAL", "XA", "BASE");
String t = defaultType.trim().toUpperCase(Locale.ROOT);
if (!VALID.contains(t)) throw new IllegalArgumentException("DEFAULT_TYPE must be one of LOCAL, XA, BASE: " + defaultType);

Try / catch

try { proxy.executeSql("ALTER TRANSACTION RULE DEFAULT_TYPE=" + type + ";"); } catch (final InvalidRuleConfigurationException ex) { /* surface message listing supported types; fix DEFAULT_TYPE */ }

Prevention

When it happens

Trigger: Executing ALTER TRANSACTION RULE ... DEFAULT_TYPE=<value> through ShardingSphere proxy DistSQL where <value> is something like 'XA_MYSQL', 'jdbc', 'none', 'local_trx', or misspelled; checkTransactionType catches the IllegalArgumentException and rethrows the InvalidRuleConfigurationException.

Common situations: Confusing the transaction provider name (e.g. Atomikos, Narayana, Bitronix) with the transaction type; copying example DistSQL with a made-up type; older/newer docs using different type names; trailing whitespace or quotes in the value.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/d3b9465a70e4fa93. Report an issue: GitHub.