We are having a multi threaded application (using java) that is updating value in bin using Operations.add(). We are seeing inconsistency in the results. Also, we are updating the keys in batch update. So there can be multiple threads doing batch update. And each batch update can have several add operation. Attaching a sample code to produce the issue.
Using high availability cluster.
key = UUID.randomUUID().toString();
int writeCount = 20;
int threads = 10;
val batchOfBatchRecords = new ArrayList<ArrayList<BatchRecord>>();
for(int i=0;i<threads;i++) {
val batchRecords = new ArrayList<BatchRecord>();
batchOfBatchRecords.add(batchRecords);
for(int j=0;j<writeCount;j++) {
batchRecords.add(getBatchWriteObject(getOperations()));
}
}
ExecutorService executorService = new ThreadPoolExecutor(20, 20, 1000, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>());
for(int i=0;i<threads;i++) {
int finalI = i;
executorService.execute(() -> aerospikeClient.operate(aerospikeClient.getBatchPolicyDefault(), batchOfBatchRecords.get(finalI)));
}
Thread.sleep(10000);
val record = aerospikeClient.get(new Policy(), new Key("test", "set", key));
val readCount = (long) record.getValue("count");
val diff = threads*writeCount - readCount;
/**
get operations.
*/
private Operation[] getOperations() {
return new Operation[]{
Operation.add(new Bin("count", 1))
};
}