From d30d7b895d5fd4b64842d3c563bcfc198755fda7 Mon Sep 17 00:00:00 2001 From: Kostas Krikellas Date: Tue, 3 Dec 2024 15:36:39 +0200 Subject: [PATCH] small changes --- .../index/mapper/IntervalThrottler.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IntervalThrottler.java b/server/src/main/java/org/elasticsearch/index/mapper/IntervalThrottler.java index 310156f1bfaab..ffc35d9eaf769 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IntervalThrottler.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IntervalThrottler.java @@ -44,21 +44,23 @@ static class Acceptor { boolean accept() { final long now = System.currentTimeMillis(); - boolean accepted = false; // Check without guarding first, to reduce contention. if (now - lastAcceptedTimeMillis > intervalMillis) { - // Check if another concurrent logging operation succeeded. + // Check if another concurrent operation succeeded. if (lastAcceptedGuard.compareAndSet(false, true)) { - // Repeat check under guard protection, so that only one message gets written per interval. - if (now - lastAcceptedTimeMillis > intervalMillis) { - lastAcceptedTimeMillis = now; - accepted = true; + try { + // Repeat check under guard protection, so that only one message gets written per interval. + if (now - lastAcceptedTimeMillis > intervalMillis) { + lastAcceptedTimeMillis = now; + return true; + } + } finally { + // Reset guard. + lastAcceptedGuard.set(false); } - // Reset guard before logging. - lastAcceptedGuard.set(false); } } - return accepted; + return false; } } }