Skip to content

Commit

Permalink
Merge pull request #871 from apache/OAK-10145
Browse files Browse the repository at this point in the history
OAK-10145 Rate limit the Missing provider log messages for IndexUpdate
  • Loading branch information
thomasmueller committed Mar 17, 2023
2 parents ee3fb35 + ecbc9a3 commit 64c8249
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;

import com.google.common.collect.Iterables;

Expand Down Expand Up @@ -82,6 +83,10 @@ public class IndexUpdate implements Editor, PathSource {
// This counter is cyclically incremented till indexJcrTypeInvalidLogLimiter and then reset to 0
private static volatile long cyclicExecutionCount = INDEX_JCR_TYPE_INVALID_LOG_LIMITER;

// Warnings about missing index providers are rate limited, so the log file is not filled with them.
// this is the last time such a message was logged (if any).
private static final AtomicLong lastMissingProviderMessageTime = new AtomicLong();

/**
* <p>
* The value of this flag determines the behavior of the IndexUpdate when
Expand Down Expand Up @@ -330,9 +335,17 @@ private void collectIndexEditors(NodeBuilder definitions,
// then we don't need to handle missing handler
if (definition.hasProperty(ASYNC_PROPERTY_NAME) && rootState.async == null) {
if (!TYPE_DISABLED.equals(type)) {
log.warn("Missing provider for nrt/sync index: {} (rootState.async: {}). " +
"Please note, it means that index data should be trusted only after this index " +
"is processed in an async indexing cycle.", definition, rootState.async);
long silenceMessagesSeconds = 60;
long silenceMessagesNanos = silenceMessagesSeconds * 1_000_000_000;
long now = System.nanoTime();
long last = lastMissingProviderMessageTime.get();
if (now > last + silenceMessagesNanos
&& lastMissingProviderMessageTime.compareAndSet(last, now)) {
log.warn("Missing provider for nrt/sync index: {}. " +
"Please note, it means that index data should be trusted only after this index " +
"is processed in an async indexing cycle. " +
"This message is silenced for {} seconds.", indexPath, silenceMessagesSeconds);
}
}
} else {
rootState.missingProvider.onMissingIndex(type, definition, indexPath);
Expand Down

0 comments on commit 64c8249

Please sign in to comment.