Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature cache #2959

Merged
merged 7 commits into from
Apr 30, 2020
Merged

Feature cache #2959

merged 7 commits into from
Apr 30, 2020

Conversation

riccardomodanese
Copy link
Contributor

This PR introduces a caching feature at the service level. This implementation is compliant with the JCache specification, meaning that each cache that implements the JCache interface can be used with this caching feature.

The cache is implemented a given set of services, in order to improve performances. A simple JCache implementation based on HashMaps is also provided, in order to test the caching feature with the QAs.

Related Issue

N/A

Description of the solution adopted

The package org.eclipse.kapua.commons.service.internal.cache contains the KapuaCacheManager, which is responsible for instantiating a cache for each service, and the EntityCache class, which defines our basic cache implementation (using entities Ids as keys) on top of JCache. NamedEntityCache extends EntityCache by providing an additional cache (using entities names as keys).

The cache allows avoiding repeated queries to the database, in particular when checking permissions to perform an action on a given method. As an example, the checkPermission method of the AuthorizationService (responsible for checking if an user is allowed to perform a given operation), performs a chain of calls to the UserService, AccessInfoService, AccessPermissionService, AccessRoleService, RoleService and RolePermissionService services, each of which performs a query to the db. Caching all these services allows considerably reducing the time spent on querying the db.

Also, note that the message processing by the broker requires methods from the AccountService and DeviceRegistryService, which both perform transactions to the database. Such transactions are performed for each message received by the broker, thus using a cache on those services allows reducing queries when the same data is required.

The QAs will make use of an in-memory HashMaps-based implementation of JCache in order to mimic the behaviour of a real cache instance. In order to mimic the serialisation, this cache is also provided with a clone method which performs a deep clone of the given entity in put and get operations.

Screenshots

N/A

Any side note on the changes made

Note also that this cache feature requires a JCache implementation to run, otherwise a 'dummy' cache is used.

Services require to be modified in order to implement the cache. The following services have been cached:

  • AccessInfoService
  • AccessPermissionService
  • AccessRoleService
  • AccountService
  • DeviceConnectionService
  • DeviceRegistryService
  • RoleService
  • RolePermissionService
  • UserService

Each service is able to instantiate is own cache through a dedicated cache factory. However, note that DeviceConnectionService is not using a dedicated cache factory, but it relies on the DeviceRegistryCacheFactory. Moreover, also the AbstractKapuaConfigurableService has been provided with a cache instance, in order to cache the configuration values for each services. A LocalCache instance (which must not be confused with a JCache cache instance) has also been added in order to store the config metadata, which do not change after the first time the object is loaded.

The JCache implementation for the QAs is enabled trough the following property commons.cache.provider.classname=org.eclipse.kapua.qa.common.cache.MapCachingProvider

riccardomodanese and others added 7 commits April 29, 2020 14:45
- adding deprecation for few old methods
- removing deprecated code from entity manager

Signed-off-by: riccardomodanese <riccardo.modanese@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
Signed-off-by: Gianluca Barbon <gianluca.barbon@eurotech.com>
…ove to dependdency management root pom section

Signed-off-by: riccardomodanese <riccardo.modanese@eurotech.com>
@riccardomodanese riccardomodanese requested a review from Coduz April 30, 2020 09:51
@codecov
Copy link

codecov bot commented Apr 30, 2020

Codecov Report

Merging #2959 into develop will increase coverage by 0.31%.
The diff coverage is 68.82%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #2959      +/-   ##
=============================================
+ Coverage      55.92%   56.24%   +0.31%     
- Complexity      2557     2592      +35     
=============================================
  Files           1044     1059      +15     
  Lines          22692    22975     +283     
  Branches        2036     2061      +25     
=============================================
+ Hits           12691    12922     +231     
- Misses          9067     9106      +39     
- Partials         934      947      +13     
Impacted Files Coverage Δ Complexity Δ
...ua/commons/event/RaiseServiceEventInterceptor.java 4.44% <0.00%> (ø) 0.00 <0.00> (ø)
...apua/commons/jpa/AbstractEntityManagerFactory.java 77.77% <ø> (ø) 0.00 <0.00> (ø)
...a/org/eclipse/kapua/commons/jpa/EntityManager.java 70.90% <0.00%> (-2.68%) 0.00 <0.00> (ø)
...ns/service/event/store/internal/EventStoreDAO.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...ce/event/store/internal/EventStoreServiceImpl.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...job/engine/queue/jbatch/QueuedJobExecutionDAO.java 64.28% <0.00%> (+4.28%) 3.00 <0.00> (ø)
.../job/internal/JobDeviceManagementOperationDAO.java 60.00% <0.00%> (+5.45%) 3.00 <0.00> (ø)
...eration/internal/DeviceManagementOperationDAO.java 78.94% <0.00%> (+3.94%) 4.00 <0.00> (ø)
...step/definition/internal/JobStepDefinitionDAO.java 61.11% <0.00%> (+3.21%) 3.00 <0.00> (ø)
...pua/service/job/targets/internal/JobTargetDAO.java 73.33% <0.00%> (+4.58%) 5.00 <0.00> (ø)
... and 99 more

@Coduz
Copy link
Contributor

Coduz commented Apr 30, 2020

Commits authored from @gbarbon comes from following PRs:
cache - Internal cache implementation - be31ac1 - #2892
cache - Adding cache to services. - 560ff02 - #2945
cache - Adding HashMap-based JCache implementation to QAs - 5fa44f2 - #2955

@Coduz Coduz removed their assignment Apr 30, 2020
@Coduz Coduz added the Enhancement This PR/Issue improves an part of Kapua label Apr 30, 2020
@Coduz Coduz merged commit 1d928ef into develop Apr 30, 2020
@Coduz Coduz deleted the feature-cache branch April 30, 2020 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement This PR/Issue improves an part of Kapua
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants