Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Rules/Sitemaps/Scripts refreshed twice #4824

Closed
cribskip opened this issue Dec 29, 2017 · 2 comments · Fixed by #4834
Closed

Rules/Sitemaps/Scripts refreshed twice #4824

cribskip opened this issue Dec 29, 2017 · 2 comments · Fixed by #4834
Labels

Comments

@cribskip
Copy link

cribskip commented Dec 29, 2017

When changing files (rules, scripts, sitemaps), this results in openHAB to Load and Refresh the file twice, causing unnecessary delays especially on embedded platforms.

Expected behaviour
When changing files, the ModelRepositoryImpl should only refresh known files. When a new file is added, it should be added and watched out for changes.

Current behaviour
When changing files (rules, scripts, sitemaps), this results in openHAB to Load and Refresh the file twice, causing unnecessary delays especially on embedded platforms.

Possible solution
None known. Workaround: Stop openhab, change files as needed, start openhab again.

Steps to reproduce
Change a configuration file (rule, sitemap, script) by using any editor. Look at the openhab.log and notice "Loading model XXX", "Refreshing model XXX", "Refreshing model XXX".

My environment
Debian 9.3 on raspberry pi 3 with openhab2 2.2.0-1 stable out of repo.
root@openhab2:~# java -version
openjdk version "1.8.0_152"
OpenJDK Runtime Environment (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
OpenJDK Client VM (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 25.152-b76, mixed mode, Evaluation)

Additional notes
The bug may be caused by one of these places: https://github.com/eclipse/smarthome/blob/36c9e2717e4f89cf60a0d885e7ecc6069b338f48/bundles/model/org.eclipse.smarthome.model.core/src/main/java/org/eclipse/smarthome/model/core/internal/folder/FolderObserver.java#L242

https://github.com/eclipse/smarthome/blob/36c9e2717e4f89cf60a0d885e7ecc6069b338f48/bundles/model/org.eclipse.smarthome.model.core/src/main/java/org/eclipse/smarthome/model/core/internal/ModelRepositoryImpl.java#L91

Also discussed in the community
https://community.openhab.org/t/rules-still-loading-running-twice/22183

@sjsf
Copy link
Contributor

sjsf commented Jan 2, 2018

The framework gets these events from the JVM, and the JVM gets them from the OS/FileSystem more or less directly. I have seen this a couple of times and apparently factors like OS, files system, remote access method and used editor have an influence of this.

I was thinking already of adding a grace period in FolderObserver, i.e. only load/refresh models after there hasn't been any such event for a certain amount of time (e.g. one or very few seconds).

@sjsf sjsf added the DSL label Jan 2, 2018
sjsf added a commit to sjsf/smarthome that referenced this issue Jan 2, 2018
...in order to skip duplicate file system events or intermediate
states where the file technically is empty for a very short
moment.

fixes eclipse-archived#4824
Signed-off-by: Simon Kaufmann <simon.kfm@googlemail.com>
sjsf added a commit to sjsf/smarthome that referenced this issue Jan 2, 2018
...in order to skip duplicate file system events or intermediate
states where the file technically is empty for a very short
moment.

fixes eclipse-archived#4824
Signed-off-by: Simon Kaufmann <simon.kfm@googlemail.com>
sjsf added a commit to sjsf/smarthome that referenced this issue Jan 2, 2018
...in order to skip duplicate file system events or intermediate
states where the file technically is empty for a very short
moment.

fixes eclipse-archived#4824
Signed-off-by: Simon Kaufmann <simon.kfm@googlemail.com>
kaikreuzer pushed a commit that referenced this issue Jan 2, 2018
* delay processing of model files

...in order to skip duplicate file system events or intermediate
states where the file technically is empty for a very short
moment.

fixes #4824
Signed-off-by: Simon Kaufmann <simon.kfm@googlemail.com>
dgajic pushed a commit to dgajic/smarthome that referenced this issue Jan 27, 2018
* delay processing of model files

...in order to skip duplicate file system events or intermediate
states where the file technically is empty for a very short
moment.

fixes eclipse-archived#4824
Signed-off-by: Simon Kaufmann <simon.kfm@googlemail.com>
@cribskip
Copy link
Author

@SJKA Thank you very much for implementing this workaround. However, I just found a quirk (I'm unsure if I should open a new issue):
Running on a Raspi 3, if a rule file compiles fast, your patch works just fine preventing a second reload. However, if the rule compilation is too time consuming, it still reloades twice still escalating the situation. It would be great if a ongoing compilation could be sensed and a reload canceled until this is done.

Here are two examples:

# Working fine: Compilation in approx. 5 seconds, no second reload:
2018-08-24 21:10:42.422 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model '99_program.rules'
2018-08-24 21:10:47.216 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model '99_program.rules'
# Troublesome: Compilation takes approx. 23 seconds, second reload occurs:
2018-08-24 21:17:09.896 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model '99_voice.rules'
2018-08-24 21:17:32.390 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model '99_voice.rules'
2018-08-24 21:17:42.240 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model '99_voice.rules'
2018-08-24 21:18:04.272 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model '99_voice.rules'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants