Aerospike Atomic increment on bigInt

Viewed 19

we have a double field type in Aerospike bin which need to be incremented in highly load conditions. So far it worked fine with a use of atomic increment operation provided by Aerospike natively.

Unfortunately, now we have to use BigInteger instead of double, and there is no atomic increment from Aerospike now.

Which approach you recommend if performance is the most important point and requests for update more likely appears in concurrent way. Thank you in advance.

1 Answers

One option is to use AtomicReference.

You can do something like this.

    AtomicReference<BigInteger> r = new AtomicReference<>();

    BigInteger oldValue = r.get();
    BigInteger newValue;
    do {
        newValue = oldValue.add(BigInteger.ONE);
    } while (!r.compareAndSet(oldValue, newValue));

This isn't best solution performancewise though.

Related