首页 > 解决方案 > 预写缓存导致 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);
}

关于可能导致错误的任何想法?

标签: ignite

解决方案


“连接不可用”可能意味着连接池已满。在预写的情况下,每个写入线程中都会打开一个连接。因此,最大连接数应该至少是写入线程的数量。


推荐阅读