Consolidate input state transitions into a single code path
Description
Input runtime state is written from many places, with no single owner of the transition logic:
InputEventListener: six@Subscribehandlers (inputCreated,inputUpdated,inputStopped,inputDeleted,inputSetup,leaderChanged), each deciding what to do from its own ad-hoc read of the current stateInputLauncher.launch(): registers the state and mutates it from its own executorInputRegistry.remove()/stop()/setup(): combine map updates with lifecycle callsInputStatesResource: persistsdesired_stateand posts the triggering eventInputSetupService.shutDown()
These run on an AsyncEventBus concurrently with the launcher pool and REST threads, and each operation is a read-modify-write spread across several calls that the caller has to sequence correctly. The outcome depends on timing. There is also no reconciliation, so a node that misses an event stays diverged from the persisted desired_state until it restarts.
This has been a recurring source of bugs:
- #5106 create-then-update races, input stopped while still starting
- #10640 content pack input fails to start with "port already in use", fixed by a restart
- #25425 overview shows running, detail page shows not running
- #7812 stopped and deleted were indistinguishable to subscribers
- #22588 leader-only and stopped inputs reported misleadingly
- #4484 stopped inputs handled identically to deleted ones
Goal
One place that owns input state transitions, so the outcome does not depend on event timing or on each caller getting the sequence right, and so a node converges on the desired state even when an event is missed. The registry, the launcher and the event handlers should not each hold a piece of the logic.
Out of scope
The read path. #25358 already moved input state reads to MongoDB.
Source: Graylog2/graylog2-server