Gemfire 8升级至9后独立客户端缓存事务无法使用求助
解决方案:Gemfire 9.x独立客户端缓存事务提交报错的低侵入处理
针对你在Gemfire 8.2.7升级到9.15后,独立客户端缓存事务提交时触发CacheClosedException的问题,以下是无需搭建服务器/定位器集群的低侵入解决方案:
方案1:配置无实际连接的本地连接池
在测试缓存配置中添加一个空的连接池,让getAllPools()能找到合法的池实例,避免抛出异常,同时不会尝试连接远程节点:
XML配置示例
<pool name="test-local-pool" subscription-enabled="false"> <!-- 不配置任何server或locator地址 --> </pool> <client-cache> <!-- 指定缓存使用该空池 --> <pool name="test-local-pool" /> </client-cache>
API创建示例
// 创建空连接池 Pool emptyPool = PoolManager.createFactory() .create("test-local-pool"); // 初始化客户端缓存时绑定该池 ClientCache cache = new ClientCacheFactory() .setPoolName("test-local-pool") .create();
方案2:禁用远程类型注册
Gemfire 9新增的类型注册逻辑是为分布式场景设计的,独立客户端完全不需要该功能,通过系统属性禁用即可跳过相关代码路径:
JVM启动参数方式
-Dgemfire.disableRemoteTypeRegistration=true
代码中提前设置
// 初始化缓存前设置系统属性 System.setProperty("gemfire.disableRemoteTypeRegistration", "true"); // 正常创建独立客户端缓存 ClientCache cache = new ClientCacheFactory().create();
方案3:使用LOCAL事务类型
如果测试场景仅需本地事务,明确指定区域的事务类型为LOCAL,避免触发分布式事务相关的序列化逻辑:
XML配置示例
<region name="test-region" refid="LOCAL"> <region-attributes transactional="true" transaction-type="LOCAL" /> </region>
API创建示例
RegionFactory<String, Object> regionFactory = cache.createRegionFactory(RegionShortcut.LOCAL); regionFactory.setTransactional(true); regionFactory.setTransactionType(TransactionType.LOCAL); Region<String, Object> testRegion = regionFactory.create("test-region");
内容的提问来源于stack exchange,提问作者Jie Ming
相关产品推荐
相关产品推荐

