Replace CAS loop by updateAndGet to improve readability
Relates
@@ -1074,21 +1074,14 @@ public class InternalEngine extends Engine {
*/
private boolean mayHaveBeenIndexedBefore(Index index) {
assert canOptimizeAddDocument(index);
- boolean mayHaveBeenIndexBefore;
- long deOptimizeTimestamp = maxUnsafeAutoIdTimestamp.get();
+ final boolean mayHaveBeenIndexBefore;
if (index.isRetry()) {
mayHaveBeenIndexBefore = true;
- do {
- deOptimizeTimestamp = maxUnsafeAutoIdTimestamp.get();
- if (deOptimizeTimestamp >= index.getAutoGeneratedIdTimestamp()) {
- break;
- }
- } while (maxUnsafeAutoIdTimestamp.compareAndSet(deOptimizeTimestamp,
- index.getAutoGeneratedIdTimestamp()) == false);
+ maxUnsafeAutoIdTimestamp.updateAndGet(curr -> Math.max(index.getAutoGeneratedIdTimestamp(), curr));
assert maxUnsafeAutoIdTimestamp.get() >= index.getAutoGeneratedIdTimestamp();
} else {
// in this case we force
- mayHaveBeenIndexBefore = deOptimizeTimestamp >= index.getAutoGeneratedIdTimestamp();
+ mayHaveBeenIndexBefore = maxUnsafeAutoIdTimestamp.get() >= index.getAutoGeneratedIdTimestamp();
}
return mayHaveBeenIndexBefore;
}
