Mihai Bercea created OAK-12505:
----------------------------------
Summary: Async indexing LAST_INDEXED_TIME metric is stuck at its
startup value on non-leader cluster members
Key: OAK-12505
URL: https://issues.apache.org/jira/browse/OAK-12505
Project: Jackrabbit Oak
Issue Type: Improvement
Components: indexing
Reporter: Mihai Bercea
With OAK-12394, the async indexing metric {{<lane>.LAST_INDEXED_TIME}} (e.g.
{{org.apache.jackrabbit.oak:elastic-async.LAST_INDEXED_TIME}}) is initialized
from the persisted {{:async/<lane>-LastIndexedTo}} value when the
{{AsyncIndexUpdate}} instance is created, so it is no longer 0 after a restart.
That fix is good and should be kept.
However, after this change, on cluster members that are *not* the leader, the
value stays at the value from pod startup forever. This affects all async lanes
({{async}}, {{fulltext-async}}, {{elastic-async}}).
h3. Cause
* {{IndexMBeanRegistration.registerAsyncIndexer}} schedules the async indexing
jobs with {{RUN_ON_LEADER}}, so only the leader runs indexing cycles.
* {{AsyncIndexUpdate.ExecutionStats}} initializes the {{LAST_INDEXED_TIME}}
counter once from {{:async/<lane>-LastIndexedTo}} in its constructor.
* After that, the counter is only updated in {{ExecutionStats.doneOneCycle()}},
which is only called when this instance runs a successful cycle.
* Non-leader instances never run a cycle, so the counter stays at the startup
snapshot. Before OAK-12394 it stayed at 0 on these instances, which monitoring
could filter out ({{> 0}}); now it is a plausible but stale timestamp.
h3. Impact
Monitoring and alerting that looks at this metric per instance (for example,
"indexing lane delayed by more than 4h/12h") reports false stale indexing lanes
on non-leader members. As the time since pod startup grows, these alerts fire
even though indexing on the leader is healthy. You also cannot tell from the
metric alone which member is the leader.
h3. Expected behavior
On every cluster member, {{LAST_INDEXED_TIME}} should reflect recent indexing
progress of the lane, not only the value at startup.
Constraints and things to consider:
* Keep the restart behavior from OAK-12394: no reset to 0 after a restart.
* Keep the metric type and JMX contract (Counter, {{Count}} attribute) for
compatibility, as discussed in PR #3112.
* {{LastIndexedTo}} is only written when a cycle actually indexes changes;
cycles with no changes do not advance it, but they do advance the leader's
counter. Simply re-reading {{LastIndexedTo}} on non-leaders would make idle
lanes look stale. A possible approach: the leader persists a "last successful
cycle" timestamp under {{:async}}, and a lightweight periodic task that runs on
all members (not only the leader) refreshes the counter from it.
* The startup initialization uses {{inc()}}. If the {{StatisticsProvider}}
returns an existing counter (for example, {{MetricStatisticsProvider}} reuses
metrics by name), re-creating {{AsyncIndexUpdate}} can add the value twice.
Setting the counter to an absolute value (the delta to the current count) would
avoid this.
h3. References
* OAK-12394 – Async indexing: LAST_INDEXED_TIME is 0 after restart
* https://github.com/apache/jackrabbit-oak/pull/3112
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)