Browse Source

Edge cache

pull/6536/head
Andrii Shvaika 4 years ago
parent
commit
29396864f2
  1. 3
      dao/src/main/java/org/thingsboard/server/dao/asset/AssetCacheEvictEvent.java
  2. 16
      dao/src/main/java/org/thingsboard/server/dao/asset/AssetRedisCache.java
  3. 1
      dao/src/main/java/org/thingsboard/server/dao/asset/BaseAssetService.java
  4. 16
      dao/src/main/java/org/thingsboard/server/dao/attributes/AttributeRedisCache.java
  5. 35
      dao/src/main/java/org/thingsboard/server/dao/cache/TbRedisSerializer.java
  6. 16
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceRedisCache.java
  7. 30
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeCacheEvictEvent.java
  8. 41
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeCacheKey.java
  9. 35
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeCaffeineCache.java
  10. 39
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeRedisCache.java
  11. 46
      dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java
  12. 16
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewRedisCache.java
  13. 16
      dao/src/main/java/org/thingsboard/server/dao/relation/RelationRedisCache.java
  14. 16
      dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileRedisCache.java

3
dao/src/main/java/org/thingsboard/server/dao/asset/AssetCacheEvictEvent.java

@ -27,7 +27,4 @@ class AssetCacheEvictEvent {
private final String newName; private final String newName;
private final String oldName; private final String oldName;
public AssetCacheEvictEvent(TenantId tenantId, String newName) {
this(tenantId, newName, null);
}
} }

16
dao/src/main/java/org/thingsboard/server/dao/asset/AssetRedisCache.java

@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.CacheConstants;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.dao.cache.RedisTbTransactionalCache; import org.thingsboard.server.dao.cache.RedisTbTransactionalCache;
import org.thingsboard.server.dao.cache.TbRedisSerializer;
import org.thingsboard.server.dao.device.DeviceCacheKey; import org.thingsboard.server.dao.device.DeviceCacheKey;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
@ -33,19 +34,6 @@ import org.thingsboard.server.dao.device.DeviceCacheKey;
public class AssetRedisCache extends RedisTbTransactionalCache<AssetCacheKey, Asset> { public class AssetRedisCache extends RedisTbTransactionalCache<AssetCacheKey, Asset> {
public AssetRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) { public AssetRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
super(CacheConstants.ASSET_CACHE, cacheSpecsMap, connectionFactory, configuration, new RedisSerializer<>() { super(CacheConstants.ASSET_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbRedisSerializer<>());
private final RedisSerializer<Object> java = RedisSerializer.java();
@Override
public byte[] serialize(Asset attributeKvEntry) throws SerializationException {
return java.serialize(attributeKvEntry);
}
@Override
public Asset deserialize(byte[] bytes) throws SerializationException {
return (Asset) java.deserialize(bytes);
}
});
} }
} }

1
dao/src/main/java/org/thingsboard/server/dao/asset/BaseAssetService.java

@ -116,7 +116,6 @@ public class BaseAssetService extends AbstractCachedEntityService<AssetCacheKey,
return cache.getAndPutInTransaction(new AssetCacheKey(tenantId, name), return cache.getAndPutInTransaction(new AssetCacheKey(tenantId, name),
() -> assetDao.findAssetsByTenantIdAndName(tenantId.getId(), name) () -> assetDao.findAssetsByTenantIdAndName(tenantId.getId(), name)
.orElse(null), true); .orElse(null), true);
} }
@Transactional(propagation = Propagation.SUPPORTS) @Transactional(propagation = Propagation.SUPPORTS)

16
dao/src/main/java/org/thingsboard/server/dao/attributes/AttributeRedisCache.java

