Skip to content

fix(dynamic-entity): drop the memoized definition lists when definitions change - #2955

Open
hongwei1 wants to merge 2 commits into
OpenBankProject:developfrom
hongwei1:fix/dynamic-entity-definitions-rebuild
Open

hongwei1 wants to merge 2 commits into
OpenBankProject:developfrom
hongwei1:fix/dynamic-entity-definitions-rebuild

Conversation

@hongwei1

@hongwei1 hongwei1 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Dynamic entity definitions now follow a new dynamic_entity cache namespace version. When a definition is created, updated or deleted, DynamicEntityHelper.forgetDefinitions bumps that version once the request's transaction has committed (nothing happens on rollback), then drops this instance's map and bumps the dynamic resource-doc caches in the same after-commit step. The lists NewStyle.getDynamicEntities and getDynamicEntitiesByUserId memoize in Redis carry the version in their keys, and the definitions map is kept (DefinitionsMapCache) only while the version is the one it was built under, so a new entity's record endpoints, the management lists and /resource-docs reflect the change at once on the instance that made it and within a second on every other instance, and a read still in flight cannot store old rows under the new version. The namespace is listed on the cache info page and can be bumped through POST /management/cache/namespaces/invalidate.

DefinitionsCacheInvalidationTest covers the namespace registration, the after-commit and rollback behaviour of the bumps (it needs Redis, like the other Redis-backed tests), and the map cache's version, time-to-live and forget rules. The dynamic entity, resource-doc and cache suites pass locally, and on a k3s deployment with the default list cache the dynamic entity end-to-end test passes, with OBP-API logging the dynamic_entity, rd_dynamic and rd_all bumps after the commit on create and on delete.

…ons change

DynamicEntityHelper rebuilds its definitions map from NewStyle.getDynamicEntities,
which keeps its list in Redis for dynamicEntity.cache.ttl.seconds. forgetDefinitions
now also deletes the memoized getDynamicEntities lists, once the request's
transaction has committed, so the rebuilt map reads the current rows and a new
entity's record endpoints answer immediately instead of after the map's
time-to-live. This node's map is still dropped at once for reads later in the
same request.
…for definitions

A definition change now bumps a new dynamic_entity cache namespace once its
transaction has committed, instead of deleting the memoized lists by pattern.
The lists NewStyle.getDynamicEntities and getDynamicEntitiesByUserId memoize
carry that version in their keys, and DynamicEntityHelper keeps its
definitions map (DefinitionsMapCache) only while the version is the one it
was built under, so every instance reads the definitions again within a
second, and a read still in flight cannot store old rows under the new
version. The dynamic resource-doc caches are bumped in the same after-commit
step rather than inside the request transaction. The namespace is listed on
the cache info page and can be bumped through the cache namespace endpoint.
@sonarqubecloud

sonarqubecloud Bot commented Nov 2, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant