CRZbulabula opened a new pull request, #18338:
URL: https://github.com/apache/iotdb/pull/18338
## Description
### Problem
During a ConfigNode leader transition, procedure metrics can be registered
before `ProcedureExecutor.init()` initializes `workerThreads`. If Prometheus
scrapes metrics in this window, the procedure worker auto gauges dereference a
null list and throw a `NullPointerException`.
Both the total worker count and active worker count accessors have the same
lifecycle issue, although the active worker count was the one observed in the
failure.
### Changes
- Make the `workerThreads` reference visible to concurrent metric reporter
threads.
- Return zero from both worker metric accessors before the executor is
initialized.
- Read the worker list through a local snapshot so each accessor uses one
consistent reference.
- Add a regression test covering metric reads before initialization and the
normal initialized state.
Returning zero represents the executor's pre-initialization state without
changing the ConfigNode leader startup sequence or hiding unrelated metric
failures in the common metrics framework.
### Alternatives considered
Moving metric registration after `ProcedureExecutor` startup would close the
currently observed window, but it would change the registration timing of all
ConfigNode leader metrics and would leave the metric accessors unsafe for other
lifecycle callers. Handling the uninitialized state at the component boundary
is smaller and more robust.
### Verification
- `mvn spotless:apply -pl iotdb-core/confignode`
- `mvn test -pl iotdb-core/confignode -Dtest=TestProcedureExecutor`
- `mvn compile -pl iotdb-core/confignode`
<hr>
This PR has:
- [x] been self-reviewed.
- [x] concurrent read
- [x] added comments explaining the concurrency and lifecycle intent.
- [x] added unit tests to cover the new code path.
<hr>
##### Key changed/added classes
- `ProcedureExecutor`
- `TestProcedureExecutor`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]