refresh() schedules STOPPED for a singleton whose partition moved away, and
skips integrations that are still running when the partition comes back. If
the lifecycle executor ran that STOPPED only after the partition came back
(busy pool, or tryUpdate rescheduled after a lost tryLock), it destroyed the
integration on the node that owned it again, and nothing restarted it until
the next partition change.
When STOPPED runs, fetch the configuration and check the current ownership:
- skip the stop if the integration is running, enabled, not remote and mine;
- otherwise stop it, and if it is mine again after the stop (the partition
came back while it was being stopped) schedule CREATED. processStop()
removes the state first, so CREATED starts from a fresh state.
If the configuration can't be fetched or the ownership can't be resolved, the
integration is stopped as before. Stops for integrations switched to remote
or disabled are not affected.
A PartitionChangeEvent carries only the queue keys whose partitions changed
(and the removed ones), not a full snapshot. Keeping only the last pending
event dropped the changes of every other integration type: e.g. on a node
whose neighbours support different integration types, an MQTT-only event
queued after a first event with all types left HTTP, KAFKA, ... unsubscribed
and not refreshed until their partitions changed again. This could happen at
startup and, since events are now drained after startup too, while an event
thread waits for the synchronized drain.
Merge the pending events per queue key instead; the latest partitions of
each key win.
DefaultClusterIntegrationService.onTbApplicationEvent() added a
PartitionChangeEvent to pendingEvents only while the executor was still
starting. Once started, it skipped the add and drained an empty queue, so
every partition change after startup was dropped: refresh() did not run and
the downlink consumers were not re-subscribed. Each node kept the partition
snapshot it held when its startup completed, until the JVM restarted.
After a rolling restart, or when a single node restarts while the others
keep running, this leaves singleton integrations (MQTT, AWS IoT, Azure, ...)
running on two nodes or on none. Brokers that enforce unique client IDs
keep disconnecting the two copies, and brokers that allow both process every
uplink twice.
- Always enqueue the event before draining. Make drainPendingEvents()
synchronized, so that snapshots are applied in the order they arrive.
- In update(), check ownership against the current partitions before
starting or updating an integration (CREATED, STARTED, UPDATED,
ACTIVATED), and stop it if it is no longer owned. Ownership can change
between scheduling an event and running it.
- In reInitIntegrations(), stop FAILED integrations that are no longer
owned instead of re-initializing them.
- In refresh(), treat an empty partition set as a real snapshot and stop the
singletons of that type. Restrict the stop loop to the refreshed
integration type, because the owned partitions belong to that type only.
Nothing new is created on an empty snapshot.
Adds DefaultClusterIntegrationServiceTest and
DefaultIntegrationManagerServiceTest, covering partition flip-flops during
startup and on long-running nodes.
Integration executors loaded the rule engine queues only at startup and never
evicted the cached tenant routing info. After a tenant switched to or from an
isolated rule engine they kept pushing its uplinks to the old queue until restart.
- send queue update/delete notifications to integration executors
(new repeated fields 2 and 3 in ToIntegrationExecutorNotificationMsg)
- apply them in DefaultClusterIntegrationService
- evict tenant routing info on TENANT / TENANT_PROFILE events, after the
tenant profile caches (new PartitionService.evictTenantProfileInfo)