The tracking compensated for isManagedByCurrentService reporting isolated tenants
of a profile without dedicated servers as not managed (a dedicated server for any
other profile flipped it). That root cause is fixed in #16345, after which a
tenant's managed status changes only together with its own queue ownership, and
its queue keys are already in the partition change event.
Replace the test that pinned the old flip with one that checks the affected
tenants when a dedicated server for the tenant's own profile joins and leaves.
HttpIntegrationTest creates the integration disabled and enables it right
away, which produces CREATED and UPDATED lifecycle messages. The CREATED task
reads the integration configuration when it runs. If the enable has already
been committed, that task starts the integration (STARTED), and the UPDATED
task that follows calls update() on the running integration and persists an
UPDATED event. waitUntilIntegrationStarted required the latest lifecycle event
to be STARTED, so it timed out after 30 s even though the integration was up.
Accept a successful STARTED or UPDATED as the latest lifecycle event.
WhiteLabelingControllerTest saves the system-level login white-labeling
params with baseUrl "https://domain.com" and never restores them. The
params persist in the shared test database, so when QrCodeSettingsControllerTest
runs later in the same JVM, getBaseUrl() resolves the system base URL to
domain.com and testGetMobileDeepLink fails with
expected "localhost" but was "domain.com".
Reset system white-labeling settings after every WhiteLabelingControllerTest
test, and reset them in QrCodeSettingsControllerTest setup as well.
/api/agentInfos?agentIds=... is served by a derived JPA 'id IN (...)'
query with no ORDER BY, so PostgreSQL may return rows in any order
(e.g. physical tuple order after an UPDATE). The test asserted
infos.get(0) == first and infos.get(1) == second, and failed whenever
the rows came back reversed. Match the returned infos by id instead.
After the managed-status fix the field was only written, never read. It
also held the fallback entries added by resolveByPartitionIdx, so reading
it later as "profiles with dedicated servers" would bring the bug back.
HashPartitionService.resolveByPartitionIdx caches the fallback (regular)
servers of an isolated profile without dedicated servers in
responsibleServices. isManagedByCurrentService then saw a non-empty list
for that profile and reported its tenants as not managed on the regular
servers, although those servers own the tenants' partitions. This happens
as soon as any dedicated server exists in the cluster.
Remember which profiles have dedicated servers before the fallback entries
are added, and use that set in isManagedByCurrentService.
ComponentActor.init calls createProcessor on every init attempt: the
mailbox retries a failed start, and re-initializes an INIT_FAILED actor
(failed start, or failed restart after a configuration update) on the
next RuleNodeUpdatedMsg, reusing the same actor instance. Reusing the
snapshot from actor creation there would keep a stale configuration and
ignore later fixes, so later attempts read the rule node from the
database, as before.
- Resolve affected tenants in PartitionChangeEvent.getAffectedTenants(),
returning null (all tenants) for non rule engine events, empty diffs and
shared queue changes.
- HashPartitionService adds isolated tenants whose managed status changed
without a change of their own queue keys.
- PartitionChangeMsg: forAllTenants/forTenants factories instead of a null
sentinel; affected tenants excluded from toString().
- Fold the AppActor log line into the existing DefaultActorService one.
- Tests: priority ordering in ActorSystemTest, AppActorTest on a real actor
system, DefaultActorServiceTest through onTbApplicationEvent, the
managed-status scenario in HashPartitionServiceTest.
AppActor.doProcess unconditionally broadcasts PARTITION_CHANGE_MSG to
every live TenantActor at high priority, regardless of whether a given
tenant's ownership actually changed. On a shared rule-engine instance
hosting many tenants, this means any single tenant's partition change
(e.g. moving to an isolated queue) interrupts every other tenant's
in-flight message processing, even though only one tenant's ownership
changed.
DefaultActorService now resolves which tenants are actually affected
from the partition-change diff it already has on hand (returning null
when the shared/non-isolated pool itself changed, since those tenants
aren't individually tracked and everyone must still be notified), and
AppActor uses that to broadcast only to the affected tenant actors,
reusing the existing TbEntityTypeActorIdPredicate filtering idiom.
Falls back to the original broadcast-to-everyone behavior whenever the
affected set can't be narrowed down.
PartitionChangeMsg only carried the affected ServiceType, so a
consumer had no way to know which specific tenants (if any) a given
partition change actually affects versus all of them. Add an optional
affectedTenants set: null preserves today's meaning ("could affect
anyone, notify everyone"), a non-null set means only those tenants are
affected. Existing single-arg construction is unchanged and keeps
defaulting to null.
TbActorSystem/TbActorCtx already supported broadcasting to a filtered
subset of children, and separately broadcasting to all children at a
given priority, but not both together. Expose the existing internal
implementation (already used for the priority-only case) as a public
filtered + prioritized overload, so callers can target a subset of
children without giving up delivery priority.
getRuleNodeRelations keeps reading relations through the relation cache, but
validates their targets with the same batched check as getRuleNodesRelations,
so the rule engine and the metadata API cannot diverge on which connections
are valid.
A rule chain without nodes (just created, or with all nodes removed) passed an
empty id list to getRuleNodesRelations, which validateIds rejects, so the rule
chain actor failed to start or update.
Use id = ANY(:ids) / from_id = ANY(:fromIds) instead of IN lists, so the
statement text is the same for every batch size and prepared plans are
reused. Add a test with a rule chain larger than one batch and several
1 MB rule node configurations; it also runs on Citus.
Rule chain initialization issued roughly 3N + E sequential queries per
chain (N nodes, E node connections): one findById per node in
getRuleChainNodes, a second findRuleNodeById per node in the rule node
actor, one relation lookup per node for routes and one existence
check per route target. Each by-id read runs in its own read-only
transaction, so start-up is bound by round trips and JDBC connection
hand-offs, and it saturates the connection pool shared with message
processing on large multi-tenant deployments.
- getRuleChainNodes reads the chain's nodes with batched id IN queries
- new RuleChainService.getRuleNodesRelations loads the outgoing
relations of all chain nodes and validates rule node targets in
batches (RelationDao.findAllByFromIds); dangling relations are still
removed, as in getRuleNodeRelations
- initRoutes uses the batched relations
- the rule chain actor hands each loaded RuleNode to its rule node
actor, which copies it (deep-copied configuration, plus the fields the
RuleNode copy constructor skips) instead of re-reading it
Both batched reads are served by existing indexes (rule_node_pkey,
idx_relation_from_id).
ruleChainsInitialized stays false when initRuleChains() fails part-way and when onRuleChainMsg creates rule chain actors lazily, so gating destroy on it could leave rule chain actors running for a disabled tenant. On enable the flag is redundant: after a disable it is always false.
The API_USAGE_STATE lifecycle message is broadcast to every core and rule engine service, and the handler had no isRuleEngine or isManagedByCurrentService check. Every re-enable built the tenant's rule chains on all core and rule engine nodes, including the isolated tier, instead of only on the owner.
TenantActor.onPartitionChangeMsg initialized rule chains for any managed
tenant whose chains were not initialized yet, ignoring the API usage
state. TenantActor.init and the API_USAGE_STATE lifecycle handler both
respect isReExecEnabled(), so tenants with rule-engine execution
disabled by API limits had no rule chains until the first partition
change, which then materialized their whole rule-chain/rule-node actor
tree on every rule-engine node (and failed to start script nodes when
script execution is disabled too).
Apply the same isReExecEnabled() gate on the partition-change path and
cover it with two TenantActorTest cases.
Calculated field actors page through each tenant's calculated fields on
startup (WHERE tenant_id = ? ORDER BY id LIMIT ?). With no index leading on
tenant_id, every page and its count query scan the whole table and sort,
so startup cost grows with tenants x table size.
Ship the index in schema-entities-idx.sql for new installs and as a new
4.4.1.0 LTS migration for existing ones (4.4.0.0 is already released, and
the range lower bound is exclusive).