3

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.

Leonid
  • 478
  • 5
  • 15
  • It is hard to give advice without knowing all the details. I assume by "double field" you mean `long`, otherwise `BigInteger` isn't good replacement. `long` have huge upper limit. I doubt you can count to it in years. So it is unclear why you need this in first place. – talex Sep 06 '22 at 09:13

1 Answers1

1

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.

talex
  • 17,973
  • 3
  • 29
  • 66