Ignite write-through 和 write-behind 启用但行仍然按记录保留

Ignite write-through and write-behind enabled but rows still being persisted per record

我正在使用 MS SQL 服务器进行第 3 方持久性。我的目的是将数据从数据库加载到数据网格,执行一些计算(分布式),最后将结果写回 SQL 服务器。要处理的记录数大于 100 万条记录,因此我不希望记录按记录保存,而是分批保存(例如,根据一个时间间隔,或每 X 毫秒)。这是我配置节点的方式:

ccfg.setReadThrough(true);
ccfg.setWriteThrough(true);
ccfg.setWriteBehindEnabled(true);
ccfg.setWriteBehindBatchSize(10000);

这里是执行计算的代码和put缓存:

int i = 0;

for (ComputePOJO computeItem : computeItems) {
    InvoiceItem invoiceItem = calcInvoiceItem();

    InvoiceItemKey key = new InvoiceItemKey(invoiceId, contractItemId);
    invoiceItem.setId(key);
    invoiceItemCache.put(key, invoiceItem);

    i++;

    if (i % 1000 == 0) {
        System.out.printf("> Computed %s InvoiceItems...%n", i);
    }
}

如果我在 put 调用上放置断点并计算 put 调用前后的记录(SELECT COUNT(*) FROM InvoiceItem 在 SQL 服务器中查询),我可以看到记录被立即写入磁盘,尽管启用了后写并配置为每 10 秒写入一次。我也试过 putAsync 但结果相同。

我在这里错过了什么?

谢谢。

后来发现CacheAtomicityMode设置为CacheMode.ATOMIC,改为CacheAtomicityMode.TRANSACTIONAL,不再逐行写入DB了。