WriteConflict error in MongoDB when running batches of insertMany operation with transaction from Quarkus

93 views Asked by At

Below is a snippet of my transaction implementation. Currently MongoDB will throw WriteConflict error every time when it is processing the records from 800k onwards.

    ClientSession clientSession = mongoClient.startSession();
    clientSession.startTransaction();
    int batchSize = 100000;

    try {
        for (int i = 1; i <= 1000000; i++) {

            ArrayList<SampleData> sampleDataList = new ArrayList();
            sampleDataList.add(new SampleData(i));
            if (i % batchSize == 0 || i == sampleDataList.size()) {
                sampleDataRepo.mongoCollection().insertMany(clientSession, sampleDataList);
                sampleDataList.clear();

            }
        }
        clientSession.commitTransaction();
    }

    catch (Exception e){
        clientSession.abortTransaction();
        throw new Exception(e.getMessage());
    }
1

There are 1 answers

0
Zhen Wei On

Resolved by increasing the wiredTigerCacheSizeGB