From f361dfeb1ecb6d38237e2f2674d9f11943a59b37 Mon Sep 17 00:00:00 2001 From: ViacheslavKlimov Date: Mon, 14 Apr 2025 18:33:47 +0300 Subject: [PATCH] Fix CF entity profiles cache initialization --- .../server/actors/tenant/TenantActor.java | 1 + .../cf/DefaultCalculatedFieldInitService.java | 68 ------------------- .../server/queue/util/AfterStartUp.java | 1 - 3 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 application/src/main/java/org/thingsboard/server/service/cf/DefaultCalculatedFieldInitService.java diff --git a/application/src/main/java/org/thingsboard/server/actors/tenant/TenantActor.java b/application/src/main/java/org/thingsboard/server/actors/tenant/TenantActor.java index 9605324782..84edd064b5 100644 --- a/application/src/main/java/org/thingsboard/server/actors/tenant/TenantActor.java +++ b/application/src/main/java/org/thingsboard/server/actors/tenant/TenantActor.java @@ -100,6 +100,7 @@ public class TenantActor extends RuleChainManagerActor { () -> DefaultActorService.CF_MANAGER_DISPATCHER_NAME, () -> new CalculatedFieldManagerActorCreator(systemContext, tenantId), () -> true); + cfActor.tellWithHighPriority(new CalculatedFieldCacheInitMsg(tenantId)); } catch (Exception e) { log.info("[{}] Failed to init CF Actor.", tenantId, e); } diff --git a/application/src/main/java/org/thingsboard/server/service/cf/DefaultCalculatedFieldInitService.java b/application/src/main/java/org/thingsboard/server/service/cf/DefaultCalculatedFieldInitService.java deleted file mode 100644 index 79950f2e3f..0000000000 --- a/application/src/main/java/org/thingsboard/server/service/cf/DefaultCalculatedFieldInitService.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright © 2016-2025 The Thingsboard Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.thingsboard.server.service.cf; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.thingsboard.server.actors.ActorSystemContext; -import org.thingsboard.server.common.data.ProfileEntityIdInfo; -import org.thingsboard.server.common.data.page.PageDataIterable; -import org.thingsboard.server.common.msg.cf.CalculatedFieldInitProfileEntityMsg; -import org.thingsboard.server.dao.asset.AssetService; -import org.thingsboard.server.dao.device.DeviceService; -import org.thingsboard.server.queue.util.AfterStartUp; -import org.thingsboard.server.queue.util.TbRuleEngineComponent; - -@Slf4j -@Service -@TbRuleEngineComponent -@RequiredArgsConstructor -public class DefaultCalculatedFieldInitService implements CalculatedFieldInitService { - - private final AssetService assetService; - private final DeviceService deviceService; - private final ActorSystemContext actorSystemContext; - - @Value("${queue.calculated_fields.init_fetch_pack_size:50000}") - @Getter - private int initFetchPackSize; - - @AfterStartUp(order = AfterStartUp.CF_READ_PROFILE_ENTITIES_SERVICE) - public void initCalculatedFieldDefinitions() { - PageDataIterable deviceIdInfos = new PageDataIterable<>(deviceService::findProfileEntityIdInfos, initFetchPackSize); - for (ProfileEntityIdInfo idInfo : deviceIdInfos) { - log.trace("Processing device record: {}", idInfo); - try { - actorSystemContext.tell(new CalculatedFieldInitProfileEntityMsg(idInfo.getTenantId(), idInfo.getProfileId(), idInfo.getEntityId())); - } catch (Exception e) { - log.error("Failed to process device record: {}", idInfo, e); - } - } - PageDataIterable assetIdInfos = new PageDataIterable<>(assetService::findProfileEntityIdInfos, initFetchPackSize); - for (ProfileEntityIdInfo idInfo : assetIdInfos) { - log.trace("Processing asset record: {}", idInfo); - try { - actorSystemContext.tell(new CalculatedFieldInitProfileEntityMsg(idInfo.getTenantId(), idInfo.getProfileId(), idInfo.getEntityId())); - } catch (Exception e) { - log.error("Failed to process asset record: {}", idInfo, e); - } - } - } - -} diff --git a/common/queue/src/main/java/org/thingsboard/server/queue/util/AfterStartUp.java b/common/queue/src/main/java/org/thingsboard/server/queue/util/AfterStartUp.java index 6a3aaa4a7f..8cf48faaa6 100644 --- a/common/queue/src/main/java/org/thingsboard/server/queue/util/AfterStartUp.java +++ b/common/queue/src/main/java/org/thingsboard/server/queue/util/AfterStartUp.java @@ -37,7 +37,6 @@ public @interface AfterStartUp { int STARTUP_SERVICE = 8; int ACTOR_SYSTEM = 9; - int CF_READ_PROFILE_ENTITIES_SERVICE = 10; int CF_READ_CF_SERVICE = 10; int REGULAR_SERVICE = 11;