@ -27,25 +27,13 @@ import org.thingsboard.server.cache.TBRedisCacheConfiguration;
import org.thingsboard.server.common.data.CacheConstants; import org.thingsboard.server.common.data.CacheConstants;
import org.thingsboard.server.common.data.kv.AttributeKvEntry; import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.dao.cache.RedisTbTransactionalCache; import org.thingsboard.server.dao.cache.RedisTbTransactionalCache;
import org.thingsboard.server.dao.cache.TbRedisSerializer;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
@Service("AttributeCache") @Service("AttributeCache")
public class AttributeRedisCache extends RedisTbTransactionalCache<AttributeCacheKey, AttributeKvEntry> { public class AttributeRedisCache extends RedisTbTransactionalCache<AttributeCacheKey, AttributeKvEntry> {
public AttributeRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) { public AttributeRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
super(CacheConstants.ATTRIBUTES_CACHE, cacheSpecsMap, connectionFactory, configuration, new RedisSerializer<>() { super(CacheConstants.ATTRIBUTES_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbRedisSerializer<>());
private final RedisSerializer<Object> java = RedisSerializer.java();
@Override
public byte[] serialize(AttributeKvEntry attributeKvEntry) throws SerializationException {
return java.serialize(attributeKvEntry);
}
@Override
public AttributeKvEntry deserialize(byte[] bytes) throws SerializationException {
return (AttributeKvEntry) java.deserialize(bytes);
}
});
} }
} }

35
dao/src/main/java/org/thingsboard/server/dao/cache/TbRedisSerializer.java

