ignite - 预写缓存导致 CacheWriterException
问题描述
我试图对启用了预写的点燃缓存进行一些简单的基准测试(使用 JMH)。直写工作正常,但预写错误。
我得到CacheWriterException
并且连接池正在超时。数据源是 Spring Boot 配置的默认值hikari datasource
(这可以与 Write Through 一起正常工作)。
点燃缓存配置
CacheConfiguration<Long, Customer> customerWriteAheadCacheCfg = new CacheConfiguration<(CacheName.WRITE_AHEAD.getCacheName());
customerWriteAheadCacheCfg.setIndexedTypes(Long.class, Customer.class);
customerWriteAheadCacheCfg.setWriteThrough(true);
customerWriteAheadCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
customerWriteAheadCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
customerWriteAheadCacheCfg.setWriteBehindEnabled(true);
customerWriteAheadCacheCfg.setWriteBehindBatchSize(50);
存储和实体配置
CacheJdbcPojoStoreFactory<Long, Customer> customerPojoFactory1 = new CacheJdbcPojoStoreFactory<>();
customerPojoFactory1.setDataSourceBean("dataSource");
customerPojoFactory1.setDialect(new BasicJdbcDialect());
JdbcType customerPojoType1 = new JdbcType();
customerPojoType1.setCacheName(CacheName.WRITE_AHEAD.getCacheName());
customerPojoType1.setKeyType(Long.class);
customerPojoType1.setValueType(Customer.class);
customerPojoType1.setDatabaseTable("customer");
customerPojoType1.setKeyFields(new JdbcTypeField(Types.INTEGER, "id", Long.class, "id"));
customerPojoType1.setValueFields(
new JdbcTypeField(Types.VARCHAR, "name", String.class, "name"),
new JdbcTypeField(Types.VARCHAR, "type", String.class, "type")
);
customerPojoFactory1.setTypes(customerPojoType1);
对于基准测试,我只是put
在缓存中使用
public void saveToCacheWriteAhead(Customer customer) {
waCache.put(customer.getId(), customer);
}
关于可能导致错误的任何想法?
解决方案
“连接不可用”可能意味着连接池已满。在预写的情况下,每个写入线程中都会打开一个连接。因此,最大连接数应该至少是写入线程的数量。
推荐阅读
- server - 如何在当前的互联网设置中制作即时通讯系统?
- python - 在 for 循环中尝试 /Except 的行为不符合预期
- flutter - 如何从颜色列表中选择更改容器颜色?
- java - Java Data Elasticsearch 客户端将端口 9200 附加到 url
- java - jdeps 返回“未找到”
- ruby-on-rails - ActiveRecord 集合减法
- blazor - 在 Blazor 组件中的选项卡之间切换时如何保留数据?
- javascript - 在 React 事件中使用 setTimeout,出于性能原因重用此合成事件
- amazon-web-services - 如果没有设置重新驱动策略,AWS SQS 中的失败消息会发生什么情况?
- java - 使用 ASM 修改 Java 字节码会引发 ClassFormatError: Invalid length XXX in LocalVariableTable