Search code examples
sql-serverignitein-memory-database

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


I am using MS SQL Server for 3rd party persistence. My intention is to load data from the database to the data grid, perform some computation (distributed) and write the result back to SQL Server at the end. The number of records to process is > 1 million records therefore I do not want records to be persisted per-record but in batches (eg. according to an interval, or every X milliseconds). Here's how I've configured my node:

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

Here is the code that performs the calculation and the put to cache:

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);
    }
}

If I put a breakpoint on the put call and count the records (SELECT COUNT(*) FROM InvoiceItem query in SQL Server) before and after the put call, I can see that the record was written immediately to disk, despite enabling write-behind and configuring to write every 10 seconds. I also tried with putAsync but same result.

What am I missing here?

Thank you.


Solution

  • I later realized that CacheAtomicityMode was set to CacheMode.ATOMIC, changed to CacheAtomicityMode.TRANSACTIONAL and it is no longer writing to DB row by row.