MyCATApache/Mycat-Server · error · java.lang.IllegalArgumentException

can't find cache pool

Error message

can't find cache pool:{poolName}

What it means

getCachePool retrieves a CachePool by name from allPools, which is populated from the cache configuration at CacheService init. When the requested pool name was never configured (or init skipped it due to an earlier error), it throws IllegalArgumentException. Callers like RouteService depend on pools such as RouteService cache or sqlRouteCache existing.

Solutions

  1. Add the missing cache pool entry to your Mycat cache configuration with the exact name being requested (e.g. 'sqlRouteCache','ER sqlcache')
  2. Verify with logs whether cache init failed earlier for that pool (e.g. bad type) and fix the root cause
  3. Grep the code/config for the pool name to confirm the exact spelling expected by the caller (RouteService)
  4. If you intentionally don't need that cache, configure the related feature to disable cache usage rather than leaving the pool undefined

Example fix

// before (cache config missing pool)
<cache name="sqlRouteCache2" type="ehcache" ... />
// after (name matches what getCachePool requests)
<cache name="sqlRouteCache" type="ehcache" ... />
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure pool exists before use
if (!cacheService.getAllCachePools().containsKey(poolName)) {
    LOG.warn("cache pool {} not configured, skipping cache usage", poolName);
    return null;
}

Try / catch

try {
    CachePool pool = cacheService.getCachePool(poolName);
    return pool.get(key);
} catch (IllegalArgumentException e) {
    LOG.warn("cache pool {} missing, bypassing cache", poolName, e);
    return loadFromDatabase(key); // fallback, never fail the query for cache
}

Prevention

When it happens

Trigger: Calling CacheService.getCachePool("someName") where someName is absent from the cache config: e.g. RouteService requests its route cache but the cache section was removed, renamed, or the cacheServerPort/cache config file failed to define it.

Common situations: Deleting or renaming a cache entry in the Mycat cache configuration while code/system defaults still reference the old name; cache initialization silently skipped a pool because its factory type was invalid; copy-paste config between environments missing pool entries.

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/b2fad8337a547a35. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/cache/CacheService.java:177

	private CachePoolFactory getCacheFact(String type) {
		CachePoolFactory facty = this.poolFactorys.get(type);
		if (facty == null) {
			throw new RuntimeException("CachePoolFactory not defined for type:"
					+ type);
		}
		return facty;
	}

	/**
	 * get cache pool by name ,caller should cache result
	 * 
	 * @param poolName
	 * @return CachePool
	 */
	public CachePool getCachePool(String poolName) {
		CachePool pool = allPools.get(poolName);
		if (pool == null) {
			throw new IllegalArgumentException("can't find cache pool:"
					+ poolName);
		} else {
			return pool;
		}

	}

	public void clearCache() {

		logger.info("clear all cache pool ");
		for (CachePool pool : allPools.values()) {

			pool.clearCache();
		}

	}

}

View on GitHub (pinned to 65f8d8beb7)