@ -0,0 +1,35 @@
/**
* Copyright © 2016-2022 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.dao.cache;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.thingsboard.server.common.data.edge.Edge;
public class TbRedisSerializer<T> implements RedisSerializer<T> {
private final RedisSerializer<Object> java = RedisSerializer.java();
@Override
public byte[] serialize(T t) throws SerializationException {
return java.serialize(t);
}
@Override
public T deserialize(byte[] bytes) throws SerializationException {
return (T) java.deserialize(bytes);
}
}

16
dao/src/main/java/org/thingsboard/server/dao/device/DeviceRedisCache.java

@ -25,25 +25,13 @@ import org.thingsboard.server.cache.TBRedisCacheConfiguration;
import org.thingsboard.server.common.data.CacheConstants; import org.thingsboard.server.common.data.CacheConstants;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.dao.cache.RedisTbTransactionalCache; import org.thingsboard.server.dao.cache.RedisTbTransactionalCache;
import org.thingsboard.server.dao.cache.TbRedisSerializer;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
@Service("DeviceCache") @Service("DeviceCache")
public class DeviceRedisCache extends RedisTbTransactionalCache<DeviceCacheKey, Device> { public class DeviceRedisCache extends RedisTbTransactionalCache<DeviceCacheKey, Device> {
public DeviceRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) { public DeviceRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
super(CacheConstants.DEVICE_CACHE, cacheSpecsMap, connectionFactory, configuration, new RedisSerializer<>() { super(CacheConstants.DEVICE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbRedisSerializer<>());
private final RedisSerializer<Object> java = RedisSerializer.java();
@Override
public byte[] serialize(Device attributeKvEntry) throws SerializationException {
return java.serialize(attributeKvEntry);
}
@Override
public Device deserialize(byte[] bytes) throws SerializationException {
return (Device) java.deserialize(bytes);
}
});
} }
} }

30
dao/src/main/java/org/thingsboard/server/dao/edge/EdgeCacheEvictEvent.java

@ -0,0 +1,30 @@
/**
* Copyright © 2016-2022 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.dao.edge;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.thingsboard.server.common.data.id.TenantId;
@Data
@RequiredArgsConstructor
class EdgeCacheEvictEvent {
private final TenantId tenantId;
private final String newName;
private final String oldName;
}

41
dao/src/main/java/org/thingsboard/server/dao/edge/EdgeCacheKey.java

@ -0,0 +1,41 @@
/**
* Copyright © 2016-2022 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.dao.edge;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.thingsboard.server.cache.CacheKeyUtil;
import org.thingsboard.server.common.data.id.TenantId;
import java.io.Serializable;
@Getter
@EqualsAndHashCode
@RequiredArgsConstructor
@Builder
public class EdgeCacheKey implements Serializable {
private final TenantId tenantId;
private final String name;
@Override
public String toString() {
return CacheKeyUtil.toString(tenantId, name);
}
}

35
dao/src/main/java/org/thingsboard/server/dao/edge/EdgeCaffeineCache.java

@ -0,0 +1,35 @@
/**
* Copyright © 2016-2022 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.dao.edge;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.CacheConstants;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.dao.asset.AssetCacheKey;
import org.thingsboard.server.dao.cache.CaffeineTbTransactionalCache;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "caffeine", matchIfMissing = true)
@Service("EdgeCache")
public class EdgeCaffeineCache extends CaffeineTbTransactionalCache<EdgeCacheKey, Edge> {
public EdgeCaffeineCache(CacheManager cacheManager) {
super(cacheManager, CacheConstants.EDGE_CACHE);
}
}

39
dao/src/main/java/org/thingsboard/server/dao/edge/EdgeRedisCache.java

@ -0,0 +1,39 @@
/**
* Copyright © 2016-2022 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.dao.edge;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.stereotype.Service;
import org.thingsboard.server.cache.CacheSpecsMap;
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
import org.thingsboard.server.common.data.CacheConstants;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.dao.asset.AssetCacheKey;
import org.thingsboard.server.dao.cache.RedisTbTransactionalCache;
import org.thingsboard.server.dao.cache.TbRedisSerializer;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
@Service("EdgeCache")
public class EdgeRedisCache extends RedisTbTransactionalCache<EdgeCacheKey, Edge> {
public EdgeRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
super(CacheConstants.EDGE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbRedisSerializer<>());
}
}

46
dao/src/main/java/org/thingsboard/server/dao/edge/EdgeServiceImpl.java

@ -25,11 +25,14 @@ import com.google.common.util.concurrent.MoreExecutors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;
import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.EntitySubtype;
import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.edge.Edge; import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.edge.EdgeInfo; import org.thingsboard.server.common.data.edge.EdgeInfo;
@ -47,8 +50,7 @@ import org.thingsboard.server.common.data.relation.EntityRelation;
import org.thingsboard.server.common.data.relation.EntitySearchDirection; import org.thingsboard.server.common.data.relation.EntitySearchDirection;
import org.thingsboard.server.common.data.rule.RuleChain; import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainConnectionInfo; import org.thingsboard.server.common.data.rule.RuleChainConnectionInfo;
import org.thingsboard.server.dao.cache.EntitiesCacheManager; import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
import org.thingsboard.server.dao.entity.AbstractEntityService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.relation.RelationService; import org.thingsboard.server.dao.relation.RelationService;
import org.thingsboard.server.dao.rule.RuleChainService; import org.thingsboard.server.dao.rule.RuleChainService;
@ -74,7 +76,7 @@ import static org.thingsboard.server.dao.service.Validator.validateString;
@Service @Service
@Slf4j @Slf4j
public class EdgeServiceImpl extends AbstractEntityService implements EdgeService { public class EdgeServiceImpl extends AbstractCachedEntityService<EdgeCacheKey, Edge, EdgeCacheEvictEvent> implements EdgeService {
public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; public static final String INCORRECT_TENANT_ID = "Incorrect tenantId ";
public static final String INCORRECT_CUSTOMER_ID = "Incorrect customerId "; public static final String INCORRECT_CUSTOMER_ID = "Incorrect customerId ";
@ -90,9 +92,6 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private EntitiesCacheManager cacheManager;
@Autowired @Autowired
private RuleChainService ruleChainService; private RuleChainService ruleChainService;
@ -102,6 +101,17 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
@Autowired @Autowired
private DataValidator<Edge> edgeValidator; private DataValidator<Edge> edgeValidator;
@TransactionalEventListener(classes = EdgeCacheEvictEvent.class)
@Override
public void handleEvictEvent(EdgeCacheEvictEvent event) {
List<EdgeCacheKey> keys = new ArrayList<>(2);
keys.add(new EdgeCacheKey(event.getTenantId(), event.getNewName()));
if (StringUtils.isNotEmpty(event.getOldName()) && !event.getOldName().equals(event.getNewName())) {
keys.add(new EdgeCacheKey(event.getTenantId(), event.getOldName()));
}
cache.evict(keys);
}
@Override @Override
public Edge findEdgeById(TenantId tenantId, EdgeId edgeId) { public Edge findEdgeById(TenantId tenantId, EdgeId edgeId) {
log.trace("Executing findEdgeById [{}]", edgeId); log.trace("Executing findEdgeById [{}]", edgeId);
@ -128,8 +138,9 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
public Edge findEdgeByTenantIdAndName(TenantId tenantId, String name) { public Edge findEdgeByTenantIdAndName(TenantId tenantId, String name) {
log.trace("Executing findEdgeByTenantIdAndName [{}][{}]", tenantId, name); log.trace("Executing findEdgeByTenantIdAndName [{}][{}]", tenantId, name);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
Optional<Edge> edgeOpt = edgeDao.findEdgeByTenantIdAndName(tenantId.getId(), name); return cache.getAndPutInTransaction(new EdgeCacheKey(tenantId, name),
return edgeOpt.orElse(null); () -> edgeDao.findEdgeByTenantIdAndName(tenantId.getId(), name)
.orElse(null), true);
} }
@Override @Override
@ -139,13 +150,16 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
return edgeDao.findByRoutingKey(tenantId.getId(), routingKey); return edgeDao.findByRoutingKey(tenantId.getId(), routingKey);
} }
@CacheEvict(cacheNames = EDGE_CACHE, key = "{#edge.tenantId, #edge.name}") @Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
public Edge saveEdge(Edge edge) { public Edge saveEdge(Edge edge) {
log.trace("Executing saveEdge [{}]", edge); log.trace("Executing saveEdge [{}]", edge);
edgeValidator.validate(edge, Edge::getTenantId); Edge oldEdge = edgeValidator.validate(edge, Edge::getTenantId);
EdgeCacheEvictEvent evictEvent = new EdgeCacheEvictEvent(edge.getTenantId(), edge.getName(), oldEdge != null ? oldEdge.getName() : null);
try { try {
return edgeDao.save(edge.getTenantId(), edge); var savedEdge = edgeDao.save(edge.getTenantId(), edge);
publishEvictEvent(evictEvent);
return savedEdge;
} catch (Exception t) { } catch (Exception t) {
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
if (e != null && e.getConstraintName() != null if (e != null && e.getConstraintName() != null
@ -157,6 +171,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
} }
} }
@Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
public Edge assignEdgeToCustomer(TenantId tenantId, EdgeId edgeId, CustomerId customerId) { public Edge assignEdgeToCustomer(TenantId tenantId, EdgeId edgeId, CustomerId customerId) {
log.trace("[{}] Executing assignEdgeToCustomer [{}][{}]", tenantId, edgeId, customerId); log.trace("[{}] Executing assignEdgeToCustomer [{}][{}]", tenantId, edgeId, customerId);
@ -165,6 +180,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
return saveEdge(edge); return saveEdge(edge);
} }
@Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
public Edge unassignEdgeFromCustomer(TenantId tenantId, EdgeId edgeId) { public Edge unassignEdgeFromCustomer(TenantId tenantId, EdgeId edgeId) {
log.trace("[{}] Executing unassignEdgeFromCustomer [{}]", tenantId, edgeId); log.trace("[{}] Executing unassignEdgeFromCustomer [{}]", tenantId, edgeId);
@ -173,6 +189,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
return saveEdge(edge); return saveEdge(edge);
} }
@Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
public void deleteEdge(TenantId tenantId, EdgeId edgeId) { public void deleteEdge(TenantId tenantId, EdgeId edgeId) {
log.trace("Executing deleteEdge [{}]", edgeId); log.trace("Executing deleteEdge [{}]", edgeId);
@ -182,9 +199,9 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
deleteEntityRelations(tenantId, edgeId); deleteEntityRelations(tenantId, edgeId);
cacheManager.removeEdgeFromCacheByName(edge.getTenantId(), edge.getName());
edgeDao.removeById(tenantId, edgeId.getId()); edgeDao.removeById(tenantId, edgeId.getId());
publishEvictEvent(new EdgeCacheEvictEvent(edge.getTenantId(), edge.getName(), null));
} }
@Override @Override
@ -284,6 +301,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
customerId.getId(), toUUIDs(edgeIds)); customerId.getId(), toUUIDs(edgeIds));
} }
@Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
public void unassignCustomerEdges(TenantId tenantId, CustomerId customerId) { public void unassignCustomerEdges(TenantId tenantId, CustomerId customerId) {
log.trace("Executing unassignCustomerEdges, tenantId [{}], customerId [{}]", tenantId, customerId); log.trace("Executing unassignCustomerEdges, tenantId [{}], customerId [{}]", tenantId, customerId);

16
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewRedisCache.java

@ -26,25 +26,13 @@ import org.thingsboard.server.common.data.CacheConstants;
import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.dao.asset.AssetCacheKey; import org.thingsboard.server.dao.asset.AssetCacheKey;
import org.thingsboard.server.dao.cache.RedisTbTransactionalCache; import org.thingsboard.server.dao.cache.RedisTbTransactionalCache;
import org.thingsboard.server.dao.cache.TbRedisSerializer;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
@Service("EntityViewCache") @Service("EntityViewCache")
public class EntityViewRedisCache extends RedisTbTransactionalCache<EntityViewCacheKey, EntityViewCacheValue> { public class EntityViewRedisCache extends RedisTbTransactionalCache<EntityViewCacheKey, EntityViewCacheValue> {
public EntityViewRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) { public EntityViewRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
super(CacheConstants.ENTITY_VIEW_CACHE, cacheSpecsMap, connectionFactory, configuration, new RedisSerializer<>() { super(CacheConstants.ENTITY_VIEW_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbRedisSerializer<>());
private final RedisSerializer<Object> java = RedisSerializer.java();
@Override
public byte[] serialize(EntityViewCacheValue attributeKvEntry) throws SerializationException {
return java.serialize(attributeKvEntry);
}
@Override
public EntityViewCacheValue deserialize(byte[] bytes) throws SerializationException {
return (EntityViewCacheValue) java.deserialize(bytes);
}
});
} }
} }

16
dao/src/main/java/org/thingsboard/server/dao/relation/RelationRedisCache.java

@ -26,25 +26,13 @@ import org.thingsboard.server.common.data.CacheConstants;
import org.thingsboard.server.common.data.kv.AttributeKvEntry; import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.dao.attributes.AttributeCacheKey; import org.thingsboard.server.dao.attributes.AttributeCacheKey;
import org.thingsboard.server.dao.cache.RedisTbTransactionalCache; import org.thingsboard.server.dao.cache.RedisTbTransactionalCache;
import org.thingsboard.server.dao.cache.TbRedisSerializer;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
@Service("RelationCache") @Service("RelationCache")
public class RelationRedisCache extends RedisTbTransactionalCache<RelationCacheKey, RelationCacheValue> { public class RelationRedisCache extends RedisTbTransactionalCache<RelationCacheKey, RelationCacheValue> {
public RelationRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) { public RelationRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
super(CacheConstants.RELATIONS_CACHE, cacheSpecsMap, connectionFactory, configuration, new RedisSerializer<>() { super(CacheConstants.RELATIONS_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbRedisSerializer<>());
private final RedisSerializer<Object> java = RedisSerializer.java();
@Override
public byte[] serialize(RelationCacheValue attributeKvEntry) throws SerializationException {
return java.serialize(attributeKvEntry);
}
@Override
public RelationCacheValue deserialize(byte[] bytes) throws SerializationException {
return (RelationCacheValue) java.deserialize(bytes);
}
});
} }
} }

16
dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileRedisCache.java

@ -27,25 +27,13 @@ import org.thingsboard.server.common.data.TenantProfile;
import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.dao.asset.AssetCacheKey; import org.thingsboard.server.dao.asset.AssetCacheKey;
import org.thingsboard.server.dao.cache.RedisTbTransactionalCache; import org.thingsboard.server.dao.cache.RedisTbTransactionalCache;
import org.thingsboard.server.dao.cache.TbRedisSerializer;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis") @ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
@Service("TenantProfileCache") @Service("TenantProfileCache")
public class TenantProfileRedisCache extends RedisTbTransactionalCache<TenantProfileCacheKey, TenantProfile> { public class TenantProfileRedisCache extends RedisTbTransactionalCache<TenantProfileCacheKey, TenantProfile> {
public TenantProfileRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) { public TenantProfileRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
super(CacheConstants.TENANT_PROFILE_CACHE, cacheSpecsMap, connectionFactory, configuration, new RedisSerializer<>() { super(CacheConstants.TENANT_PROFILE_CACHE, cacheSpecsMap, connectionFactory, configuration, new TbRedisSerializer<>());
private final RedisSerializer<Object> java = RedisSerializer.java();
@Override
public byte[] serialize(TenantProfile attributeKvEntry) throws SerializationException {
return java.serialize(attributeKvEntry);
}
@Override
public TenantProfile deserialize(byte[] bytes) throws SerializationException {
return (TenantProfile) java.deserialize(bytes);
}
});
} }
} }

Loading…
Cancel
Save