Skip to content

Conversation

mherwege
Copy link
Contributor

@mherwege mherwege commented Mar 26, 2025

Closes #4470

This is a breaking change.

With this PR, the default persistence strategy is not applied automatically anymore when no other strategy is defined.

The PersistenceService interface still keeps the getDefaultStrategies method. Therefore no change is required in the persistence services implementations. But rather than applying this automatically, these default strategies are now considered configuration suggestions.

The current PersistenceService.getDefaultStrategies() method has been deprecated and replaced by a PersistenceService.getSuggestedStrategies() method. A default implementation will redirect PersistenceService.getSuggestedStrategies() to PersistenceService.getDefaultStrategies(), so there is no need to immediately change PersistenceService implementations.

An extra sub-endpoint to the persistence REST API endpoint is defined to retrieve these strategy suggestions (GET persistence/strategysuggestions?serviceId={serviceId}). This endpoint can be used by the UI to suggest strategies when configuring the service. Applying these suggestions will then become a clear user decision.

File based persistence configurations will have to be changed by the user if they use the default strategies.

As part of this PR, a persistence configuration health check endpoint has been implemented(GET persistence/persistencehealth?serviceId={serviceId}). This endpoint will then be used in the UI to show persistence configuration health (similar to orphan links), and will allow more easy support when default strategies are being removed.

To complete this functionality, the following is also needed:

@mherwege mherwege requested a review from a team as a code owner March 26, 2025 15:59
@mherwege
Copy link
Contributor Author

@J-N-K Can you let me know what you think? If this is accepted as the direction, I could start working on the UI side of this. But I don't want to spend time if the direction is not agreed upon.

@J-N-K
Copy link
Member

J-N-K commented Mar 28, 2025

This is what I suggested about two years ago (IIRC). IMO a "proposal" is much better than some magic that is applied. However, there might be an issue with the "empty strategy". It would be better (but not so easy to implement) when the persistence service is not considered "ready" up without a valid configuration. It is necessary to allow the service to start, otherwise it can't be found and as a result the suggested strategy is not present (and the service can't be configured), but it should not be considered as "available".

@mherwege
Copy link
Contributor Author

It would be better (but not so easy to implement) when the persistence service is not considered "ready" up without a valid configuration.

Yes, I agree that would be better. But it would require implementing a life cycle for persistence services (like for things) which is beyond what I feel comfortable doing. A persistence service persisting anything is not just dependent on a strategy being available, but also items to be persisted defined. What if you delete the all item definitions from an existing configuration? Should it go back to not ready? It should. I think it makes it more complicated then needed, and just not doing anything with an empty definition, or an item definition with no strategy is acceptable I believe.

@mherwege mherwege force-pushed the persistence_no_default branch from 1666ab4 to 0f0b1c6 Compare March 28, 2025 19:44
@mherwege mherwege marked this pull request as draft March 29, 2025 07:50
@mherwege mherwege marked this pull request as ready for review March 31, 2025 12:10
@mherwege mherwege force-pushed the persistence_no_default branch from 0301274 to 773395a Compare April 3, 2025 07:17
@mherwege mherwege changed the title Persistence no default strategies Persistence no default strategies and persistence configuration health check Apr 3, 2025
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/oh-5-0-0-snapshot-mapdb-persistence-not-restoring-some-items-on-startup/163502/2

@mherwege
Copy link
Contributor Author

mherwege commented Apr 3, 2025

@holgerfriedrich I saw #4693. This PR is already rebased on that PR, but I still see a javadoc failure. Should this be resolved?

* be used to allow the consumer (e.g. UI) to tailor the message.
* @param serviceId persistence service
* @param items list of persistence item definitions
* @param strategy persistence strategy selected for the list of items
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param strategy persistence strategy selected for the list of items

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good now I believe.

@holgerfriedrich
Copy link
Member

@mherwege the log of the javadoc job needs improvement. Running it locally, I see the message causing it to fail:

[INFO] The goal 'org.apache.maven.plugins:maven-javadoc-plugin:3.11.2:javadoc' has not been previously called for the module: 'org.openhab.core.bom:org.openhab.core.bom.compile-model:pom:5.0.0-SNAPSHOT'. Trying to invoke it...
[WARNING] Javadoc Warnings
[WARNING] openhab-core\bundles\org.openhab.core.persistence\src\main\java\org\openhab\core\persistence\PersistenceServiceProblem.java:26: warning: @param argument "strategy" is not the name of a record component.
[WARNING] * @param strategy persistence strategy selected for the list of items

@mherwege
Copy link
Contributor Author

mherwege commented Apr 4, 2025

Thanks. How do I run this locally?

@mherwege mherwege force-pushed the persistence_no_default branch from 3eaea1b to 709e40b Compare April 16, 2025 08:36
@J-N-K
Copy link
Member

J-N-K commented May 19, 2025

What is the current state here? I see 4/4 tasks completed, but has everything been done and this can be considered as "ready for review"?

@mherwege
Copy link
Contributor Author

What is the current state here? I see 4/4 tasks completed, but has everything been done and this can be considered as "ready for review"?

Yes, I consider this ready for review, in combination with the related PR's that are also ready.

@mherwege
Copy link
Contributor Author

@J-N-K Any chance to get this across the line?

@mherwege mherwege force-pushed the persistence_no_default branch from 709e40b to f72a54e Compare June 30, 2025 10:49
@mherwege
Copy link
Contributor Author

Rebased to account for changes in UpgradeTool.

@wborn wborn requested a review from Copilot July 26, 2025 15:54
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a breaking change that removes automatic application of default persistence strategies when no strategy is defined, requiring explicit configuration by users instead.

Key changes:

  • Deprecated PersistenceService.getDefaultStrategies() in favor of PersistenceService.getSuggestedStrategies()
  • Added persistence configuration health check API endpoint
  • Created upgrade tool to migrate existing configurations with missing strategies

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/upgradetool/src/main/java/org/openhab/core/tools/internal/PersistenceUpgrader.java New upgrader class to migrate persistence configurations by copying default strategies to configurations without explicit strategies
tools/upgradetool/src/main/java/org/openhab/core/tools/UpgradeTool.java Added persistence upgrader to the list of upgraders
tools/upgradetool/pom.xml Added persistence bundle dependency and OSGi annotations
bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/PersistenceService.java Deprecated getDefaultStrategies() and added getSuggestedStrategies() method
bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/PersistenceServiceProblem.java New record class for representing persistence configuration problems
bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManagerImpl.java Removed automatic application of default strategies and simplified configuration handling
bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResource.java Added new REST endpoints for strategy suggestions and persistence health checks

mherwege added 4 commits July 29, 2025 15:59
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
@mherwege mherwege force-pushed the persistence_no_default branch from 3595f9e to 11cc97c Compare July 29, 2025 14:41
@mherwege
Copy link
Contributor Author

@wborn Rebased and copilot suggestions considered.

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.

Remove default persistence strategy and replace by suggested strategy

4 participants