thingsboard / thingsboard-edge

Apache License 2.0
93 stars 71 forks source link

CalculateDeltaNode: Delta calculation fails after upgrade to 3.7.0 #114

Closed AdrienAdB closed 3 weeks ago

AdrienAdB commented 3 weeks ago

Describe the bug

Rule chain node delta calculation fails after upgrade to TB-EDGE 3.7.0

Server configuration

# REDIS
export CACHE_TYPE=redis
export REDIS_CONNECTION_TYPE=standalone
export REDIS_HOST=localhost
export REDIS_PORT=6379

Additional context

msg:

{
    "e": 6004.3
}

Node config:

{"inputValueKey":"e","outputValueKey":"energy_delta","useCache":false,"addPeriodBetweenMsgs":false,"periodValueKey":"periodInMs","round":null,"tellFailureIfDeltaIsNegative":true,"excludeZeroDeltas":false}

Error:

java.lang.NullPointerException: Cannot invoke "java.util.Map.get(Object)" because "this.cache" is null
    at org.thingsboard.rule.engine.metadata.CalculateDeltaNode.getLatestFromCacheOrFetchFromDb(CalculateDeltaNode.java:184)
    at org.thingsboard.rule.engine.metadata.CalculateDeltaNode.processMsgAsync(CalculateDeltaNode.java:152)
    at org.thingsboard.rule.engine.util.SemaphoreWithTbMsgQueue.tryProcessQueue(SemaphoreWithTbMsgQueue.java:94)
    at org.thingsboard.rule.engine.util.SemaphoreWithTbMsgQueue.addToQueueAndTryProcess(SemaphoreWithTbMsgQueue.java:59)
    at org.thingsboard.rule.engine.metadata.CalculateDeltaNode.onMsg(CalculateDeltaNode.java:95)
    at org.thingsboard.server.actors.ruleChain.RuleNodeActorMessageProcessor.onRuleChainToRuleNodeMsg(RuleNodeActorMessageProcessor.java:158)
    at org.thingsboard.server.actors.ruleChain.RuleNodeActor.onRuleChainToRuleNodeMsg(RuleNodeActor.java:101)
    at org.thingsboard.server.actors.ruleChain.RuleNodeActor.doProcess(RuleNodeActor.java:60)
    at org.thingsboard.server.actors.service.ContextAwareActor.process(ContextAwareActor.java:41)
    at org.thingsboard.server.actors.TbActorMailbox.processMailbox(TbActorMailbox.java:157)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
AdrienAdB commented 3 weeks ago

Forcing useCache seems to work with Redis.

{"inputValueKey":"e","outputValueKey":"energy_delta","useCache":true,"addPeriodBetweenMsgs":false,"periodValueKey":"periodInMs","round":null,"tellFailureIfDeltaIsNegative":true,"excludeZeroDeltas":false}
AndriiLandiak commented 3 weeks ago

Hi, @AdrienAdB.

Currently, there is an issue with this rule node that only allows it to function properly when the "Use cache" option is set to true. This issue will be fixed in the upcoming minor release - 3.7.1. But as for now, just set "useCase" to true.

If you encounter any issues or have questions, please do not hesitate to reach out to us.